summaryrefslogtreecommitdiff
path: root/gcc/ada/s-pack17.adb
blob: 0fc493881bb2b41121923fdd004d7de345a5ce9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT RUN-TIME COMPONENTS                         --
--                                                                          --
--                       S Y S T E M . P A C K _ 1 7                        --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--          Copyright (C) 1992-2014, Free Software Foundation, Inc.         --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

with System.Storage_Elements;
with System.Unsigned_Types;

package body System.Pack_17 is

   subtype Bit_Order is System.Bit_Order;
   Reverse_Bit_Order : constant Bit_Order :=
     Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order));

   subtype Ofs is System.Storage_Elements.Storage_Offset;
   subtype Uns is System.Unsigned_Types.Unsigned;
   subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;

   use type System.Storage_Elements.Storage_Offset;
   use type System.Unsigned_Types.Unsigned;

   type Cluster is record
      E0, E1, E2, E3, E4, E5, E6, E7 : Bits_17;
   end record;

   for Cluster use record
      E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
      E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
      E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
      E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
      E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
      E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
      E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
      E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
   end record;

   for Cluster'Size use Bits * 8;

   for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment,
     1 +
     1 * Boolean'Pos (Bits mod 2 = 0) +
     2 * Boolean'Pos (Bits mod 4 = 0));
   --  Use maximum possible alignment, given the bit field size, since this
   --  will result in the most efficient code possible for the field.

   type Cluster_Ref is access Cluster;

   type Rev_Cluster is new Cluster
     with Bit_Order            => Reverse_Bit_Order,
          Scalar_Storage_Order => Reverse_Bit_Order;
   type Rev_Cluster_Ref is access Rev_Cluster;

   ------------
   -- Get_17 --
   ------------

   function Get_17
     (Arr     : System.Address;
      N       : Natural;
      Rev_SSO : Boolean) return Bits_17
   is
      A  : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
      C  : Cluster_Ref     with Address => A'Address, Import;
      RC : Rev_Cluster_Ref with Address => A'Address, Import;
   begin
      if Rev_SSO then
         case N07 (Uns (N) mod 8) is
            when 0 => return RC.E0;
            when 1 => return RC.E1;
            when 2 => return RC.E2;
            when 3 => return RC.E3;
            when 4 => return RC.E4;
            when 5 => return RC.E5;
            when 6 => return RC.E6;
            when 7 => return RC.E7;
         end case;

      else
         case N07 (Uns (N) mod 8) is
            when 0 => return C.E0;
            when 1 => return C.E1;
            when 2 => return C.E2;
            when 3 => return C.E3;
            when 4 => return C.E4;
            when 5 => return C.E5;
            when 6 => return C.E6;
            when 7 => return C.E7;
         end case;
      end if;
   end Get_17;

   ------------
   -- Set_17 --
   ------------

   procedure Set_17
     (Arr     : System.Address;
      N       : Natural;
      E       : Bits_17;
      Rev_SSO : Boolean)
   is
      A  : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
      C  : Cluster_Ref     with Address => A'Address, Import;
      RC : Rev_Cluster_Ref with Address => A'Address, Import;
   begin
      if Rev_SSO then
         case N07 (Uns (N) mod 8) is
            when 0 => RC.E0 := E;
            when 1 => RC.E1 := E;
            when 2 => RC.E2 := E;
            when 3 => RC.E3 := E;
            when 4 => RC.E4 := E;
            when 5 => RC.E5 := E;
            when 6 => RC.E6 := E;
            when 7 => RC.E7 := E;
         end case;
      else
         case N07 (Uns (N) mod 8) is
            when 0 => C.E0 := E;
            when 1 => C.E1 := E;
            when 2 => C.E2 := E;
            when 3 => C.E3 := E;
            when 4 => C.E4 := E;
            when 5 => C.E5 := E;
            when 6 => C.E6 := E;
            when 7 => C.E7 := E;
         end case;
      end if;
   end Set_17;

end System.Pack_17;