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