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