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