OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [ada/] [s-pack42.adb] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT RUN-TIME COMPONENTS                         --
4
--                                                                          --
5
--                       S Y S T E M . P A C K _ 4 2                        --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--          Copyright (C) 1992-2005, Free Software Foundation, Inc.         --
10
--                                                                          --
11
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12
-- terms of the  GNU General Public License as published  by the Free Soft- --
13
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17
-- for  more details.  You should have  received  a copy of the GNU General --
18
-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20
-- Boston, MA 02110-1301, USA.                                              --
21
--                                                                          --
22
-- As a special exception,  if other files  instantiate  generics from this --
23
-- unit, or you link  this unit with other files  to produce an executable, --
24
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
25
-- covered  by the  GNU  General  Public  License.  This exception does not --
26
-- however invalidate  any other reasons why  the executable file  might be --
27
-- covered by the  GNU Public License.                                      --
28
--                                                                          --
29
-- GNAT was originally developed  by the GNAT team at  New York University. --
30
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
31
--                                                                          --
32
------------------------------------------------------------------------------
33
 
34
with System.Storage_Elements;
35
with System.Unsigned_Types;
36
with Unchecked_Conversion;
37
 
38
package body System.Pack_42 is
39
 
40
   subtype Ofs is System.Storage_Elements.Storage_Offset;
41
   subtype Uns is System.Unsigned_Types.Unsigned;
42
   subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;
43
 
44
   use type System.Storage_Elements.Storage_Offset;
45
   use type System.Unsigned_Types.Unsigned;
46
 
47
   type Cluster is record
48
      E0, E1, E2, E3, E4, E5, E6, E7 : Bits_42;
49
   end record;
50
 
51
   for Cluster use record
52
      E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
53
      E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
54
      E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
55
      E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
56
      E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
57
      E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
58
      E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
59
      E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
60
   end record;
61
 
62
   for Cluster'Size use Bits * 8;
63
 
64
   for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment,
65
     1 +
66
     1 * Boolean'Pos (Bits mod 2 = 0) +
67
     2 * Boolean'Pos (Bits mod 4 = 0));
68
   --  Use maximum possible alignment, given the bit field size, since this
69
   --  will result in the most efficient code possible for the field.
70
 
71
   type Cluster_Ref is access Cluster;
72
 
73
   function To_Ref is new
74
     Unchecked_Conversion (System.Address, Cluster_Ref);
75
 
76
   --  The following declarations are for the case where the address
77
   --  passed to GetU_42 or SetU_42 is not guaranteed to be aligned.
78
   --  These routines are used when the packed array is itself a
79
   --  component of a packed record, and therefore may not be aligned.
80
 
81
   type ClusterU is new Cluster;
82
   for ClusterU'Alignment use 1;
83
 
84
   type ClusterU_Ref is access ClusterU;
85
 
86
   function To_Ref is new
87
     Unchecked_Conversion (System.Address, ClusterU_Ref);
88
 
89
   ------------
90
   -- Get_42 --
91
   ------------
92
 
93
   function Get_42 (Arr : System.Address; N : Natural) return Bits_42 is
94
      C : constant Cluster_Ref := To_Ref (Arr + Bits * Ofs (Uns (N) / 8));
95
   begin
96
      case N07 (Uns (N) mod 8) is
97
         when 0 => return C.E0;
98
         when 1 => return C.E1;
99
         when 2 => return C.E2;
100
         when 3 => return C.E3;
101
         when 4 => return C.E4;
102
         when 5 => return C.E5;
103
         when 6 => return C.E6;
104
         when 7 => return C.E7;
105
      end case;
106
   end Get_42;
107
 
108
   -------------
109
   -- GetU_42 --
110
   -------------
111
 
112
   function GetU_42 (Arr : System.Address; N : Natural) return Bits_42 is
113
      C : constant ClusterU_Ref := To_Ref (Arr + Bits * Ofs (Uns (N) / 8));
114
   begin
115
      case N07 (Uns (N) mod 8) is
116
         when 0 => return C.E0;
117
         when 1 => return C.E1;
118
         when 2 => return C.E2;
119
         when 3 => return C.E3;
120
         when 4 => return C.E4;
121
         when 5 => return C.E5;
122
         when 6 => return C.E6;
123
         when 7 => return C.E7;
124
      end case;
125
   end GetU_42;
126
 
127
   ------------
128
   -- Set_42 --
129
   ------------
130
 
131
   procedure Set_42 (Arr : System.Address; N : Natural; E : Bits_42) is
132
      C : constant Cluster_Ref := To_Ref (Arr + Bits * Ofs (Uns (N) / 8));
133
   begin
134
      case N07 (Uns (N) mod 8) is
135
         when 0 => C.E0 := E;
136
         when 1 => C.E1 := E;
137
         when 2 => C.E2 := E;
138
         when 3 => C.E3 := E;
139
         when 4 => C.E4 := E;
140
         when 5 => C.E5 := E;
141
         when 6 => C.E6 := E;
142
         when 7 => C.E7 := E;
143
      end case;
144
   end Set_42;
145
 
146
   -------------
147
   -- SetU_42 --
148
   -------------
149
 
150
   procedure SetU_42 (Arr : System.Address; N : Natural; E : Bits_42) is
151
      C : constant ClusterU_Ref := To_Ref (Arr + Bits * Ofs (Uns (N) / 8));
152
   begin
153
      case N07 (Uns (N) mod 8) is
154
         when 0 => C.E0 := E;
155
         when 1 => C.E1 := E;
156
         when 2 => C.E2 := E;
157
         when 3 => C.E3 := E;
158
         when 4 => C.E4 := E;
159
         when 5 => C.E5 := E;
160
         when 6 => C.E6 := E;
161
         when 7 => C.E7 := E;
162
      end case;
163
   end SetU_42;
164
 
165
end System.Pack_42;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.