2 !!DESCRIPTION!! Signed comparisons of the form: (variable>=LIT)
3 !!ORIGIN!! SDCC regression tests
4 !!LICENCE!! GPL, read COPYING.GPL
10 /* This regression test exercises all of the boundary
11 conditions in literal less than comparisons. There
12 are numerous opportunities to optimize these comparison
13 and each one has an astonishing capability of failing
16 unsigned char success = 0;
17 unsigned char failures = 0;
18 unsigned char dummy = 0;
19 unsigned char result = 0;
21 #ifdef SUPPORT_BIT_TYPES
26 unsigned char uchar0 = 0;
27 unsigned char uchar1 = 0;
28 signed char char0 = 0;
29 signed char char1 = 0;
33 /* *** NOTE *** This particular test takes quite a while to run
34 * ~ 10,000,000 instruction cycles. (2.5 seconds on a 20Mhz PIC).
35 * The WDT will reset the CPU if it's enabled. So disable it...
44 void c_char_gte_lit1(unsigned char expected_result)
66 if(result != expected_result)
69 printf("c_char_gte_lit1: char %02x - result %02x expected: %02x\n",char0,result,expected_result);
73 /* printf("char %02x - %02x failures: %d\n",char0,expected_result,failures); */
76 void char_compare(void)
79 c_char_gte_lit1(0x3f);
82 c_char_gte_lit1(0x1f);
85 c_char_gte_lit1(0x0f);
88 c_char_gte_lit1(0x0f);
91 c_char_gte_lit1(0x0f);
94 c_char_gte_lit1(0x07);
97 c_char_gte_lit1(0x03);
100 c_char_gte_lit1(0x01);
103 c_char_gte_lit1(0x01);
106 c_char_gte_lit1(0x01);
109 c_char_gte_lit1(0x01);
112 c_char_gte_lit1(0x00);
114 /* Now test entire range */
116 for(char0=1; char0 != 0x7e; char0++)
117 c_char_gte_lit1(0x0f);
119 for(char0=-0x7f; char0 != -1; char0++)
120 c_char_gte_lit1(0x01);
123 void c_int_gte_lit1(unsigned char expected_result)
151 if(result != expected_result)
155 void int_compare1(void)
158 c_int_gte_lit1(0x00);
161 c_int_gte_lit1(0x01);
164 c_int_gte_lit1(0x03);
167 c_int_gte_lit1(0x03);
170 c_int_gte_lit1(0x03);
173 c_int_gte_lit1(0x07);
176 c_int_gte_lit1(0x0f);
179 c_int_gte_lit1(0x1f);
182 c_int_gte_lit1(0x1f);
185 c_int_gte_lit1(0x1f);
188 c_int_gte_lit1(0x3f);
191 c_int_gte_lit1(0x7f);
194 c_int_gte_lit1(0xff);
197 c_int_gte_lit1(0xff);
199 /* now check contiguous ranges */
201 for(int0 = -0x7fff; int0 != -1; int0++)
202 c_int_gte_lit1(0x00);
204 for(int0 = 1; int0 != 0xff; int0++)
205 c_int_gte_lit1(0x03);
207 for(int0 = 0x201; int0 != 0x7fff; int0++)
208 c_int_gte_lit1(0xff);
211 void c_int_gte_lit2(unsigned char expected_result)
239 if(result != expected_result)
243 void int_compare2(void)
246 c_int_gte_lit2(0x01);
249 c_int_gte_lit2(0x03);
252 c_int_gte_lit2(0x07);
255 c_int_gte_lit2(0x0f);
258 c_int_gte_lit2(0x0f);
261 c_int_gte_lit2(0x0f);
264 c_int_gte_lit2(0x0f);
267 c_int_gte_lit2(0x0f);
270 c_int_gte_lit2(0x1f);
273 c_int_gte_lit2(0x3f);
276 c_int_gte_lit2(0x7f);
279 c_int_gte_lit2(0x7f);
282 c_int_gte_lit2(0xff);
285 c_int_gte_lit2(0xff);
288 c_int_gte_lit2(0xff);
291 c_int_gte_lit2(0xff);
293 /* now check contiguous ranges */
295 for(int0 = -0x7fff; int0 != -0x7f00; int0++)
296 c_int_gte_lit2(0x01);
298 for(int0 = -0x7e00; int0 != -0x101; int0++)
299 c_int_gte_lit2(0x0f);
301 for(int0 = -1; int0 != 0x7fff; int0++)
302 c_int_gte_lit2(0xff);
309 printf("failures: %d\n",failures);
311 printf("failures: %d\n",failures);
316 printf("failures: %d\n",failures);