PIC Port - fixed pointer/array accesses. Stream line comparisons. Started function...
[fw/sdcc] / src / regression / compare8.c
1 // Signed comparisons of the form:  (variable>LIT)
2 //
3 // This regression test exercises all of the boundary
4 // conditions in literal less than comparisons. There
5 // are numerous opportunities to optimize these comparison
6 // and each one has an astonishing capability of failing
7 // a boundary condition.
8
9 unsigned char success = 0;
10 unsigned char failures = 0;
11 unsigned char dummy = 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
25 /* copied from 16f877.inc file supplied with gpasm */
26
27 #define _CP_ALL          0x0FCF
28 #define _CP_HALF         0x1FDF
29 #define _CP_UPPER_256    0x2FEF
30 #define _CP_OFF          0x3FFF
31 #define _DEBUG_ON        0x37FF
32 #define _DEBUG_OFF       0x3FFF
33 #define _WRT_ENABLE_ON   0x3FFF
34 #define _WRT_ENABLE_OFF  0x3DFF
35 #define _CPD_ON          0x3EFF
36 #define _CPD_OFF         0x3FFF
37 #define _LVP_ON          0x3FFF
38 #define _LVP_OFF         0x3F7F
39 #define _BODEN_ON        0x3FFF
40 #define _BODEN_OFF       0x3FBF
41 #define _PWRTE_OFF       0x3FFF
42 #define _PWRTE_ON        0x3FF7
43 #define _WDT_ON          0x3FFF
44 #define _WDT_OFF         0x3FFB
45 #define _LP_OSC          0x3FFC
46 #define _XT_OSC          0x3FFD
47 #define _HS_OSC          0x3FFE
48 #define _RC_OSC          0x3FFF
49
50 /* *** NOTE ***  This particular test takes quite a while to run 
51  * ~ 10,000,000 instruction cycles. (2.5 seconds on a 20Mhz PIC).
52  * The WDT will reset the CPU if it's enabled. So disable it...
53 */
54
55 typedef unsigned int word;
56
57 word at 0x2007  CONFIG = _WDT_OFF & _PWRTE_ON;
58
59 void
60 done ()
61 {
62   dummy++;
63 }
64
65
66 void c_char_gt_lit1(unsigned char expected_result)
67 {
68   result = 0;
69
70   if(char0 > -0x7f)
71     result |= 1;
72
73
74   if(char0 > -1)
75     result |= 2;
76
77   if(char0 > 0)
78     result |= 4;
79
80   if(char0 > 1)
81     result |= 8;
82
83   if(char0 > 0x7e)
84     result |= 0x10;
85   
86   if(char0 > 0x7f)
87     result |= 0x20;
88   
89   if(result != expected_result)
90     failures++;
91 }
92
93
94 void char_compare(void)
95 {
96   char0 = 0x7f;
97   c_char_gt_lit1(0x1f);
98
99   char0 = 0x7e;
100   c_char_gt_lit1(0x0f);
101
102   char0 = 0x40;
103   c_char_gt_lit1(0x0f);
104
105   char0 = 0x2;
106   c_char_gt_lit1(0x0f);
107
108   char0 = 0x1;
109   c_char_gt_lit1(0x07);
110
111   char0 = 0;
112   c_char_gt_lit1(0x03);
113
114   char0 = -1;
115   c_char_gt_lit1(0x01);
116
117   char0 = -2;
118   c_char_gt_lit1(0x01);
119
120   char0 = -0x40;
121   c_char_gt_lit1(0x01);
122
123   char0 = -0x7e;
124   c_char_gt_lit1(0x01);
125
126   char0 = -0x7f;
127   c_char_gt_lit1(0x00);
128
129   char0 = 0x80;
130   c_char_gt_lit1(0x00);
131
132
133   /* Now test entire range */
134
135   for(char0=2; char0 != 0x7f; char0++)
136     c_char_gt_lit1(0x0f);
137
138
139   for(char0=-0x7e; char0 != -1; char0++)
140     c_char_gt_lit1(0x01);
141
142
143 }
144
145
146 void c_int_gt_lit1(unsigned char expected_result)
147 {
148   result = 0;
149
150   if(int0 > 0)
151     result |= 1;
152
153   if(int0 > 1)
154     result |= 2;
155
156
157   if(int0 > 0xff)
158     result |= 4;
159
160   if(int0 > 0x100)
161     result |= 8;
162
163   if(int0 > 0x0101)
164     result |= 0x10;
165   
166   if(int0 > 0x01ff)
167     result |= 0x20;
168   
169   if(int0 > 0x0200)
170     result |= 0x40;
171
172   if(int0 > 0x0201)
173     result |= 0x80;
174
175   if(result != expected_result)
176     failures=1;
177
178 }
179
180
181 void int_compare1(void)
182 {
183   int0 = -1;
184   c_int_gt_lit1(0x00);
185
186   int0 = 0;
187   c_int_gt_lit1(0x00);
188
189   int0 = 1;
190   c_int_gt_lit1(0x01);
191
192   int0 = 2;
193   c_int_gt_lit1(0x03);
194
195   int0 = 0xfe;
196   c_int_gt_lit1(0x03);
197
198   int0 = 0xff;
199   c_int_gt_lit1(0x03);
200
201   int0 = 0x100;
202   c_int_gt_lit1(0x07);
203
204   int0 = 0x101;
205   c_int_gt_lit1(0x0f);
206
207   int0 = 0x102;
208   c_int_gt_lit1(0x1f);
209
210   int0 = 0x1fe;
211   c_int_gt_lit1(0x1f);
212
213   int0 = 0x1ff;
214   c_int_gt_lit1(0x1f);
215
216   int0 = 0x200;
217   c_int_gt_lit1(0x3f);
218
219   int0 = 0x201;
220   c_int_gt_lit1(0x7f);
221
222   int0 = 0x7f00;
223   c_int_gt_lit1(0xff);
224
225   /* now check contiguous ranges */
226
227   for(int0 = -0x7fff; int0 != -1; int0++)
228     c_int_gt_lit1(0x00);
229
230   for(int0 = 2; int0 != 0xff; int0++)
231     c_int_gt_lit1(0x03);
232
233   for(int0 = 0x202; int0 != 0x7fff; int0++)
234     c_int_gt_lit1(0xff);
235
236 }
237
238
239 void c_int_gt_lit2(unsigned char expected_result)
240 {
241   result = 0;
242
243   if(int0 > -0x7fff)
244     result |= 1;
245
246   if(int0 > -0x7f00)
247     result |= 2;
248
249   if(int0 > -0x7eff)
250     result |= 4;
251
252   if(int0 > -0x7e00)
253     result |= 8;
254
255   if(int0 > -0x0101)
256     result |= 0x10;
257   
258   if(int0 > -0x0100)
259     result |= 0x20;
260   
261   if(int0 > -0xff)
262     result |= 0x40;
263
264   if(int0 > -1)
265     result |= 0x80;
266
267   if(result != expected_result)
268     failures=1;
269 }
270
271 void int_compare2(void)
272 {
273   int0 = -0x7fff;
274   c_int_gt_lit2(0x00);
275
276   int0 = -0x7f00;
277   c_int_gt_lit2(0x01);
278
279   int0 = -0x7eff;
280   c_int_gt_lit2(0x03);
281
282   int0 = -0x7e00;
283   c_int_gt_lit2(0x07);
284
285   int0 = -0x7dff;
286   c_int_gt_lit2(0x0f);
287
288   int0 = -0x4567;
289   c_int_gt_lit2(0x0f);
290
291   int0 = -0x200;
292   c_int_gt_lit2(0x0f);
293
294   int0 = -0x102;
295   c_int_gt_lit2(0x0f);
296
297   int0 = -0x101;
298   c_int_gt_lit2(0x0f);
299
300   int0 = -0x100;
301   c_int_gt_lit2(0x1f);
302
303   int0 = -0xff;
304   c_int_gt_lit2(0x3f);
305
306   int0 = -0x02;
307   c_int_gt_lit2(0x7f);
308
309   int0 = -0x01;
310   c_int_gt_lit2(0x7f);
311
312   int0 = 0;
313   c_int_gt_lit2(0xff);
314
315   int0 = 1;
316   c_int_gt_lit2(0xff);
317
318   int0 = 0x7fff;
319   c_int_gt_lit2(0xff);
320
321   /* now check contiguous ranges */
322
323   for(int0 = -0x7ffe; int0 != -0x7f01; int0++)
324     c_int_gt_lit2(0x01);
325
326   for(int0 = -0x7dff; int0 != -0x101; int0++)
327     c_int_gt_lit2(0x0f);
328
329   for(int0 = 0; int0 != 0x7fff; int0++)
330     c_int_gt_lit2(0xff);
331
332 }
333
334
335
336
337 void
338 main (void)
339 {
340   char_compare();
341   int_compare1();
342   int_compare2();
343
344   success = failures;
345   done ();
346 }