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