File: | pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/lltest.c |
Warning: | line 663, column 5 The left operand of '>>' is a garbage value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |||
2 | /* This Source Code Form is subject to the terms of the Mozilla Public | |||
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |||
5 | ||||
6 | /* | |||
7 | ** testll.c -- test suite for 64bit integer (longlong) operations | |||
8 | ** | |||
9 | ** Summary: testll [-d] | [-h] | |||
10 | ** | |||
11 | ** Where: | |||
12 | ** -d set debug mode on; displays individual test failures | |||
13 | ** -v verbose mode; displays progress in test, plus -d | |||
14 | ** -h gives usage message. | |||
15 | ** | |||
16 | ** Description: | |||
17 | ** lltest.c tests the functions defined in NSPR 2.0's prlong.h. | |||
18 | ** | |||
19 | ** Successive tests begin to depend on other LL functions working | |||
20 | ** correctly. So, ... Do not change the order of the tests as run | |||
21 | ** from main(). | |||
22 | ** | |||
23 | ** Caveats: | |||
24 | ** Do not even begin to think that this is an exhaustive test! | |||
25 | ** | |||
26 | ** These tests try a little of everything, but not all boundary | |||
27 | ** conditions and limits are tested. | |||
28 | ** You want better coverage? ... Add it. | |||
29 | ** | |||
30 | ** --- | |||
31 | ** Author: Lawrence Hardiman <larryh@netscape.com>. | |||
32 | ** --- | |||
33 | ** Revision History: | |||
34 | ** 01-Oct-1997. Original implementation. | |||
35 | ** | |||
36 | */ | |||
37 | ||||
38 | #include "nspr.h" | |||
39 | #include "plgetopt.h" | |||
40 | ||||
41 | /* --- Local Definitions --- */ | |||
42 | #define ReportProgress(m)if (verboseMode) PR_fprintf(output, (m)); if (verboseMode) PR_fprintf(output, (m)); | |||
43 | ||||
44 | ||||
45 | /* --- Global variables --- */ | |||
46 | static PRIntn failedAlready = 0; | |||
47 | static PRFileDesc* output = NULL((void*)0); | |||
48 | static PRBool debugMode = PR_FALSE0; | |||
49 | static PRBool verboseMode = PR_FALSE0; | |||
50 | ||||
51 | /* | |||
52 | ** Constants used in tests. | |||
53 | */ | |||
54 | const PRInt64 bigZero = LL_INIT( 0, 0 )((0L << 32) + 0L); | |||
55 | const PRInt64 bigOne = LL_INIT( 0, 1 )((0L << 32) + 1L); | |||
56 | const PRInt64 bigTwo = LL_INIT( 0, 2 )((0L << 32) + 2L); | |||
57 | const PRInt64 bigSixTeen = LL_INIT( 0, 16 )((0L << 32) + 16L); | |||
58 | const PRInt64 bigThirtyTwo = LL_INIT( 0, 32 )((0L << 32) + 32L); | |||
59 | const PRInt64 bigMinusOne = LL_INIT( 0xffffffff, 0xffffffff )((0xffffffffL << 32) + 0xffffffffL); | |||
60 | const PRInt64 bigMinusTwo = LL_INIT( 0xffffffff, 0xfffffffe )((0xffffffffL << 32) + 0xfffffffeL); | |||
61 | const PRInt64 bigNumber = LL_INIT( 0x7fffffff, 0xffffffff )((0x7fffffffL << 32) + 0xffffffffL); | |||
62 | const PRInt64 bigMinusNumber = LL_INIT( 0x80000000, 0x00000001 )((0x80000000L << 32) + 0x00000001L); | |||
63 | const PRInt64 bigMaxInt32 = LL_INIT( 0x00000000, 0x7fffffff )((0x00000000L << 32) + 0x7fffffffL); | |||
64 | const PRInt64 big2To31 = LL_INIT( 0x00000000, 0x80000000 )((0x00000000L << 32) + 0x80000000L); | |||
65 | const PRUint64 bigZeroFox = LL_INIT( 0x00000000, 0xffffffff )((0x00000000L << 32) + 0xffffffffL); | |||
66 | const PRUint64 bigFoxFox = LL_INIT( 0xffffffff, 0xffffffff )((0xffffffffL << 32) + 0xffffffffL); | |||
67 | const PRUint64 bigFoxZero = LL_INIT( 0xffffffff, 0x00000000 )((0xffffffffL << 32) + 0x00000000L); | |||
68 | const PRUint64 bigEightZero = LL_INIT( 0x80000000, 0x00000000 )((0x80000000L << 32) + 0x00000000L); | |||
69 | const PRUint64 big64K = LL_INIT( 0x00000000, 0x00010000 )((0x00000000L << 32) + 0x00010000L); | |||
70 | const PRInt64 bigInt0 = LL_INIT( 0x01a00000, 0x00001000 )((0x01a00000L << 32) + 0x00001000L); | |||
71 | const PRInt64 bigInt1 = LL_INIT( 0x01a00000, 0x00001100 )((0x01a00000L << 32) + 0x00001100L); | |||
72 | const PRInt64 bigInt2 = LL_INIT( 0x01a00000, 0x00000100 )((0x01a00000L << 32) + 0x00000100L); | |||
73 | const PRInt64 bigInt3 = LL_INIT( 0x01a00001, 0x00001000 )((0x01a00001L << 32) + 0x00001000L); | |||
74 | const PRInt64 bigInt4 = LL_INIT( 0x01a00001, 0x00001100 )((0x01a00001L << 32) + 0x00001100L); | |||
75 | const PRInt64 bigInt5 = LL_INIT( 0x01a00001, 0x00000100 )((0x01a00001L << 32) + 0x00000100L); | |||
76 | const PRInt64 bigInt6 = LL_INIT( 0xb1a00000, 0x00001000 )((0xb1a00000L << 32) + 0x00001000L); | |||
77 | const PRInt64 bigInt7 = LL_INIT( 0xb1a00000, 0x00001100 )((0xb1a00000L << 32) + 0x00001100L); | |||
78 | const PRInt64 bigInt8 = LL_INIT( 0xb1a00000, 0x00000100 )((0xb1a00000L << 32) + 0x00000100L); | |||
79 | const PRInt64 bigInt9 = LL_INIT( 0xb1a00001, 0x00001000 )((0xb1a00001L << 32) + 0x00001000L); | |||
80 | const PRInt64 bigInt10 = LL_INIT( 0xb1a00001, 0x00001100 )((0xb1a00001L << 32) + 0x00001100L); | |||
81 | const PRInt64 bigInt11 = LL_INIT( 0xb1a00001, 0x00000100 )((0xb1a00001L << 32) + 0x00000100L); | |||
82 | const PRInt32 one = 1l; | |||
83 | const PRInt32 minusOne = -1l; | |||
84 | const PRInt32 sixteen = 16l; | |||
85 | const PRInt32 thirtyTwo = 32l; | |||
86 | const PRInt32 sixtyThree = 63l; | |||
87 | ||||
88 | /* | |||
89 | ** SetFailed() -- Report individual test failure | |||
90 | ** | |||
91 | */ | |||
92 | static void | |||
93 | SetFailed( char *what, char *how ) | |||
94 | { | |||
95 | failedAlready = 1; | |||
96 | if ( debugMode ) { | |||
97 | PR_fprintf(output, "%s: failed: %s\n", what, how ); | |||
98 | } | |||
99 | return; | |||
100 | } | |||
101 | ||||
102 | static void | |||
103 | ResultFailed( char *what, char *how, PRInt64 expected, PRInt64 got) | |||
104 | { | |||
105 | if ( debugMode) | |||
106 | { | |||
107 | SetFailed( what, how ); | |||
108 | PR_fprintf(output, "Expected: 0x%llx Got: 0x%llx\n", expected, got ); | |||
109 | } | |||
110 | return; | |||
111 | } | |||
112 | ||||
113 | ||||
114 | /* | |||
115 | ** TestAssignment() -- Test the assignment | |||
116 | */ | |||
117 | static void TestAssignment( void ) | |||
118 | { | |||
119 | PRInt64 zero = LL_Zero(); | |||
120 | PRInt64 min = LL_MinInt(); | |||
121 | PRInt64 max = LL_MaxInt(); | |||
122 | if (!LL_EQ(zero, bigZero)((zero) == (bigZero))) { | |||
123 | SetFailed("LL_EQ(zero, bigZero)", "!="); | |||
124 | } | |||
125 | if (!LL_CMP(max, >, min)((PRInt64)(max) > (PRInt64)(min))) { | |||
126 | SetFailed("LL_CMP(max, >, min)", "!>"); | |||
127 | } | |||
128 | } | |||
129 | ||||
130 | /* | |||
131 | ** TestComparisons() -- Test the longlong comparison operations | |||
132 | */ | |||
133 | static void | |||
134 | TestComparisons( void ) | |||
135 | { | |||
136 | ReportProgress("Testing Comparisons Operations\n")if (verboseMode) PR_fprintf(output, ("Testing Comparisons Operations\n" ));; | |||
137 | ||||
138 | /* test for zero */ | |||
139 | if ( !LL_IS_ZERO( bigZero )((bigZero) == 0)) { | |||
140 | SetFailed( "LL_IS_ZERO", "Zero is not zero" ); | |||
141 | } | |||
142 | ||||
143 | if ( LL_IS_ZERO( bigOne )((bigOne) == 0)) { | |||
144 | SetFailed( "LL_IS_ZERO", "One tests as zero" ); | |||
145 | } | |||
146 | ||||
147 | if ( LL_IS_ZERO( bigMinusOne )((bigMinusOne) == 0)) { | |||
148 | SetFailed( "LL_IS_ZERO", "Minus One tests as zero" ); | |||
149 | } | |||
150 | ||||
151 | /* test equal */ | |||
152 | if ( !LL_EQ( bigZero, bigZero )((bigZero) == (bigZero))) { | |||
153 | SetFailed( "LL_EQ", "zero EQ zero"); | |||
154 | } | |||
155 | ||||
156 | if ( !LL_EQ( bigOne, bigOne )((bigOne) == (bigOne))) { | |||
157 | SetFailed( "LL_EQ", "one EQ one" ); | |||
158 | } | |||
159 | ||||
160 | if ( !LL_EQ( bigNumber, bigNumber )((bigNumber) == (bigNumber))) { | |||
161 | SetFailed( "LL_EQ", "bigNumber EQ bigNumber" ); | |||
162 | } | |||
163 | ||||
164 | if ( !LL_EQ( bigMinusOne, bigMinusOne )((bigMinusOne) == (bigMinusOne))) { | |||
165 | SetFailed( "LL_EQ", "minus one EQ minus one"); | |||
166 | } | |||
167 | ||||
168 | if ( LL_EQ( bigZero, bigOne )((bigZero) == (bigOne))) { | |||
169 | SetFailed( "LL_EQ", "zero EQ one"); | |||
170 | } | |||
171 | ||||
172 | if ( LL_EQ( bigOne, bigZero )((bigOne) == (bigZero))) { | |||
173 | SetFailed( "LL_EQ", "one EQ zero" ); | |||
174 | } | |||
175 | ||||
176 | if ( LL_EQ( bigMinusOne, bigOne )((bigMinusOne) == (bigOne))) { | |||
177 | SetFailed( "LL_EQ", "minus one EQ one"); | |||
178 | } | |||
179 | ||||
180 | if ( LL_EQ( bigNumber, bigOne )((bigNumber) == (bigOne))) { | |||
181 | SetFailed( "LL_EQ", "bigNumber EQ one"); | |||
182 | } | |||
183 | ||||
184 | /* test not equal */ | |||
185 | if ( LL_NE( bigZero, bigZero )((bigZero) != (bigZero))) { | |||
186 | SetFailed( "LL_NE", "0 NE 0"); | |||
187 | } | |||
188 | ||||
189 | if ( LL_NE( bigOne, bigOne )((bigOne) != (bigOne))) { | |||
190 | SetFailed( "LL_NE", "1 NE 1"); | |||
191 | } | |||
192 | ||||
193 | if ( LL_NE( bigMinusOne, bigMinusOne )((bigMinusOne) != (bigMinusOne))) { | |||
194 | SetFailed( "LL_NE", "-1 NE -1"); | |||
195 | } | |||
196 | ||||
197 | if ( LL_NE( bigNumber, bigNumber )((bigNumber) != (bigNumber))) { | |||
198 | SetFailed( "LL_NE", "n NE n"); | |||
199 | } | |||
200 | ||||
201 | if ( LL_NE( bigMinusNumber, bigMinusNumber )((bigMinusNumber) != (bigMinusNumber))) { | |||
202 | SetFailed( "LL_NE", "-n NE -n"); | |||
203 | } | |||
204 | ||||
205 | if ( !LL_NE( bigZero, bigOne)((bigZero) != (bigOne))) { | |||
206 | SetFailed( "LL_NE", "0 NE 1"); | |||
207 | } | |||
208 | ||||
209 | if ( !LL_NE( bigOne, bigMinusNumber)((bigOne) != (bigMinusNumber))) { | |||
210 | SetFailed( "LL_NE", "1 NE -n"); | |||
211 | } | |||
212 | ||||
213 | /* Greater than or equal to zero */ | |||
214 | if ( !LL_GE_ZERO( bigZero )((bigZero) >= 0)) { | |||
215 | SetFailed( "LL_GE_ZERO", "0"); | |||
216 | } | |||
217 | ||||
218 | if ( !LL_GE_ZERO( bigOne )((bigOne) >= 0)) { | |||
219 | SetFailed( "LL_GE_ZERO", "1"); | |||
220 | } | |||
221 | ||||
222 | if ( !LL_GE_ZERO( bigNumber )((bigNumber) >= 0)) { | |||
223 | SetFailed( "LL_GE_ZERO", "n"); | |||
224 | } | |||
225 | ||||
226 | if ( LL_GE_ZERO( bigMinusOne )((bigMinusOne) >= 0)) { | |||
227 | SetFailed( "LL_GE_ZERO", "-1"); | |||
228 | } | |||
229 | ||||
230 | if ( LL_GE_ZERO( bigMinusNumber )((bigMinusNumber) >= 0)) { | |||
231 | SetFailed( "LL_GE_ZERO", "-n"); | |||
232 | } | |||
233 | ||||
234 | /* Algebraic Compare two values */ | |||
235 | if ( !LL_CMP( bigZero, ==, bigZero )((PRInt64)(bigZero) == (PRInt64)(bigZero))) { | |||
236 | SetFailed( "LL_CMP", "0 == 0"); | |||
237 | } | |||
238 | ||||
239 | if ( LL_CMP( bigZero, >, bigZero )((PRInt64)(bigZero) > (PRInt64)(bigZero))) { | |||
240 | SetFailed( "LL_CMP", "0 > 0"); | |||
241 | } | |||
242 | ||||
243 | if ( LL_CMP( bigZero, <, bigZero )((PRInt64)(bigZero) < (PRInt64)(bigZero))) { | |||
244 | SetFailed( "LL_CMP", "0 < 0"); | |||
245 | } | |||
246 | ||||
247 | if ( LL_CMP( bigNumber, <, bigOne )((PRInt64)(bigNumber) < (PRInt64)(bigOne))) { | |||
248 | SetFailed( "LL_CMP", "n < 1"); | |||
249 | } | |||
250 | ||||
251 | if ( !LL_CMP( bigNumber, >, bigOne )((PRInt64)(bigNumber) > (PRInt64)(bigOne))) { | |||
252 | SetFailed( "LL_CMP", "n <= 1"); | |||
253 | } | |||
254 | ||||
255 | if ( LL_CMP( bigOne, >, bigNumber )((PRInt64)(bigOne) > (PRInt64)(bigNumber))) { | |||
256 | SetFailed( "LL_CMP", "1 > n"); | |||
257 | } | |||
258 | ||||
259 | if ( LL_CMP( bigMinusNumber, >, bigNumber )((PRInt64)(bigMinusNumber) > (PRInt64)(bigNumber))) { | |||
260 | SetFailed( "LL_CMP", "-n > n"); | |||
261 | } | |||
262 | ||||
263 | if ( LL_CMP( bigNumber, !=, bigNumber)((PRInt64)(bigNumber) != (PRInt64)(bigNumber))) { | |||
264 | SetFailed( "LL_CMP", "n != n"); | |||
265 | } | |||
266 | ||||
267 | if ( !LL_CMP( bigMinusOne, >, bigMinusTwo )((PRInt64)(bigMinusOne) > (PRInt64)(bigMinusTwo))) { | |||
268 | SetFailed( "LL_CMP", "-1 <= -2"); | |||
269 | } | |||
270 | ||||
271 | if ( !LL_CMP( bigMaxInt32, <, big2To31 )((PRInt64)(bigMaxInt32) < (PRInt64)(big2To31))) { | |||
272 | SetFailed( "LL_CMP", "Max 32-bit signed int >= 2^31"); | |||
273 | } | |||
274 | ||||
275 | /* Two positive numbers */ | |||
276 | if ( !LL_CMP( bigInt0, <=, bigInt0 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt0))) { | |||
277 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
278 | } | |||
279 | ||||
280 | if ( !LL_CMP( bigInt0, <=, bigInt1 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt1))) { | |||
281 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
282 | } | |||
283 | ||||
284 | if ( LL_CMP( bigInt0, <=, bigInt2 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt2))) { | |||
285 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
286 | } | |||
287 | ||||
288 | if ( !LL_CMP( bigInt0, <=, bigInt3 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt3))) { | |||
289 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
290 | } | |||
291 | ||||
292 | if ( !LL_CMP( bigInt0, <=, bigInt4 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt4))) { | |||
293 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
294 | } | |||
295 | ||||
296 | if ( !LL_CMP( bigInt0, <=, bigInt5 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt5))) { | |||
297 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
298 | } | |||
299 | ||||
300 | /* Two negative numbers */ | |||
301 | if ( !LL_CMP( bigInt6, <=, bigInt6 )((PRInt64)(bigInt6) <= (PRInt64)(bigInt6))) { | |||
302 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
303 | } | |||
304 | ||||
305 | if ( !LL_CMP( bigInt6, <=, bigInt7 )((PRInt64)(bigInt6) <= (PRInt64)(bigInt7))) { | |||
306 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
307 | } | |||
308 | ||||
309 | if ( LL_CMP( bigInt6, <=, bigInt8 )((PRInt64)(bigInt6) <= (PRInt64)(bigInt8))) { | |||
310 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
311 | } | |||
312 | ||||
313 | if ( !LL_CMP( bigInt6, <=, bigInt9 )((PRInt64)(bigInt6) <= (PRInt64)(bigInt9))) { | |||
314 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
315 | } | |||
316 | ||||
317 | if ( !LL_CMP( bigInt6, <=, bigInt10 )((PRInt64)(bigInt6) <= (PRInt64)(bigInt10))) { | |||
318 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
319 | } | |||
320 | ||||
321 | if ( !LL_CMP( bigInt6, <=, bigInt11 )((PRInt64)(bigInt6) <= (PRInt64)(bigInt11))) { | |||
322 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
323 | } | |||
324 | ||||
325 | /* One positive, one negative */ | |||
326 | if ( LL_CMP( bigInt0, <=, bigInt6 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt6))) { | |||
327 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
328 | } | |||
329 | ||||
330 | if ( LL_CMP( bigInt0, <=, bigInt7 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt7))) { | |||
331 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
332 | } | |||
333 | ||||
334 | if ( LL_CMP( bigInt0, <=, bigInt8 )((PRInt64)(bigInt0) <= (PRInt64)(bigInt8))) { | |||
335 | SetFailed( "LL_CMP", "LL_CMP(<=) failed"); | |||
336 | } | |||
337 | ||||
338 | /* Bitwise Compare two numbers */ | |||
339 | if ( !LL_UCMP( bigZero, ==, bigZero )((PRUint64)(bigZero) == (PRUint64)(bigZero))) { | |||
340 | SetFailed( "LL_UCMP", "0 == 0"); | |||
341 | } | |||
342 | ||||
343 | if ( LL_UCMP( bigZero, >, bigZero )((PRUint64)(bigZero) > (PRUint64)(bigZero))) { | |||
344 | SetFailed( "LL_UCMP", "0 > 0"); | |||
345 | } | |||
346 | ||||
347 | if ( LL_UCMP( bigZero, <, bigZero )((PRUint64)(bigZero) < (PRUint64)(bigZero))) { | |||
348 | SetFailed( "LL_UCMP", "0 < 0"); | |||
349 | } | |||
350 | ||||
351 | if ( LL_UCMP( bigNumber, <, bigOne )((PRUint64)(bigNumber) < (PRUint64)(bigOne))) { | |||
352 | SetFailed( "LL_UCMP", "n < 1"); | |||
353 | } | |||
354 | ||||
355 | if ( !LL_UCMP( bigNumber, >, bigOne )((PRUint64)(bigNumber) > (PRUint64)(bigOne))) { | |||
356 | SetFailed( "LL_UCMP", "n < 1"); | |||
357 | } | |||
358 | ||||
359 | if ( LL_UCMP( bigOne, >, bigNumber )((PRUint64)(bigOne) > (PRUint64)(bigNumber))) { | |||
360 | SetFailed( "LL_UCMP", "1 > n"); | |||
361 | } | |||
362 | ||||
363 | if ( LL_UCMP( bigMinusNumber, <, bigNumber )((PRUint64)(bigMinusNumber) < (PRUint64)(bigNumber))) { | |||
364 | SetFailed( "LL_UCMP", "-n < n"); | |||
365 | } | |||
366 | ||||
367 | /* Two positive numbers */ | |||
368 | if ( !LL_UCMP( bigInt0, <=, bigInt0 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt0))) { | |||
369 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
370 | } | |||
371 | ||||
372 | if ( !LL_UCMP( bigInt0, <=, bigInt1 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt1))) { | |||
373 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
374 | } | |||
375 | ||||
376 | if ( LL_UCMP( bigInt0, <=, bigInt2 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt2))) { | |||
377 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
378 | } | |||
379 | ||||
380 | if ( !LL_UCMP( bigInt0, <=, bigInt3 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt3))) { | |||
381 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
382 | } | |||
383 | ||||
384 | if ( !LL_UCMP( bigInt0, <=, bigInt4 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt4))) { | |||
385 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
386 | } | |||
387 | ||||
388 | if ( !LL_UCMP( bigInt0, <=, bigInt5 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt5))) { | |||
389 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
390 | } | |||
391 | ||||
392 | /* Two negative numbers */ | |||
393 | if ( !LL_UCMP( bigInt6, <=, bigInt6 )((PRUint64)(bigInt6) <= (PRUint64)(bigInt6))) { | |||
394 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
395 | } | |||
396 | ||||
397 | if ( !LL_UCMP( bigInt6, <=, bigInt7 )((PRUint64)(bigInt6) <= (PRUint64)(bigInt7))) { | |||
398 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
399 | } | |||
400 | ||||
401 | if ( LL_UCMP( bigInt6, <=, bigInt8 )((PRUint64)(bigInt6) <= (PRUint64)(bigInt8))) { | |||
402 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
403 | } | |||
404 | ||||
405 | if ( !LL_UCMP( bigInt6, <=, bigInt9 )((PRUint64)(bigInt6) <= (PRUint64)(bigInt9))) { | |||
406 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
407 | } | |||
408 | ||||
409 | if ( !LL_UCMP( bigInt6, <=, bigInt10 )((PRUint64)(bigInt6) <= (PRUint64)(bigInt10))) { | |||
410 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
411 | } | |||
412 | ||||
413 | if ( !LL_UCMP( bigInt6, <=, bigInt11 )((PRUint64)(bigInt6) <= (PRUint64)(bigInt11))) { | |||
414 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
415 | } | |||
416 | ||||
417 | /* One positive, one negative */ | |||
418 | if ( !LL_UCMP( bigInt0, <=, bigInt6 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt6))) { | |||
419 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
420 | } | |||
421 | ||||
422 | if ( !LL_UCMP( bigInt0, <=, bigInt7 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt7))) { | |||
423 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
424 | } | |||
425 | ||||
426 | if ( !LL_UCMP( bigInt0, <=, bigInt8 )((PRUint64)(bigInt0) <= (PRUint64)(bigInt8))) { | |||
427 | SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); | |||
428 | } | |||
429 | ||||
430 | return; | |||
431 | } | |||
432 | ||||
433 | /* | |||
434 | ** TestLogicalOperations() -- Tests for AND, OR, ... | |||
435 | ** | |||
436 | */ | |||
437 | static void | |||
438 | TestLogicalOperations( void ) | |||
439 | { | |||
440 | PRUint64 result, result2; | |||
441 | ||||
442 | ReportProgress("Testing Logical Operations\n")if (verboseMode) PR_fprintf(output, ("Testing Logical Operations\n" ));; | |||
443 | ||||
444 | /* Test AND */ | |||
445 | LL_AND( result, bigZero, bigZero )((result) = (bigZero) & (bigZero)); | |||
446 | if ( !LL_IS_ZERO( result )((result) == 0)) { | |||
447 | ResultFailed( "LL_AND", "0 & 0", bigZero, result ); | |||
448 | } | |||
449 | ||||
450 | LL_AND( result, bigOne, bigOne )((result) = (bigOne) & (bigOne)); | |||
451 | if ( LL_IS_ZERO( result )((result) == 0)) { | |||
452 | ResultFailed( "LL_AND", "1 & 1", bigOne, result ); | |||
453 | } | |||
454 | ||||
455 | LL_AND( result, bigZero, bigOne )((result) = (bigZero) & (bigOne)); | |||
456 | if ( !LL_IS_ZERO( result )((result) == 0)) { | |||
457 | ResultFailed( "LL_AND", "1 & 1", bigZero, result ); | |||
458 | } | |||
459 | ||||
460 | LL_AND( result, bigMinusOne, bigMinusOne )((result) = (bigMinusOne) & (bigMinusOne)); | |||
461 | if ( !LL_UCMP( result, ==, bigMinusOne )((PRUint64)(result) == (PRUint64)(bigMinusOne))) { | |||
462 | ResultFailed( "LL_AND", "-1 & -1", bigMinusOne, result ); | |||
463 | } | |||
464 | ||||
465 | /* test OR */ | |||
466 | LL_OR( result, bigZero, bigZero )((result) = (bigZero) | (bigZero)); | |||
467 | if ( !LL_IS_ZERO( result )((result) == 0)) { | |||
468 | ResultFailed( "LL_OR", "0 | 1", bigZero, result); | |||
469 | } | |||
470 | ||||
471 | LL_OR( result, bigZero, bigOne )((result) = (bigZero) | (bigOne)); | |||
472 | if ( LL_IS_ZERO( result )((result) == 0)) { | |||
473 | ResultFailed( "LL_OR", "0 | 1", bigOne, result ); | |||
474 | } | |||
475 | ||||
476 | LL_OR( result, bigZero, bigMinusNumber )((result) = (bigZero) | (bigMinusNumber)); | |||
477 | if ( !LL_UCMP( result, ==, bigMinusNumber )((PRUint64)(result) == (PRUint64)(bigMinusNumber))) { | |||
478 | ResultFailed( "LL_OR", "0 | -n", bigMinusNumber, result); | |||
479 | } | |||
480 | ||||
481 | LL_OR( result, bigMinusNumber, bigZero )((result) = (bigMinusNumber) | (bigZero)); | |||
482 | if ( !LL_UCMP( result, ==, bigMinusNumber )((PRUint64)(result) == (PRUint64)(bigMinusNumber))) { | |||
483 | ResultFailed( "LL_OR", "-n | 0", bigMinusNumber, result ); | |||
484 | } | |||
485 | ||||
486 | /* test XOR */ | |||
487 | LL_XOR( result, bigZero, bigZero )((result) = (bigZero) ^ (bigZero)); | |||
488 | if ( LL_UCMP( result, !=, bigZero )((PRUint64)(result) != (PRUint64)(bigZero))) { | |||
489 | ResultFailed( "LL_XOR", "0 ^ 0", bigZero, result); | |||
490 | } | |||
491 | ||||
492 | LL_XOR( result, bigOne, bigZero )((result) = (bigOne) ^ (bigZero)); | |||
493 | if ( LL_UCMP( result, !=, bigOne )((PRUint64)(result) != (PRUint64)(bigOne))) { | |||
494 | ResultFailed( "LL_XOR", "1 ^ 0", bigZero, result ); | |||
495 | } | |||
496 | ||||
497 | LL_XOR( result, bigMinusNumber, bigZero )((result) = (bigMinusNumber) ^ (bigZero)); | |||
498 | if ( LL_UCMP( result, !=, bigMinusNumber )((PRUint64)(result) != (PRUint64)(bigMinusNumber))) { | |||
499 | ResultFailed( "LL_XOR", "-n ^ 0", bigMinusNumber, result ); | |||
500 | } | |||
501 | ||||
502 | LL_XOR( result, bigMinusNumber, bigMinusNumber )((result) = (bigMinusNumber) ^ (bigMinusNumber)); | |||
503 | if ( LL_UCMP( result, !=, bigZero )((PRUint64)(result) != (PRUint64)(bigZero))) { | |||
504 | ResultFailed( "LL_XOR", "-n ^ -n", bigMinusNumber, result); | |||
505 | } | |||
506 | ||||
507 | /* test OR2. */ | |||
508 | result = bigZero; | |||
509 | LL_OR2( result, bigOne )((result) = (result) | (bigOne)); | |||
510 | if ( LL_UCMP( result, !=, bigOne )((PRUint64)(result) != (PRUint64)(bigOne))) { | |||
511 | ResultFailed( "LL_OR2", "(r=0) |= 1", bigOne, result); | |||
512 | } | |||
513 | ||||
514 | result = bigOne; | |||
515 | LL_OR2( result, bigNumber )((result) = (result) | (bigNumber)); | |||
516 | if ( LL_UCMP( result, !=, bigNumber )((PRUint64)(result) != (PRUint64)(bigNumber))) { | |||
517 | ResultFailed( "LL_OR2", "(r=1) |= n", bigNumber, result); | |||
518 | } | |||
519 | ||||
520 | result = bigMinusNumber; | |||
521 | LL_OR2( result, bigMinusNumber )((result) = (result) | (bigMinusNumber)); | |||
522 | if ( LL_UCMP( result, !=, bigMinusNumber )((PRUint64)(result) != (PRUint64)(bigMinusNumber))) { | |||
523 | ResultFailed( "LL_OR2", "(r=-n) |= -n", bigMinusNumber, result); | |||
524 | } | |||
525 | ||||
526 | /* test NOT */ | |||
527 | LL_NOT( result, bigMinusNumber)((result) = ~(bigMinusNumber)); | |||
528 | LL_NOT( result2, result)((result2) = ~(result)); | |||
529 | if ( LL_UCMP( result2, !=, bigMinusNumber )((PRUint64)(result2) != (PRUint64)(bigMinusNumber))) { | |||
530 | ResultFailed( "LL_NOT", "r != ~(~-n)", bigMinusNumber, result); | |||
531 | } | |||
532 | ||||
533 | /* test Negation */ | |||
534 | LL_NEG( result, bigMinusNumber )((result) = -(bigMinusNumber)); | |||
535 | LL_NEG( result2, result )((result2) = -(result)); | |||
536 | if ( LL_CMP( result2, !=, bigMinusNumber )((PRInt64)(result2) != (PRInt64)(bigMinusNumber))) { | |||
537 | ResultFailed( "LL_NEG", "r != -(-(-n))", bigMinusNumber, result); | |||
538 | } | |||
539 | ||||
540 | return; | |||
541 | } | |||
542 | ||||
543 | ||||
544 | ||||
545 | /* | |||
546 | ** TestConversion() -- Test Conversion Operations | |||
547 | ** | |||
548 | */ | |||
549 | static void | |||
550 | TestConversion( void ) | |||
551 | { | |||
552 | PRInt64 result; | |||
553 | PRInt64 resultU; | |||
554 | PRInt32 result32; | |||
555 | PRUint32 resultU32; | |||
556 | float resultF; | |||
557 | PRFloat64 resultD; | |||
558 | ||||
559 | ReportProgress("Testing Conversion Operations\n")if (verboseMode) PR_fprintf(output, ("Testing Conversion Operations\n" ));; | |||
560 | ||||
561 | /* LL_L2I -- Convert to signed 32bit */ | |||
562 | LL_L2I(result32, bigOne )((result32) = (PRInt32)(bigOne)); | |||
563 | if ( result32 != one ) { | |||
564 | SetFailed( "LL_L2I", "r != 1"); | |||
565 | } | |||
566 | ||||
567 | LL_L2I(result32, bigMinusOne )((result32) = (PRInt32)(bigMinusOne)); | |||
568 | if ( result32 != minusOne ) { | |||
569 | SetFailed( "LL_L2I", "r != -1"); | |||
570 | } | |||
571 | ||||
572 | /* LL_L2UI -- Convert 64bit to unsigned 32bit */ | |||
573 | LL_L2UI( resultU32, bigMinusOne )((resultU32) = (PRUint32)(bigMinusOne)); | |||
574 | if ( resultU32 != (PRUint32) minusOne ) { | |||
575 | SetFailed( "LL_L2UI", "r != -1"); | |||
576 | } | |||
577 | ||||
578 | LL_L2UI( resultU32, bigOne )((resultU32) = (PRUint32)(bigOne)); | |||
579 | if ( resultU32 != (PRUint32) one ) { | |||
580 | SetFailed( "LL_L2UI", "r != 1"); | |||
581 | } | |||
582 | ||||
583 | /* LL_L2F -- Convert to 32bit floating point */ | |||
584 | LL_L2F( resultF, bigOne )((resultF) = (PRFloat64)(bigOne)); | |||
585 | if ( resultF != 1.0 ) { | |||
586 | SetFailed( "LL_L2F", "r != 1.0"); | |||
587 | } | |||
588 | ||||
589 | LL_L2F( resultF, bigMinusOne )((resultF) = (PRFloat64)(bigMinusOne)); | |||
590 | if ( resultF != -1.0 ) { | |||
591 | SetFailed( "LL_L2F", "r != 1.0"); | |||
592 | } | |||
593 | ||||
594 | /* LL_L2D -- Convert to 64bit floating point */ | |||
595 | LL_L2D( resultD, bigOne )((resultD) = (PRFloat64)(bigOne)); | |||
596 | if ( resultD != 1.0L ) { | |||
597 | SetFailed( "LL_L2D", "r != 1.0"); | |||
598 | } | |||
599 | ||||
600 | LL_L2D( resultD, bigMinusOne )((resultD) = (PRFloat64)(bigMinusOne)); | |||
601 | if ( resultD != -1.0L ) { | |||
602 | SetFailed( "LL_L2D", "r != -1.0"); | |||
603 | } | |||
604 | ||||
605 | /* LL_I2L -- Convert 32bit signed to 64bit signed */ | |||
606 | LL_I2L( result, one )((result) = (PRInt64)(one)); | |||
607 | if ( LL_CMP(result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
608 | SetFailed( "LL_I2L", "r != 1"); | |||
609 | } | |||
610 | ||||
611 | LL_I2L( result, minusOne )((result) = (PRInt64)(minusOne)); | |||
612 | if ( LL_CMP(result, !=, bigMinusOne )((PRInt64)(result) != (PRInt64)(bigMinusOne))) { | |||
613 | SetFailed( "LL_I2L", "r != -1"); | |||
614 | } | |||
615 | ||||
616 | /* LL_UI2L -- Convert 32bit unsigned to 64bit unsigned */ | |||
617 | LL_UI2L( resultU, (PRUint32) one )((resultU) = (PRInt64)((PRUint32) one)); | |||
618 | if ( LL_CMP(resultU, !=, bigOne )((PRInt64)(resultU) != (PRInt64)(bigOne))) { | |||
619 | SetFailed( "LL_UI2L", "r != 1"); | |||
620 | } | |||
621 | ||||
622 | /* [lth.] This did not behave as expected, but it is correct | |||
623 | */ | |||
624 | LL_UI2L( resultU, (PRUint32) minusOne )((resultU) = (PRInt64)((PRUint32) minusOne)); | |||
625 | if ( LL_CMP(resultU, !=, bigZeroFox )((PRInt64)(resultU) != (PRInt64)(bigZeroFox))) { | |||
626 | ResultFailed( "LL_UI2L", "r != -1", bigZeroFox, resultU); | |||
627 | } | |||
628 | ||||
629 | /* LL_F2L -- Convert 32bit float to 64bit signed */ | |||
630 | LL_F2L( result, 1.0 )((result) = (PRInt64)(1.0)); | |||
631 | if ( LL_CMP(result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
632 | SetFailed( "LL_F2L", "r != 1"); | |||
633 | } | |||
634 | ||||
635 | LL_F2L( result, -1.0 )((result) = (PRInt64)(-1.0)); | |||
636 | if ( LL_CMP(result, !=, bigMinusOne )((PRInt64)(result) != (PRInt64)(bigMinusOne))) { | |||
637 | SetFailed( "LL_F2L", "r != -1"); | |||
638 | } | |||
639 | ||||
640 | /* LL_D2L -- Convert 64bit Float to 64bit signed */ | |||
641 | LL_D2L( result, 1.0L )((result) = (PRInt64)(1.0L)); | |||
642 | if ( LL_CMP(result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
643 | SetFailed( "LL_D2L", "r != 1"); | |||
644 | } | |||
645 | ||||
646 | LL_D2L( result, -1.0L )((result) = (PRInt64)(-1.0L)); | |||
647 | if ( LL_CMP(result, !=, bigMinusOne )((PRInt64)(result) != (PRInt64)(bigMinusOne))) { | |||
648 | SetFailed( "LL_D2L", "r != -1"); | |||
649 | } | |||
650 | ||||
651 | return; | |||
652 | } | |||
653 | ||||
654 | static void ShiftCompileOnly() | |||
655 | { | |||
656 | /* | |||
657 | ** This function is only compiled, never called. | |||
658 | ** The real test is to see if it compiles w/o | |||
659 | ** warnings. This is no small feat, by the way. | |||
660 | */ | |||
661 | PRInt64 ia, ib; | |||
| ||||
662 | PRUint64 ua, ub; | |||
663 | LL_SHR(ia, ib, 32)((ia) = (PRInt64)(ib) >> (32)); | |||
| ||||
664 | LL_SHL(ia, ib, 32)((ia) = (PRInt64)(ib) << (32)); | |||
665 | ||||
666 | LL_USHR(ua, ub, 32)((ua) = (PRUint64)(ub) >> (32)); | |||
667 | LL_ISHL(ia, 49, 32)((ia) = (PRInt64)(49) << (32)); | |||
668 | ||||
669 | } /* ShiftCompileOnly */ | |||
670 | ||||
671 | ||||
672 | /* | |||
673 | ** TestShift() -- Test Shifting Operations | |||
674 | ** | |||
675 | */ | |||
676 | static void | |||
677 | TestShift( void ) | |||
678 | { | |||
679 | static const PRInt64 largeTwoZero = LL_INIT( 0x00000002, 0x00000000 )((0x00000002L << 32) + 0x00000000L); | |||
680 | PRInt64 result; | |||
681 | PRUint64 resultU; | |||
682 | ||||
683 | ReportProgress("Testing Shifting Operations\n")if (verboseMode) PR_fprintf(output, ("Testing Shifting Operations\n" ));; | |||
684 | ||||
685 | /* LL_SHL -- Shift left algebraic */ | |||
686 | LL_SHL( result, bigOne, one )((result) = (PRInt64)(bigOne) << (one)); | |||
687 | if ( LL_CMP( result, !=, bigTwo )((PRInt64)(result) != (PRInt64)(bigTwo))) { | |||
688 | ResultFailed( "LL_SHL", "r != 2", bigOne, result ); | |||
689 | } | |||
690 | ||||
691 | LL_SHL( result, bigTwo, thirtyTwo )((result) = (PRInt64)(bigTwo) << (thirtyTwo)); | |||
692 | if ( LL_CMP( result, !=, largeTwoZero )((PRInt64)(result) != (PRInt64)(largeTwoZero))) { | |||
693 | ResultFailed( "LL_SHL", "r != twoZero", largeTwoZero, result); | |||
694 | } | |||
695 | ||||
696 | /* LL_SHR -- Shift right algebraic */ | |||
697 | LL_SHR( result, bigFoxZero, thirtyTwo )((result) = (PRInt64)(bigFoxZero) >> (thirtyTwo)); | |||
698 | if ( LL_CMP( result, !=, bigMinusOne )((PRInt64)(result) != (PRInt64)(bigMinusOne))) { | |||
699 | ResultFailed( "LL_SHR", "r != -1", bigMinusOne, result); | |||
700 | } | |||
701 | ||||
702 | LL_SHR( result, bigTwo, one )((result) = (PRInt64)(bigTwo) >> (one)); | |||
703 | if ( LL_CMP( result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
704 | ResultFailed( "LL_SHR", "r != 1", bigOne, result); | |||
705 | } | |||
706 | ||||
707 | LL_SHR( result, bigFoxFox, thirtyTwo )((result) = (PRInt64)(bigFoxFox) >> (thirtyTwo)); | |||
708 | if ( LL_CMP( result, !=, bigMinusOne )((PRInt64)(result) != (PRInt64)(bigMinusOne))) { | |||
709 | ResultFailed( "LL_SHR", "r != -1 (was ff,ff)", bigMinusOne, result); | |||
710 | } | |||
711 | ||||
712 | /* LL_USHR -- Logical shift right */ | |||
713 | LL_USHR( resultU, bigZeroFox, thirtyTwo )((resultU) = (PRUint64)(bigZeroFox) >> (thirtyTwo)); | |||
714 | if ( LL_UCMP( resultU, !=, bigZero )((PRUint64)(resultU) != (PRUint64)(bigZero))) { | |||
715 | ResultFailed( "LL_USHR", "r != 0 ", bigZero, result); | |||
716 | } | |||
717 | ||||
718 | LL_USHR( resultU, bigFoxFox, thirtyTwo )((resultU) = (PRUint64)(bigFoxFox) >> (thirtyTwo)); | |||
719 | if ( LL_UCMP( resultU, !=, bigZeroFox )((PRUint64)(resultU) != (PRUint64)(bigZeroFox))) { | |||
720 | ResultFailed( "LL_USHR", "r != 0 ", bigZeroFox, result); | |||
721 | } | |||
722 | ||||
723 | /* LL_ISHL -- Shift a 32bit integer into a 64bit result */ | |||
724 | LL_ISHL( resultU, minusOne, thirtyTwo )((resultU) = (PRInt64)(minusOne) << (thirtyTwo)); | |||
725 | if ( LL_UCMP( resultU, !=, bigFoxZero )((PRUint64)(resultU) != (PRUint64)(bigFoxZero))) { | |||
726 | ResultFailed( "LL_ISHL", "r != ff,00 ", bigFoxZero, result); | |||
727 | } | |||
728 | ||||
729 | LL_ISHL( resultU, one, sixtyThree )((resultU) = (PRInt64)(one) << (sixtyThree)); | |||
730 | if ( LL_UCMP( resultU, !=, bigEightZero )((PRUint64)(resultU) != (PRUint64)(bigEightZero))) { | |||
731 | ResultFailed( "LL_ISHL", "r != 80,00 ", bigEightZero, result); | |||
732 | } | |||
733 | ||||
734 | LL_ISHL( resultU, one, sixteen )((resultU) = (PRInt64)(one) << (sixteen)); | |||
735 | if ( LL_UCMP( resultU, !=, big64K )((PRUint64)(resultU) != (PRUint64)(big64K))) { | |||
736 | ResultFailed( "LL_ISHL", "r != 64K ", big64K, resultU); | |||
737 | } | |||
738 | ||||
739 | return; | |||
740 | } | |||
741 | ||||
742 | ||||
743 | /* | |||
744 | ** TestArithmetic() -- Test arithmetic operations. | |||
745 | ** | |||
746 | */ | |||
747 | static void | |||
748 | TestArithmetic( void ) | |||
749 | { | |||
750 | PRInt64 largeVal = LL_INIT( 0x00000001, 0xffffffff )((0x00000001L << 32) + 0xffffffffL); | |||
751 | PRInt64 largeValPlusOne = LL_INIT( 0x00000002, 0x00000000 )((0x00000002L << 32) + 0x00000000L); | |||
752 | PRInt64 largeValTimesTwo = LL_INIT( 0x00000003, 0xfffffffe )((0x00000003L << 32) + 0xfffffffeL); | |||
753 | PRInt64 largeMultCand = LL_INIT( 0x00000000, 0x7fffffff )((0x00000000L << 32) + 0x7fffffffL); | |||
754 | PRInt64 largeMinusMultCand = LL_INIT( 0xffffffff, 0x10000001 )((0xffffffffL << 32) + 0x10000001L); | |||
755 | PRInt64 largeMultCandx64K = LL_INIT( 0x00007fff, 0xffff0000 )((0x00007fffL << 32) + 0xffff0000L); | |||
756 | PRInt64 largeNumSHL5 = LL_INIT( 0x0000001f, 0xffffffe0 )((0x0000001fL << 32) + 0xffffffe0L); | |||
757 | PRInt64 result, result2; | |||
758 | ||||
759 | /* Addition */ | |||
760 | LL_ADD( result, bigOne, bigOne )((result) = (bigOne) + (bigOne)); | |||
761 | if ( LL_CMP( result, !=, bigTwo )((PRInt64)(result) != (PRInt64)(bigTwo))) { | |||
762 | ResultFailed( "LL_ADD", "r != 1 + 1", bigTwo, result); | |||
763 | } | |||
764 | ||||
765 | LL_ADD( result, bigMinusOne, bigOne )((result) = (bigMinusOne) + (bigOne)); | |||
766 | if ( LL_CMP( result, !=, bigZero )((PRInt64)(result) != (PRInt64)(bigZero))) { | |||
767 | ResultFailed( "LL_ADD", "r != -1 + 1", bigOne, result); | |||
768 | } | |||
769 | ||||
770 | LL_ADD( result, largeVal, bigOne )((result) = (largeVal) + (bigOne)); | |||
771 | if ( LL_CMP( result, !=, largeValPlusOne )((PRInt64)(result) != (PRInt64)(largeValPlusOne))) { | |||
772 | ResultFailed( "LL_ADD", "lVP1 != lV + 1", largeValPlusOne, result); | |||
773 | } | |||
774 | ||||
775 | /* Subtraction */ | |||
776 | LL_SUB( result, bigOne, bigOne )((result) = (bigOne) - (bigOne)); | |||
777 | if ( LL_CMP( result, !=, bigZero )((PRInt64)(result) != (PRInt64)(bigZero))) { | |||
778 | ResultFailed( "LL_SUB", "r != 1 - 1", bigZero, result); | |||
779 | } | |||
780 | ||||
781 | LL_SUB( result, bigTwo, bigOne )((result) = (bigTwo) - (bigOne)); | |||
782 | if ( LL_CMP( result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
783 | ResultFailed( "LL_SUB", "r != 2 - 1", bigOne, result); | |||
784 | } | |||
785 | ||||
786 | LL_SUB( result, largeValPlusOne, bigOne )((result) = (largeValPlusOne) - (bigOne)); | |||
787 | if ( LL_CMP( result, !=, largeVal )((PRInt64)(result) != (PRInt64)(largeVal))) { | |||
788 | ResultFailed( "LL_SUB", "r != lVP1 - 1", largeVal, result); | |||
789 | } | |||
790 | ||||
791 | ||||
792 | /* Multiply */ | |||
793 | LL_MUL( result, largeVal, bigTwo )((result) = (largeVal) * (bigTwo)); | |||
794 | if ( LL_CMP( result, !=, largeValTimesTwo )((PRInt64)(result) != (PRInt64)(largeValTimesTwo))) { | |||
795 | ResultFailed( "LL_MUL", "r != lV*2", largeValTimesTwo, result); | |||
796 | } | |||
797 | ||||
798 | LL_MUL( result, largeMultCand, big64K )((result) = (largeMultCand) * (big64K)); | |||
799 | if ( LL_CMP( result, !=, largeMultCandx64K )((PRInt64)(result) != (PRInt64)(largeMultCandx64K))) { | |||
800 | ResultFailed( "LL_MUL", "r != lV*64K", largeMultCandx64K, result); | |||
801 | } | |||
802 | ||||
803 | LL_NEG( result2, largeMultCand )((result2) = -(largeMultCand)); | |||
804 | LL_MUL( result, largeMultCand, bigMinusOne )((result) = (largeMultCand) * (bigMinusOne)); | |||
805 | if ( LL_CMP( result, !=, result2 )((PRInt64)(result) != (PRInt64)(result2))) { | |||
806 | ResultFailed( "LL_MUL", "r != -lMC", result2, result); | |||
807 | } | |||
808 | ||||
809 | LL_SHL( result2, bigZeroFox, 5)((result2) = (PRInt64)(bigZeroFox) << (5)); | |||
810 | LL_MUL( result, bigZeroFox, bigThirtyTwo )((result) = (bigZeroFox) * (bigThirtyTwo)); | |||
811 | if ( LL_CMP( result, !=, largeNumSHL5 )((PRInt64)(result) != (PRInt64)(largeNumSHL5))) { | |||
812 | ResultFailed( "LL_MUL", "r != 0f<<5", largeNumSHL5, result ); | |||
813 | } | |||
814 | ||||
815 | ||||
816 | ||||
817 | /* LL_DIV() Division */ | |||
818 | LL_DIV( result, bigOne, bigOne)((result) = (bigOne) / (bigOne)); | |||
819 | if ( LL_CMP( result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
820 | ResultFailed( "LL_DIV", "1 != 1", bigOne, result); | |||
821 | } | |||
822 | ||||
823 | LL_DIV( result, bigNumber, bigOne )((result) = (bigNumber) / (bigOne)); | |||
824 | if ( LL_CMP( result, !=, bigNumber )((PRInt64)(result) != (PRInt64)(bigNumber))) { | |||
825 | ResultFailed( "LL_DIV", "r != n / 1", bigNumber, result); | |||
826 | } | |||
827 | ||||
828 | LL_DIV( result, bigNumber, bigMinusOne )((result) = (bigNumber) / (bigMinusOne)); | |||
829 | if ( LL_CMP( result, !=, bigMinusNumber )((PRInt64)(result) != (PRInt64)(bigMinusNumber))) { | |||
830 | ResultFailed( "LL_DIV", "r != n / -1", bigMinusNumber, result); | |||
831 | } | |||
832 | ||||
833 | LL_DIV( result, bigMinusNumber, bigMinusOne )((result) = (bigMinusNumber) / (bigMinusOne)); | |||
834 | if ( LL_CMP( result, !=, bigNumber )((PRInt64)(result) != (PRInt64)(bigNumber))) { | |||
835 | ResultFailed( "LL_DIV", "r != -n / -1", bigNumber, result); | |||
836 | } | |||
837 | ||||
838 | LL_SHL( result2, bigZeroFox, 5 )((result2) = (PRInt64)(bigZeroFox) << (5)); | |||
839 | LL_DIV( result, result2, bigOne )((result) = (result2) / (bigOne)); | |||
840 | if ( LL_CMP( result, !=, result2 )((PRInt64)(result) != (PRInt64)(result2))) { | |||
841 | ResultFailed( "LL_DIV", "0f<<5 != 0f<<5", result2, result); | |||
842 | } | |||
843 | ||||
844 | LL_SHL( result2, bigZeroFox, 5 )((result2) = (PRInt64)(bigZeroFox) << (5)); | |||
845 | LL_NEG( result2, result2 )((result2) = -(result2)); | |||
846 | LL_DIV( result, result2, bigOne )((result) = (result2) / (bigOne)); | |||
847 | if ( LL_CMP( result, !=, result2 )((PRInt64)(result) != (PRInt64)(result2))) { | |||
848 | ResultFailed( "LL_DIV", "-0f<<5 != -0f<<5", result2, result); | |||
849 | } | |||
850 | ||||
851 | LL_SHL( result2, bigZeroFox, 17 )((result2) = (PRInt64)(bigZeroFox) << (17)); | |||
852 | LL_DIV( result, result2, bigMinusOne )((result) = (result2) / (bigMinusOne)); | |||
853 | LL_NEG( result2, result2 )((result2) = -(result2)); | |||
854 | if ( LL_CMP( result, !=, result2 )((PRInt64)(result) != (PRInt64)(result2))) { | |||
855 | ResultFailed( "LL_DIV", "-0f<<17 != -0f<<17", result2, result); | |||
856 | } | |||
857 | ||||
858 | ||||
859 | /* LL_MOD() Modulo Division */ | |||
860 | LL_ADD( result2, bigThirtyTwo, bigOne )((result2) = (bigThirtyTwo) + (bigOne)); | |||
861 | LL_MOD( result, result2, bigSixTeen )((result) = (result2) % (bigSixTeen)); | |||
862 | if ( LL_CMP( result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
863 | ResultFailed( "LL_MOD", "r != 1", bigSixTeen, result); | |||
864 | } | |||
865 | ||||
866 | ||||
867 | LL_MUL( result2, bigZeroFox, bigThirtyTwo )((result2) = (bigZeroFox) * (bigThirtyTwo)); | |||
868 | LL_ADD( result2, result2, bigSixTeen)((result2) = (result2) + (bigSixTeen)); | |||
869 | LL_MOD( result, result2, bigThirtyTwo )((result) = (result2) % (bigThirtyTwo)); | |||
870 | if ( LL_CMP( result, !=, bigSixTeen )((PRInt64)(result) != (PRInt64)(bigSixTeen))) { | |||
871 | ResultFailed( "LL_MOD", "r != 16", bigSixTeen, result); | |||
872 | } | |||
873 | ||||
874 | /* LL_UDIVMOD */ | |||
875 | LL_DIV( result, bigOne, bigOne)((result) = (bigOne) / (bigOne)); | |||
876 | if ( LL_CMP( result, !=, bigOne )((PRInt64)(result) != (PRInt64)(bigOne))) { | |||
877 | ResultFailed( "LL_DIV", "r != 16", bigSixTeen, result); | |||
878 | } | |||
879 | ||||
880 | ||||
881 | return; | |||
882 | } | |||
883 | ||||
884 | static void TestWellknowns(void) | |||
885 | { | |||
886 | PRInt64 max = LL_MAXINT9223372036854775807L, min = LL_MININT(-9223372036854775807L - 1L), zero = LL_ZERO0L; | |||
887 | PRInt64 mmax = LL_MaxInt(), mmin = LL_MinInt(), mzero = LL_Zero(); | |||
888 | if (LL_NE(max, mmax)((max) != (mmax))) { | |||
889 | ResultFailed( "max, mmax", "max != mmax", max, mmax); | |||
890 | } | |||
891 | if (LL_NE(min, mmin)((min) != (mmin))) { | |||
892 | ResultFailed( "min, mmin", "min != mmin", max, mmin); | |||
893 | } | |||
894 | if (LL_NE(zero, mzero)((zero) != (mzero))) { | |||
895 | ResultFailed( "zero, mzero", "zero != mzero", zero, mzero); | |||
896 | } | |||
897 | } /* TestWellknowns */ | |||
898 | ||||
899 | /* | |||
900 | ** Initialize() -- Initialize the test case | |||
901 | ** | |||
902 | ** Parse command line options | |||
903 | ** | |||
904 | */ | |||
905 | static PRIntn | |||
906 | Initialize( PRIntn argc, char **argv ) | |||
907 | { | |||
908 | PLOptState *opt = PL_CreateOptState(argc, argv, "dvh"); | |||
909 | PLOptStatus os; | |||
910 | ||||
911 | /* | |||
912 | ** Parse command line options | |||
913 | */ | |||
914 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) | |||
915 | { | |||
916 | if (PL_OPT_BAD == os) { | |||
917 | continue; | |||
918 | } | |||
919 | switch (opt->option) | |||
920 | { | |||
921 | case 'd': /* set debug mode */ | |||
922 | debugMode = PR_TRUE1; | |||
923 | break; | |||
924 | ||||
925 | case 'v': /* set verbose mode */ | |||
926 | verboseMode = PR_TRUE1; | |||
927 | debugMode = PR_TRUE1; | |||
928 | break; | |||
929 | ||||
930 | case 'h': /* user wants some guidance */ | |||
931 | default: | |||
932 | PR_fprintf(output, "You get help.\n"); | |||
933 | return(1); | |||
934 | } | |||
935 | } | |||
936 | PL_DestroyOptState(opt); | |||
937 | return(0); | |||
938 | } | |||
939 | ||||
940 | int main(int argc, char **argv) | |||
941 | { | |||
942 | PR_STDIO_INIT(); | |||
943 | output = PR_GetSpecialFD(PR_StandardError); | |||
944 | ||||
945 | if ( Initialize( argc, argv )) { | |||
946 | return(1); | |||
947 | } | |||
948 | ||||
949 | TestAssignment(); | |||
950 | TestComparisons(); | |||
951 | TestLogicalOperations(); | |||
952 | TestConversion(); | |||
953 | TestShift(); | |||
954 | TestArithmetic(); | |||
955 | TestWellknowns(); | |||
956 | ||||
957 | /* | |||
958 | ** That's all folks! | |||
959 | */ | |||
960 | if ( failedAlready ) | |||
961 | { | |||
962 | PR_fprintf(output, "FAIL\n"); \ | |||
963 | } | |||
964 | else | |||
965 | { | |||
966 | PR_fprintf(output, "PASS\n"); \ | |||
967 | } | |||
968 | return failedAlready; | |||
969 | } /* end main() */ |