2015-07-14 Sandra Loosemore <sandra@codesourcery.com>
[official-gcc.git] / gcc / testsuite / gcc.target / nios2 / cdx-ldstwm-2.c
blob0e69534dcc1b1deb53c9af2703fef872874beeeb
1 /* { dg-do assemble } */
2 /* { dg-options "-O3 -fomit-frame-pointer -funroll-loops -march=r2 -mcdx -w" } */
4 /* Based on gcc.c-torture/execute/20021120-1.c.
5 This test used to result in assembler errors with R2 CDX because of
6 a bug in regrename; it wasn't re-validating insns after renaming, so
7 ldwm/stwm instructions with incorrect registers were being emitted. */
9 /* Macros to emit "L Nxx R" for each octal number xx between 000 and 037. */
10 #define OP1(L, N, R, I, J) L N##I##J R
11 #define OP2(L, N, R, I) \
12 OP1(L, N, R, 0, I), OP1(L, N, R, 1, I), \
13 OP1(L, N, R, 2, I), OP1(L, N, R, 3, I)
14 #define OP(L, N, R) \
15 OP2(L, N, R, 0), OP2(L, N, R, 1), OP2(L, N, R, 2), OP2(L, N, R, 3), \
16 OP2(L, N, R, 4), OP2(L, N, R, 5), OP2(L, N, R, 6), OP2(L, N, R, 7)
18 /* Declare 32 unique variables with prefix N. */
19 #define DECLARE(N) OP (, N,)
21 /* Copy 32 variables with prefix N from the array at ADDR.
22 Leave ADDR pointing to the end of the array. */
23 #define COPYIN(N, ADDR) OP (, N, = *(ADDR++))
25 /* Likewise, but copy the other way. */
26 #define COPYOUT(N, ADDR) OP (*(ADDR++) =, N,)
28 /* Add the contents of the array at ADDR to 32 variables with prefix N.
29 Leave ADDR pointing to the end of the array. */
30 #define ADD(N, ADDR) OP (, N, += *(ADDR++))
32 volatile double gd[32];
33 volatile float gf[32];
35 void foo (int n)
37 double DECLARE(d);
38 float DECLARE(f);
39 volatile double *pd;
40 volatile float *pf;
41 int i;
43 pd = gd; COPYIN (d, pd);
44 for (i = 0; i < n; i++)
46 pf = gf; COPYIN (f, pf);
47 pd = gd; ADD (d, pd);
48 pd = gd; ADD (d, pd);
49 pd = gd; ADD (d, pd);
50 pf = gf; COPYOUT (f, pf);
52 pd = gd; COPYOUT (d, pd);
55 int main ()
57 int i;
59 for (i = 0; i < 32; i++)
60 gd[i] = i, gf[i] = i;
61 foo (1);
62 for (i = 0; i < 32; i++)
63 if (gd[i] != i * 4 || gf[i] != i)
64 abort ();
65 exit (0);