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