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