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-20021120-1.c
blob65da36b61a2fc9f34dc71083f58dd5ed79f1e260
1 /*
2 20021120-1.c from the execute part of the gcc torture suite.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #pragma disable_warning 93
10 #endif
12 /* This generates too much code for a mcs51, hc08, pdk14 and pdk15 */
13 /* pic14: Not enough data memory */
14 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pic14) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15)
16 /* Macros to emit "L Nxx R" for each octal number xx between 000 and 037. */
17 #define OP1(L, N, R, I, J) L N##I##J R
18 #define OP2(L, N, R, I) \
19 OP1(L, N, R, 0, I), OP1(L, N, R, 1, I), \
20 OP1(L, N, R, 2, I), OP1(L, N, R, 3, I)
21 #define OP(L, N, R) \
22 OP2(L, N, R, 0), OP2(L, N, R, 1), OP2(L, N, R, 2), OP2(L, N, R, 3), \
23 OP2(L, N, R, 4), OP2(L, N, R, 5), OP2(L, N, R, 6), OP2(L, N, R, 7)
25 /* Declare 32 unique variables with prefix N. */
26 #define DECLARE(N) OP (, N,)
28 /* Copy 32 variables with prefix N from the array at ADDR.
29 Leave ADDR pointing to the end of the array. */
30 #define COPYIN(N, ADDR) OP (, N, = *(ADDR++))
32 /* Likewise, but copy the other way. */
33 #define COPYOUT(N, ADDR) OP (*(ADDR++) =, N,)
35 /* Add the contents of the array at ADDR to 32 variables with prefix N.
36 Leave ADDR pointing to the end of the array. */
37 #define ADD(N, ADDR) OP (, N, += *(ADDR++))
39 volatile double gd[32];
40 volatile float gf[32];
42 void foo (int n)
44 #if defined(__SDCC_STACK_AUTO) && ( defined (__SDCC_mos6502) || defined (__SDCC_mos65c02) )
45 static double DECLARE(d);
46 static float DECLARE(f);
47 #else
48 double DECLARE(d);
49 float DECLARE(f);
50 #endif
51 volatile double *pd;
52 volatile float *pf;
53 int i;
55 pd = gd; COPYIN (d, pd);
56 for (i = 0; i < n; i++)
58 pf = gf; COPYIN (f, pf);
59 pd = gd; ADD (d, pd);
60 pd = gd; ADD (d, pd);
61 pd = gd; ADD (d, pd);
62 pf = gf; COPYOUT (f, pf);
64 pd = gd; COPYOUT (d, pd);
66 #endif
68 void
69 testTortureExecute (void)
71 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pic14) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15)
72 int i;
74 for (i = 0; i < 32; i++)
75 gd[i] = i, gf[i] = i;
76 foo (1);
77 for (i = 0; i < 32; i++)
78 ASSERT (gd[i] == i * 4 && gf[i] == i);
79 return;
80 #endif