struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-920501-2.c
blob059fe0f4701529b57efb50f28aaf1554dc1c79a7
1 /*
2 920501-2.c from the execute part of the gcc torture suite.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 // Todo: Enable when sdcc supports long long
12 #if 0
13 unsigned long
14 gcd_ll (unsigned long long x, unsigned long long y)
16 for (;;)
18 if (y == 0)
19 return (unsigned long) x;
20 x = x % y;
21 if (x == 0)
22 return (unsigned long) y;
23 y = y % x;
27 unsigned long long
28 powmod_ll (unsigned long long b, unsigned e, unsigned long long m)
30 unsigned t;
31 unsigned long long pow;
32 int i;
34 if (e == 0)
35 return 1;
37 /* Find the most significant bit in E. */
38 t = e;
39 for (i = 0; t != 0; i++)
40 t >>= 1;
42 /* The most sign bit in E is handled outside of the loop, by beginning
43 with B in POW, and decrementing I. */
44 pow = b;
45 i -= 2;
47 for (; i >= 0; i--)
49 pow = pow * pow % m;
50 if ((1 << i) & e)
51 pow = pow * b % m;
54 return pow;
57 unsigned long factab[10];
59 void
60 facts (t, a_int, x0, p)
61 unsigned long long t;
62 int a_int;
63 int x0;
64 unsigned p;
66 unsigned long *xp = factab;
67 unsigned long long x, y;
68 unsigned long q = 1;
69 unsigned long long a = a_int;
70 int i;
71 unsigned long d;
72 int j = 1;
73 unsigned long tmp;
74 int jj = 0;
76 x = x0;
77 y = x0;
79 for (i = 1; i < 10000; i++)
81 x = powmod_ll (x, p, t) + a;
82 y = powmod_ll (y, p, t) + a;
83 y = powmod_ll (y, p, t) + a;
85 if (x > y)
86 tmp = x - y;
87 else
88 tmp = y - x;
89 q = (unsigned long long) q * tmp % t;
91 if (i == j)
93 jj += 1;
94 j += jj;
95 d = gcd_ll (q, t);
96 if (d != 1)
98 *xp++ = d;
99 t /= d;
100 if (t == 1)
102 return;
103 *xp = 0;
109 #endif
111 void
112 testTortureExecute (void)
114 #if 0
115 unsigned long long t;
116 unsigned x0, a;
117 unsigned p;
119 p = 27;
120 t = (1ULL << p) - 1;
122 a = -1;
123 x0 = 3;
125 facts (t, a, x0, p);
126 if (factab[0] != 7 || factab[1] != 73 || factab[2] != 262657)
127 ASSERT(0);
128 return;
129 #endif