1 /** Simple long long tests.
2 test: mul, div, bit, shift
13 #if !(defined(__SDCC_mcs51) && !defined(__SDCC_STACK_AUTO) && defined(__SDCC_MODEL_SMALL) ) && !defined(__SDCC_pic14) && !defined(__SDCC_pic16) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
41 long long (*gp
)(void) = &g
;
43 static unsigned long long mulLL(unsigned long long a
, unsigned long long b
)
51 volatile unsigned long tmp
;
56 ASSERT ((*gp
)() == 24);
60 ASSERT (d(12) == 12ll);
61 ASSERT ((x
>> 1) == 21);
62 ASSERT ((x
<< 1) == 84);
64 ASSERT ((x
<< 17) == (42l << 17));
67 ASSERT ((y
>> 1) == 21);
68 ASSERT ((y
<< 1) == 84);
69 ASSERT ((y
>> 17) == 0);
70 ASSERT ((y
<< 17) == (42ul << 17));
71 ASSERT ((y
<< 16) == (42ul << 16));
76 ASSERT ((unsigned char)y
== (unsigned char)tmp
);
77 ASSERT ((unsigned int)y
== (unsigned int)tmp
);
78 ASSERT ((unsigned long)y
== (unsigned long)tmp
);
80 ASSERT ((y
>> 8) == (tmp
>>= 8));
81 ASSERT ((y
>> 12) == (tmp
>>= 4));
82 ASSERT ((y
>> 16) == (tmp
>>= 4));
83 ASSERT ((y
>> 24) == (tmp
>>= 8));
84 ASSERT ((y
>> 32) == 0x0ul
);
89 ASSERT ((y
<< 1) == 2);
90 ASSERT ((y
<< 16) == (tmp
<< 16));
91 ASSERT ((y
<< 23) == (tmp
<< 23));
100 ASSERT (y
+ tmp
== 42 + 23);
101 ASSERT (y
- tmp
== 42 - 23);
102 ASSERT (y
* tmp
== 42 * 23);
103 ASSERT (y
/ tmp
== 42 / 23);
104 ASSERT (y
% tmp
== 42 % 23);
108 ASSERT (x
+ y
== (42ll << 23) + 42);
109 ASSERT (x
- y
== (42ll << 23) - 42);
110 ASSERT (x
* y
== (42ll << 23) * 42);
111 ASSERT (x
/ tmp
== (42ll << 23) / 42);
112 ASSERT (x
% tmp
== (42ll << 23) % 42);
114 x
= 0x1122334455667788ll
;
115 y
= 0x9988776655443322ull
;
116 ASSERT (y
+ x
== 0x9988776655443322ull
+ 0x1122334455667788ll
);
117 ASSERT (y
- x
== 0x9988776655443322ull
- 0x1122334455667788ll
);
119 ASSERT (mulLL (1ull, 1ull) == 1ull * 1ull);
122 ASSERT (y
* y
== 0x55667788ull
* 0x55667788ull
); // this test is optimized by constant propagation
123 ASSERT (mulLL (y
, y
) == 0x55667788ull
* 0x55667788ull
); // this test is not
126 ASSERT (y
* x
== 0x55667788ull
* 0x55667788ll
); // this test is optimized by constant propagation
127 ASSERT (mulLL (y
, x
) == 0x55667788ull
* 0x55667788ll
); // this test is not
130 ASSERT (y
* y
== 0xa5667788ull
* 0xa5667788ull
); // this test is optimized by constant propagation
131 ASSERT (mulLL (y
, y
) == 0xa5667788ull
* 0xa5667788ull
); // this test is not
134 ASSERT (y
* x
== 0xa5667788ull
* 0xa5667788ll
); // this test is optimized by constant propagation
135 ASSERT (mulLL (y
, x
) == 0xa5667788ull
* 0xa5667788ull
); // this test is not
137 y
= 0xa5667788ccddull
;
139 ASSERT (y
* x
== 0xa5667788ccddull
* 0x0788ll
); // this test is optimized by constant propagation
140 ASSERT (mulLL (y
, x
) == 0xa5667788ccddull
* 0x0788ll
); // this test is not
142 y
= 0x1122334455667700ull
;
144 ASSERT (y
* x
== 0x1122334455667700ull
* 0x2ll
); // this test is optimized by constant propagation
145 ASSERT (mulLL (y
, x
) == 0x1122334455667700ull
* 0x2ll
); // this test is not
147 c(); // Unused long long return value requires special handling in register allocation.
150 #elif defined(TEST_div)
152 static unsigned long long divULL(unsigned long long a
, unsigned long long b
)
157 static unsigned long long modULL(unsigned long long a
, unsigned long long b
)
162 static long long divLL(long long a
, long long b
)
167 static long long modLL(long long a
, long long b
)
175 y
= 0x1122334455667700ull
;
177 ASSERT (y
/ x
== 0x1122334455667700ull
/ 0x7ll
); // this test is optimized by constant propagation
178 ASSERT (divULL (y
, x
) == 0x1122334455667700ull
/ 0x7ll
); // this test is not
179 ASSERT (y
% x
== 0x1122334455667700ull
% 0x7ll
); // this test is optimized by constant propagation
180 ASSERT (modULL (y
, x
) == 0x1122334455667700ull
% 0x7ll
); // this test is not
181 x
= 0x1122334455667700ll
;
182 ASSERT (x
/ 0x7ll
== 0x1122334455667700ll
/ 0x7ll
); // this test is optimized by constant propagation
183 ASSERT (divLL (x
, 0x7ll
) == 0x1122334455667700ll
/ 0x7ll
); // this test is not
184 ASSERT (x
% 0x7ll
== 0x1122334455667700ll
% 0x7ll
); // this test is optimized by constant propagation
185 ASSERT (modLL (x
, 0x7ll
) == 0x1122334455667700ll
% 0x7ll
); // this test is not
188 #elif defined(TEST_bit)
190 static int compareLL(unsigned long long a
, unsigned long long b
)
200 static long long leftShiftLL(long long a
)
205 static long long rightShiftLL(long long a
)
210 static unsigned long long rightShiftULL(unsigned long long a
)
215 static unsigned long long leftShiftULL(unsigned long long a
)
220 static unsigned long long bitAndULL(unsigned long long a
, unsigned long long b
)
225 static unsigned long long bitOrULL(unsigned long long a
, unsigned long long b
)
230 static unsigned long long bitXorULL(unsigned long long a
, unsigned long long b
)
235 static unsigned long long bitNotULL(unsigned long long a
)
243 y
= 0x44556677aabbccddull
;
244 x
= 0x7766554433221100ull
;
247 ASSERT (compareLL (y
, x
) == -1);
248 ASSERT (compareLL (x
, y
) == 1);
250 y
= 0x5566778899aabbccull
;
251 x
= 0xaabbccdd11223344ll
;
252 ASSERT ((y
<< 8) == 0x66778899aabbcc00ull
);
253 ASSERT (leftShiftULL (y
) == 0x66778899aabbcc00ull
);
254 ASSERT ((y
>> 8) == 0x005566778899aabbull
);
255 ASSERT (rightShiftULL (y
) == 0x005566778899aabbull
);
256 ASSERT ((x
<< 8) == 0xbbccdd1122334400ll
);
257 ASSERT (leftShiftLL (x
) == 0xbbccdd1122334400ll
);
258 ASSERT ((x
>> 8) == 0xffaabbccdd112233ll
);
259 ASSERT (rightShiftLL (x
) == 0xffaabbccdd112233ll
);
261 x
= 0x44556677aabbccddll
;
262 ASSERT (++x
== 0x44556677aabbccdell
);
263 y
= 0x99556677aabbccddull
;
264 ASSERT (--y
== 0x99556677aabbccdcull
);
266 y
= 0x69aaaaaaaaaa55aaull
;
267 x
= 0x69555555555555aall
;
268 ASSERT ((y
& x
) == (0x69aaaaaaaaaa55aaull
& 0x69555555555555aall
));
269 ASSERT (bitAndULL (y
, x
) == (0x69aaaaaaaaaa55aaull
& 0x69555555555555aall
));
270 ASSERT ((y
| x
) == (0x69aaaaaaaaaa55aaull
| 0x69555555555555aall
));
271 ASSERT (bitOrULL (y
, x
) == (0x69aaaaaaaaaa55aaull
| 0x69555555555555aall
));
272 ASSERT ((y
^ x
) == (0x69aaaaaaaaaa55aaull
^ 0x69555555555555aall
));
273 ASSERT (bitXorULL (y
, x
) == (0x69aaaaaaaaaa55aaull
^ 0x69555555555555aall
));
274 ASSERT ((~y
) == (~0x69aaaaaaaaaa55aaull
));
275 ASSERT (bitNotULL (y
) == (~0x69aaaaaaaaaa55aaull
));
278 #elif defined(TEST_shift)
281 LongLong_shift (void)
283 unsigned char i
,j
,expected
,match
;
289 if ((unsigned char)(y
& 1) == expected
)
297 y
= 0x8000000000000000ull
>> i
;
301 if ((y
& 0x8000000000000000ull
) ? expected
: !expected
)
309 x
= (signed long long)0x8000000000000000ll
>> i
;
313 if ((x
& 0x8000000000000000ll
) ? expected
: !expected
)
322 #endif //TEST_mul/div/bit/shift
324 #endif //!mcs51-small
329 #if !(defined(__SDCC_mcs51) && !defined(__SDCC_STACK_AUTO) && defined(__SDCC_MODEL_SMALL) ) && !defined(__SDCC_pic14) && !defined(__SDCC_pic16) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory