f7b1b4a83424c097cdd55ca63664d025b89c03a5
[fw/sdcc] / src / regression / compare8.c
1 #include "gpsim_assert.h"
2 #include "picregs.h"
3 // Signed comparisons of the form:  (variable>LIT)
4 //
5 // This regression test exercises all of the boundary
6 // conditions in literal less than comparisons. There
7 // are numerous opportunities to optimize these comparison
8 // and each one has an astonishing capability of failing
9 // a boundary condition.
10
11 unsigned char failures = 0;
12 unsigned char result = 0;
13
14 //bit bit0 = 0;
15 int int0 = 0;
16 int int1 = 0;
17 unsigned char uchar0 = 0;
18 unsigned char uchar1 = 0;
19 signed char char0 = 0;
20 signed char char1 = 0;
21 char long0 = 0;
22 char long1 = 0;
23
24 /* *** NOTE ***  This particular test takes quite a while to run 
25  * ~ 10,000,000 instruction cycles. (2.5 seconds on a 20Mhz PIC).
26  * The WDT will reset the CPU if it's enabled. So disable it...
27 */
28
29 typedef unsigned int word;
30
31 //word at 0x2007  CONFIG = wdt_off & pwrte_on;
32
33 void
34 done()
35 {
36   ASSERT(MANGLE(failures) == 0);
37   PASSED();
38 }
39
40 void c_char_gt_lit1(unsigned char expected_result)
41 {
42   result = 0;
43
44   if(char0 > -0x7f)
45     result |= 1;
46
47
48   if(char0 > -1)
49     result |= 2;
50
51   if(char0 > 0)
52     result |= 4;
53
54   if(char0 > 1)
55     result |= 8;
56
57   if(char0 > 0x7e)
58     result |= 0x10;
59   
60   if(char0 > 0x7f)
61     result |= 0x20;
62   
63   if(result != expected_result)
64     failures++;
65 }
66
67
68 void char_compare(void)
69 {
70   char0 = 0x7f;
71   c_char_gt_lit1(0x1f);
72
73   char0 = 0x7e;
74   c_char_gt_lit1(0x0f);
75
76   char0 = 0x40;
77   c_char_gt_lit1(0x0f);
78
79   char0 = 0x2;
80   c_char_gt_lit1(0x0f);
81
82   char0 = 0x1;
83   c_char_gt_lit1(0x07);
84
85   char0 = 0;
86   c_char_gt_lit1(0x03);
87
88   char0 = -1;
89   c_char_gt_lit1(0x01);
90
91   char0 = -2;
92   c_char_gt_lit1(0x01);
93
94   char0 = -0x40;
95   c_char_gt_lit1(0x01);
96
97   char0 = -0x7e;
98   c_char_gt_lit1(0x01);
99
100   char0 = -0x7f;
101   c_char_gt_lit1(0x00);
102
103   char0 = 0x80;
104   c_char_gt_lit1(0x00);
105
106
107   /* Now test entire range */
108
109   for(char0=2; char0 != 0x7f; char0++)
110     c_char_gt_lit1(0x0f);
111
112
113   for(char0=-0x7e; char0 != -1; char0++)
114     c_char_gt_lit1(0x01);
115
116
117 }
118
119
120 void c_int_gt_lit1(unsigned char expected_result)
121 {
122   result = 0;
123
124   if(int0 > 0)
125     result |= 1;
126
127   if(int0 > 1)
128     result |= 2;
129
130
131   if(int0 > 0xff)
132     result |= 4;
133
134   if(int0 > 0x100)
135     result |= 8;
136
137   if(int0 > 0x0101)
138     result |= 0x10;
139   
140   if(int0 > 0x01ff)
141     result |= 0x20;
142   
143   if(int0 > 0x0200)
144     result |= 0x40;
145
146   if(int0 > 0x0201)
147     result |= 0x80;
148
149   if(result != expected_result)
150     failures=1;
151
152 }
153
154
155 void int_compare1(void)
156 {
157   int0 = -1;
158   c_int_gt_lit1(0x00);
159
160   int0 = 0;
161   c_int_gt_lit1(0x00);
162
163   int0 = 1;
164   c_int_gt_lit1(0x01);
165
166   int0 = 2;
167   c_int_gt_lit1(0x03);
168
169   int0 = 0xfe;
170   c_int_gt_lit1(0x03);
171
172   int0 = 0xff;
173   c_int_gt_lit1(0x03);
174
175   int0 = 0x100;
176   c_int_gt_lit1(0x07);
177
178   int0 = 0x101;
179   c_int_gt_lit1(0x0f);
180
181   int0 = 0x102;
182   c_int_gt_lit1(0x1f);
183
184   int0 = 0x1fe;
185   c_int_gt_lit1(0x1f);
186
187   int0 = 0x1ff;
188   c_int_gt_lit1(0x1f);
189
190   int0 = 0x200;
191   c_int_gt_lit1(0x3f);
192
193   int0 = 0x201;
194   c_int_gt_lit1(0x7f);
195
196   int0 = 0x7f00;
197   c_int_gt_lit1(0xff);
198
199   /* now check contiguous ranges */
200
201   for(int0 = -0x7fff; int0 != -1; int0++)
202     c_int_gt_lit1(0x00);
203
204   for(int0 = 2; int0 != 0xff; int0++)
205     c_int_gt_lit1(0x03);
206
207   for(int0 = 0x202; int0 != 0x7fff; int0++)
208     c_int_gt_lit1(0xff);
209
210 }
211
212
213 void c_int_gt_lit2(unsigned char expected_result)
214 {
215   result = 0;
216
217   if(int0 > -0x7fff)
218     result |= 1;
219
220   if(int0 > -0x7f00)
221     result |= 2;
222
223   if(int0 > -0x7eff)
224     result |= 4;
225
226   if(int0 > -0x7e00)
227     result |= 8;
228
229   if(int0 > -0x0101)
230     result |= 0x10;
231   
232   if(int0 > -0x0100)
233     result |= 0x20;
234   
235   if(int0 > -0xff)
236     result |= 0x40;
237
238   if(int0 > -1)
239     result |= 0x80;
240
241   if(result != expected_result)
242     failures=1;
243 }
244
245 void int_compare2(void)
246 {
247   int0 = -0x7fff;
248   c_int_gt_lit2(0x00);
249
250   int0 = -0x7f00;
251   c_int_gt_lit2(0x01);
252
253   int0 = -0x7eff;
254   c_int_gt_lit2(0x03);
255
256   int0 = -0x7e00;
257   c_int_gt_lit2(0x07);
258
259   int0 = -0x7dff;
260   c_int_gt_lit2(0x0f);
261
262   int0 = -0x4567;
263   c_int_gt_lit2(0x0f);
264
265   int0 = -0x200;
266   c_int_gt_lit2(0x0f);
267
268   int0 = -0x102;
269   c_int_gt_lit2(0x0f);
270
271   int0 = -0x101;
272   c_int_gt_lit2(0x0f);
273
274   int0 = -0x100;
275   c_int_gt_lit2(0x1f);
276
277   int0 = -0xff;
278   c_int_gt_lit2(0x3f);
279
280   int0 = -0x02;
281   c_int_gt_lit2(0x7f);
282
283   int0 = -0x01;
284   c_int_gt_lit2(0x7f);
285
286   int0 = 0;
287   c_int_gt_lit2(0xff);
288
289   int0 = 1;
290   c_int_gt_lit2(0xff);
291
292   int0 = 0x7fff;
293   c_int_gt_lit2(0xff);
294
295   /* now check contiguous ranges */
296
297   for(int0 = -0x7ffe; int0 != -0x7f01; int0++)
298     c_int_gt_lit2(0x01);
299
300   for(int0 = -0x7dff; int0 != -0x101; int0++)
301     c_int_gt_lit2(0x0f);
302
303   for(int0 = 0; int0 != 0x7fff; int0++)
304     c_int_gt_lit2(0xff);
305
306 }
307
308
309
310
311 void
312 main (void)
313 {
314   char_compare();
315   int_compare1();
316   int_compare2();
317
318   done ();
319 }