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