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