3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that subprograms Shift_Left, Shift_Right,
28 -- Shift_Right_Arithmetic, Rotate_Left, and Rotate_Right are available
29 -- and produce correct results for values of signed and modular
30 -- integer types of 16 bits.
33 -- This test uses the shift and rotate functions of package Interfaces
34 -- with a modular type representative of 16 bits. The functions
35 -- are used as the right hand of assignment statements, as part of
36 -- conditional statements, and as arguments in other function calls.
38 -- APPLICABILITY CRITERIA:
39 -- This test is applicable to all implementations that support signed
40 -- and modular integer types of 16 bits.
44 -- 21 Aug 95 SAIC Initial prerelease version.
45 -- 07 May 96 SAIC Incorporated reviewer comments for ACVC 2.1.
46 -- 26 Oct 96 SAIC Removed subtests based on Big/Little Endian.
47 -- 17 Feb 97 PWB.CTA Corrected "-" to "+" in parenthesized expressions.
57 Report
.Test
("CXB2002",
58 "Check that subprograms Shift_Left, Shift_Right, " &
59 "Shift_Right_Arithmetic, Rotate_Left, and Rotate_Right " &
60 "produce correct results for values of signed and " &
61 "modular integer types of 16 bits");
69 TC_Amount
: Natural := Natural'First;
71 -- Range of type Unsigned_16 is 0..65535 (0..Modulus-1).
73 TC_Result_Unsigned_16
: Unsigned_16
:= Unsigned_16
'First;
77 -- Note: The shifting and rotating subprograms operate on a bit-by-bit
78 -- basis, using the binary representation of the value of the
79 -- operands to yield a binary representation for the result.
81 -- Function Shift_Left.
84 TC_Val_Unsigned_16
:= Unsigned_16
'Last; -- 65535.
85 TC_Result_Unsigned_16
:= Shift_Left
(TC_Val_Unsigned_16
, TC_Amount
);
87 if TC_Result_Unsigned_16
/= Unsigned_16
'Last - (2**0 + 2**1 + 2**2)
89 Report
.Failed
("Incorrect result from Shift_Left - 1");
92 if Shift_Left
(TC_Val_Unsigned_16
, 0) /= Unsigned_16
'Last or
93 Shift_Left
(TC_Val_Unsigned_16
, 5) /=
94 Unsigned_16
'Last - (2**0 + 2**1 + 2**2 + 2**3 +2**4) or
95 Shift_Left
(TC_Val_Unsigned_16
, 16) /= 0
97 Report
.Failed
("Incorrect result from Shift_Left - 2");
101 -- Function Shift_Right.
104 TC_Val_Unsigned_16
:= Unsigned_16
'Last; -- 65535.
105 TC_Result_Unsigned_16
:= Shift_Right
(Value
=> TC_Val_Unsigned_16
,
106 Amount
=> TC_Amount
);
108 if TC_Result_Unsigned_16
/= Unsigned_16
'Last-(2**15 + 2**14 + 2**13)
110 Report
.Failed
("Incorrect result from Shift_Right - 1");
113 if Shift_Right
(TC_Val_Unsigned_16
, 0) /= Unsigned_16
'Last or
114 Shift_Right
(TC_Val_Unsigned_16
, 5) /=
115 Unsigned_16
'Last-(2**15 + 2**14 + 2**13 + 2**12 + 2**11) or
116 Shift_Right
(TC_Val_Unsigned_16
, 16) /= 0
118 Report
.Failed
("Incorrect result from Shift_Right - 2");
122 -- Tests of Shift_Left and Shift_Right in combination.
124 TC_Val_Unsigned_16
:= Unsigned_16
'Last;
126 if Shift_Left
(Shift_Right
(TC_Val_Unsigned_16
, 4), 4) /=
127 Unsigned_16
'Last-(2**0 + 2**1 + 2**2 + 2**3) or
128 Shift_Left
(Shift_Right
(TC_Val_Unsigned_16
, 1), 3) /=
129 Unsigned_16
'Last-(2**0 + 2**1 + 2**2) or
130 Shift_Right
(Shift_Left
(TC_Val_Unsigned_16
, 2), 4) /=
131 Unsigned_16
'Last-(2**15+ 2**14 + 2**13 + 2**12) or
132 Shift_Right
(Shift_Left
(TC_Val_Unsigned_16
, 2), 16) /= 0
134 Report
.Failed
("Incorrect result from Shift_Left - " &
135 "Shift_Right functions used in combination");
139 -- Function Shift_Right_Arithmetic.
141 -- Case where the parameter Value is less than
142 -- one half of the modulus. Zero bits will be shifted in.
143 -- Modulus of type Unsigned_16 is 2**16; one half is 2**15.
146 TC_Val_Unsigned_16
:= 2**15 - 1; -- Less than one half of modulus.
147 TC_Result_Unsigned_16
:= Shift_Right_Arithmetic
(TC_Val_Unsigned_16
,
149 if TC_Result_Unsigned_16
/=
150 TC_Val_Unsigned_16
- (2**14 + 2**13 + 2**12)
153 ("Incorrect result from Shift_Right_Arithmetic - 1");
156 if Shift_Right_Arithmetic
(TC_Val_Unsigned_16
, 0) /=
157 TC_Val_Unsigned_16
or
158 Shift_Right_Arithmetic
(TC_Val_Unsigned_16
, 5) /=
159 TC_Val_Unsigned_16
- (2**14 + 2**13 + 2**12 + 2**11 + 2**10) or
160 Shift_Right_Arithmetic
(TC_Val_Unsigned_16
, 16) /= 0
163 ("Incorrect result from Shift_Right_Arithmetic - 2");
166 -- Case where the parameter Value is greater than or equal to
167 -- one half of the modulus. One bits will be shifted in.
170 TC_Val_Unsigned_16
:= 2**15; -- One half of modulus.
171 TC_Result_Unsigned_16
:= Shift_Right_Arithmetic
(TC_Val_Unsigned_16
,
173 if TC_Result_Unsigned_16
/= TC_Val_Unsigned_16
+ 2**14 then
175 ("Incorrect result from Shift_Right_Arithmetic - 3");
179 TC_Val_Unsigned_16
:= 2**15 + 1; -- Greater than half of modulus.
180 TC_Result_Unsigned_16
:= Shift_Right_Arithmetic
(TC_Val_Unsigned_16
,
182 if TC_Result_Unsigned_16
/= TC_Val_Unsigned_16
+ 2**14 - 2**0 then
184 ("Incorrect result from Shift_Right_Arithmetic - 4");
187 if Shift_Right_Arithmetic
(TC_Val_Unsigned_16
, 0) /=
188 TC_Val_Unsigned_16
or
189 Shift_Right_Arithmetic
(TC_Val_Unsigned_16
, 4) /=
190 TC_Val_Unsigned_16
- 2**0 + 2**14 + 2**13 + 2**12 + 2**11 or
191 Shift_Right_Arithmetic
(TC_Val_Unsigned_16
, 16) /= Unsigned_16
'Last
194 ("Incorrect result from Shift_Right_Arithmetic - 5");
198 -- Function Rotate_Left.
201 TC_Val_Unsigned_16
:= Unsigned_16
'Last; -- 65535.
202 TC_Result_Unsigned_16
:= Rotate_Left
(Value
=> TC_Val_Unsigned_16
,
203 Amount
=> TC_Amount
);
204 if TC_Result_Unsigned_16
/= Unsigned_16
'Last then
205 Report
.Failed
("Incorrect result from Rotate_Left - 1");
208 TC_Val_Unsigned_16
:= 2**15 + 2**14 + 2**1 + 2**0;
209 if Rotate_Left
(TC_Val_Unsigned_16
, 0) /=
210 2**15 + 2**14 + 2**1 + 2**0 or
211 Rotate_Left
(TC_Val_Unsigned_16
, 5) /=
212 2**6 + 2**5 + 2**4 + 2**3 or
213 Rotate_Left
(TC_Val_Unsigned_16
, 16) /= TC_Val_Unsigned_16
215 Report
.Failed
("Incorrect result from Rotate_Left - 2");
219 -- Function Rotate_Right.
222 TC_Val_Unsigned_16
:= 2**1 + 2**0;
223 TC_Result_Unsigned_16
:= Rotate_Right
(Value
=> TC_Val_Unsigned_16
,
224 Amount
=> TC_Amount
);
225 if TC_Result_Unsigned_16
/= 2**15 + 2**0 then
226 Report
.Failed
("Incorrect result from Rotate_Right - 1");
229 if Rotate_Right
(TC_Val_Unsigned_16
, 0) /= 2**1 + 2**0 or
230 Rotate_Right
(TC_Val_Unsigned_16
, 5) /= 2**12 + 2**11 or
231 Rotate_Right
(TC_Val_Unsigned_16
, 16) /= 2**1 + 2**0
233 Report
.Failed
("Incorrect result from Rotate_Right - 2");
237 -- Tests of Rotate_Left and Rotate_Right in combination.
239 TC_Val_Unsigned_16
:= 32769;
241 if Rotate_Left
(Rotate_Right
(TC_Val_Unsigned_16
, 4), 3) /= 49152 or
242 Rotate_Left
(Rotate_Right
(TC_Val_Unsigned_16
, 1), 3) /= 6 or
243 Rotate_Right
(Rotate_Left
(TC_Val_Unsigned_16
, 3), 7) /= 6144 or
244 Rotate_Right
(Rotate_Left
(TC_Val_Unsigned_16
, 1), 16) /= 3
246 Report
.Failed
("Incorrect result from Rotate_Left - " &
247 "Rotate_Right functions used in combination");
252 when The_Error
: others =>
253 Report
.Failed
("The following exception was raised in the " &
254 "Test_Block: " & Exception_Name
(The_Error
));