Regression file for testing the nested for-loop bug in the PIC port that Steve Tell...
[fw/sdcc] / src / regression / compare5.c
1 #define __16F873
2 #include "p16f873.h"
3 //
4 // compare5.c
5 // regression testing program for comparing longs
6 //
7
8 #define  COMPARE_OUT_OF_RANGE 1
9
10 unsigned char success = 0;
11 unsigned char failures = 0;
12 unsigned char dummy = 0;
13
14 bit bit0 = 0;
15 int int0 = 0;
16 int int1 = 0;
17 char char0 = 0;
18 char char1 = 0;
19 long long0 = 0;
20 long long1 = 0;
21 unsigned long ulong0 = 0;
22 unsigned long ulong1 = 0;
23
24 void
25 done ()
26 {
27
28   dummy++;
29
30 }
31
32 // compare to 0
33 // assumes
34 // long0 == 0
35 // ulong0 == 0
36
37 void c_0(void)
38 {
39
40   if(long0 != 0)
41     failures++;
42
43   if(long0 > 0)
44     failures++;
45
46   if(ulong0 != 0)
47     failures++;
48
49   if(ulong0 > 0)
50     failures++;
51
52 }
53
54 // compare to 1
55 // assumes
56 // long1 == 1
57 // ulong1 == 1
58
59 void c_1(void)
60 {
61
62   if(long0 == 1)
63     failures++;
64
65   if(long1 != 1)
66     failures++;
67
68   if(ulong0 == 1)
69     failures++;
70
71   if(ulong1 != 1)
72     failures++;
73
74   if(long1 < 0)
75     failures++;
76
77   if(long1 < 1)
78     failures++;
79
80   if(ulong1 < 1)
81     failures++;
82
83   if(long1 > 1)
84     failures++;
85
86   if(ulong1 > 1)
87     failures++;
88 }
89
90 // compare to 2
91 // assumes
92 // long0 == 2
93 // ulong0  == 2
94
95 void c_2(void)
96 {
97
98   if(long0 != 2)
99     failures++;
100
101   if(ulong0 != 2)
102     failures++;
103
104   if(long1 == 2)
105     failures++;
106
107   if(ulong1 == 2)
108     failures++;
109
110 }
111
112 // compare to 0xff
113 // assumes
114 // achar0 == 0xff
115 // aint0  == 0xff
116
117 void c_ff(void)
118 {
119
120   if(long0 != 0xff)
121     failures++;
122
123   if(ulong0 != 0xff)
124     failures++;
125
126   if(long1 == 0xff)
127     failures++;
128
129   if(ulong1 == 0xff)
130     failures++;
131
132
133 }
134
135 // compare to 0x200
136 // assumes
137 // achar0 == 0x200
138 // aint0  == 0x200
139
140 void c_200(void)
141 {
142
143   if(long0 != 0x200)
144     failures++;
145
146   if(ulong0 != 0x200)
147     failures++;
148
149   if(long1 == 0x200)
150     failures++;
151
152   if(ulong1 == 0x200)
153     failures++;
154
155
156 }
157
158 // compare to 0x20000
159 // assumes
160 // long0  == 0x20000
161 // ulong0 == 0x20000
162 // long1  != 0x20000
163 // ulong1 != 0x20000
164
165 void c_20000(void)
166 {
167
168   if(long0 != 0x20000)
169     failures++;
170
171   if(ulong0 != 0x20000)
172     failures++;
173
174   if(long1 == 0x20000)
175     failures++;
176
177   if(ulong1 == 0x20000)
178     failures++;
179
180   if(long0 <= 0x10000)
181     failures++;
182
183   if(long0 < 0x10000)
184     failures++;
185
186 /*  if(long0 < 0x12345)
187     failures++;
188 */
189   if(long0 == 0)
190     failures++;
191 }
192
193 // compare to 0x00a5
194 // assumes
195 // char0  == 0xa5
196 // int0  == 0x00a5
197
198 void c_a5(void)
199 {
200
201   if(char0 != 0xa5)
202     failures++;
203
204   if(int0 != 0xa5)
205     failures++;
206
207   if(int0 == 0xa4)
208     failures++;
209
210   if(int0 == 0xa500)
211     failures++;
212
213 }
214
215 // compare to 0xa500
216 // assumes
217 // char0  == 0xa5
218 // int0  == 0xa500
219
220 void c_a500(void)
221 {
222
223 #ifdef COMPARE_OUT_OF_RANGE
224   if(char0 == 0xa500)
225     failures++;
226 #endif
227
228   if(int0 != 0xa500)
229     failures++;
230
231   if(int0 == 0xa400)
232     failures++;
233
234   if(int0 == 0x00a5)
235     failures++;
236
237 }
238
239 // compare to 0xabcd
240 // assumes
241 // char0  == 0xa5
242 // int0  == 0xabcd
243
244 void c_abcd(void)
245 {
246 #ifdef COMPARE_OUT_OF_RANGE
247   if(char0 == 0xabcd)
248     failures++;
249 #endif
250
251   if(int0 != 0xabcd)
252     failures++;
253
254   if(int0 == 0xab00)
255     failures++;
256
257   if(int0 == 0x00cd)
258     failures++;
259
260   if(int0 == 0x05cd)
261     failures++;
262
263   if(int0 == 0xab05)
264     failures++;
265
266   if(int0 == 0xab01)
267     failures++;
268
269   if(int0 == 0x01cd)
270     failures++;
271
272   if(int0 > 0)
273     failures++;
274
275 #ifdef COMPARE_OUT_OF_RANGE
276   if(int0 == 0x1234abcd)
277     failures++;
278 #endif
279
280 }
281
282 // assumes char1 == 0
283 void c_ifelse1(void)
284 {
285
286   if(char0)
287     char0 = char1;
288   else
289     char0 = 0;
290
291   if(char0)
292     failures++;
293 }
294
295 // assumes char0 = -1
296 // assumes int0 = -1
297
298 void c_minus1(void)
299 {
300   if(long0 != -1)
301     failures++;
302
303   if(long0 > 0)
304     failures++;
305
306   if(long1 < 0)
307     failures++;
308 /*
309   if(long1 < 2)
310     failures++;
311 */
312 }
313
314 // assumes
315 // long0 = long1 = ulong0 = ulong1 == 0
316
317 void c_long2long_eq(void)
318 {
319
320   if(long0 != long1)
321     failures++;
322
323   if(ulong0 != ulong1)
324     failures++;
325
326   if(long0 != ulong1)
327     failures++;
328
329   if(long0 > long1)
330     failures++;
331
332   if(long0 < long1)
333     failures++;
334
335   if(long0 > ulong0)
336     failures++;
337
338   if(long0 < ulong0)
339     failures++;
340 }
341
342 // assumes
343 // long0 = ulong0 == 0
344 // long1 = ulong1 == 1
345
346 void c_long2long_neq(void)
347 {
348
349   if(long0 == long1)
350     failures++;
351
352   if(ulong0 == ulong1)
353     failures++;
354
355   if(long1 != ulong1)
356     failures++;
357
358   if(long1 < long0)
359     failures++;
360
361   if(long1 <= long0)
362     failures++;
363
364   if(ulong1 < ulong0)
365     failures++;
366
367   if(ulong1 <= ulong0)
368     failures++;
369
370 }
371
372
373 //  long0=-100;
374 //  long1=-1000;
375 void
376 c_long2neglit(void)
377 {
378
379   if(long0>0)
380     failures++;
381   if(long1>0)
382     failures++;
383
384   if(long1 > long0)
385     failures++;
386
387   if(long1 > 100)
388     failures++;
389
390   if(long0 > -50)
391     failures++;
392
393   if(long1 < -5000)
394     failures++;
395 }
396
397 void
398 main (void)
399 {
400
401   c_0();
402
403   c_long2long_eq();
404
405   long1 = 1;
406   ulong1 = 1;
407   c_1();
408   c_long2long_neq();
409
410   long0 = 2;
411   ulong0 = 2;
412   c_2();
413
414   long0 = 0xff;
415   ulong0 = 0xff;
416   c_ff();
417
418   long0 = 0x200;
419   ulong0 = 0x200;
420   c_200();
421
422   long0 = 0x20000;
423   ulong0 = 0x20000;
424   c_20000();
425
426   long0 = -1;
427   c_minus1();
428
429   long0=-100;
430   long1=-1000;
431   c_long2neglit();
432
433   success = failures;
434   done ();
435 }