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