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