Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-arith-rand-ll.c
blobdff89d5e0dd006dd9af339f2223299af91c07797
1 /*
2 arith-rand-ll.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
8 long long
9 simple_rand ()
11 static unsigned long long seed = 47114711;
12 unsigned long long this = seed * 1103515245 + 12345;
13 seed = this;
14 return this >> 8;
17 unsigned long long int
18 random_bitstring ()
20 unsigned long long int x;
21 int n_bits;
22 long long ran;
23 int tot_bits = 0;
25 x = 0;
26 for (;;)
28 ran = simple_rand ();
29 n_bits = (ran >> 1) % 16;
30 tot_bits += n_bits;
32 if (n_bits == 0)
33 return x;
34 else
36 x <<= n_bits;
37 if (ran & 1)
38 x |= (1 << n_bits) - 1;
40 if (tot_bits > 8 * sizeof (long long) + 6)
41 return x;
45 #endif
47 #define ABS(x) ((x) >= 0 ? (x) : -(x))
49 void
50 testTortureExecute (void)
52 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
53 #ifndef __SDCC_mcs51 // Not enough internal RAM for area OSEG.
54 long long int i;
56 for (i = 0; i < 10 /* GCC original was 10000 - take too much time */; i++)
58 unsigned long long x, y;
59 x = random_bitstring ();
60 y = random_bitstring ();
62 if (sizeof (int) == sizeof (long long))
63 goto save_time;
65 { unsigned long long xx = x, yy = y, r1, r2;
66 if (yy == 0) continue;
67 r1 = xx / yy;
68 r2 = xx % yy;
69 if (r2 >= yy || r1 * yy + r2 != xx)
70 ASSERT (0);
72 { signed long long xx = x, yy = y, r1, r2;
73 if ((unsigned long long) xx << 1 == 0 && yy == -1)
74 continue;
75 r1 = xx / yy;
76 r2 = xx % yy;
77 if (ABS (r2) >= (unsigned long long) ABS (yy) || (signed long long) (r1 * yy + r2) != xx)
78 ASSERT (0);
80 save_time:
81 { unsigned int xx = x, yy = y, r1, r2;
82 if (yy == 0) continue;
83 r1 = xx / yy;
84 r2 = xx % yy;
85 if (r2 >= yy || r1 * yy + r2 != xx)
86 ASSERT (0);
88 { signed int xx = x, yy = y, r1, r2;
89 if ((unsigned int) xx << 1 == 0 && yy == -1)
90 continue;
91 r1 = xx / yy;
92 r2 = xx % yy;
93 if (ABS (r2) >= (unsigned int) ABS (yy) || (signed int) (r1 * yy + r2) != xx || ((xx < 0) != (r2 < 0) && r2))
94 ASSERT (0);
96 { unsigned short xx = x, yy = y, r1, r2;
97 if (yy == 0) continue;
98 r1 = xx / yy;
99 r2 = xx % yy;
100 if (r2 >= yy || r1 * yy + r2 != xx)
101 ASSERT (0);
103 { signed short xx = x, yy = y, r1, r2;
104 r1 = xx / yy;
105 r2 = xx % yy;
106 if (ABS (r2) >= (unsigned short) ABS (yy) || (signed short) (r1 * yy + r2) != xx)
107 ASSERT (0);
109 { unsigned char xx = x, yy = y, r1, r2;
110 if (yy == 0) continue;
111 r1 = xx / yy;
112 r2 = xx % yy;
113 if (r2 >= yy || r1 * yy + r2 != xx)
114 ASSERT (0);
116 { signed char xx = x, yy = y, r1, r2;
117 r1 = xx / yy;
118 r2 = xx % yy;
119 if (ABS (r2) >= (unsigned char) ABS (yy) || (signed char) (r1 * yy + r2) != xx)
120 ASSERT (0);
123 #endif
124 #endif
125 return;