Debian Codegraph @

gcc/testsuite/gcc.target/gcn/simd-math-3.c

raw
1 /* Test that signed and unsigned division and modulus use the correct
2 vector routines and give the correct results. */
3
4 /* Setting it this way ensures the run tests use the same flag as the
5 compile tests. */
6 #pragma GCC optimize("O2")
7
8 typedef signed char v2qi __attribute__ ((vector_size (2)));
9 typedef signed char v4qi __attribute__ ((vector_size (4)));
10 typedef signed char v8qi __attribute__ ((vector_size (8)));
11 typedef signed char v16qi __attribute__ ((vector_size (16)));
12 typedef signed char v32qi __attribute__ ((vector_size (32)));
13 typedef signed char v64qi __attribute__ ((vector_size (64)));
14
15 typedef unsigned char v2uqi __attribute__ ((vector_size (2)));
16 typedef unsigned char v4uqi __attribute__ ((vector_size (4)));
17 typedef unsigned char v8uqi __attribute__ ((vector_size (8)));
18 typedef unsigned char v16uqi __attribute__ ((vector_size (16)));
19 typedef unsigned char v32uqi __attribute__ ((vector_size (32)));
20 typedef unsigned char v64uqi __attribute__ ((vector_size (64)));
21
22 typedef short v2hi __attribute__ ((vector_size (4)));
23 typedef short v4hi __attribute__ ((vector_size (8)));
24 typedef short v8hi __attribute__ ((vector_size (16)));
25 typedef short v16hi __attribute__ ((vector_size (32)));
26 typedef short v32hi __attribute__ ((vector_size (64)));
27 typedef short v64hi __attribute__ ((vector_size (128)));
28
29 typedef unsigned short v2uhi __attribute__ ((vector_size (4)));
30 typedef unsigned short v4uhi __attribute__ ((vector_size (8)));
31 typedef unsigned short v8uhi __attribute__ ((vector_size (16)));
32 typedef unsigned short v16uhi __attribute__ ((vector_size (32)));
33 typedef unsigned short v32uhi __attribute__ ((vector_size (64)));
34 typedef unsigned short v64uhi __attribute__ ((vector_size (128)));
35
36 typedef int v2si __attribute__ ((vector_size (8)));
37 typedef int v4si __attribute__ ((vector_size (16)));
38 typedef int v8si __attribute__ ((vector_size (32)));
39 typedef int v16si __attribute__ ((vector_size (64)));
40 typedef int v32si __attribute__ ((vector_size (128)));
41 typedef int v64si __attribute__ ((vector_size (256)));
42
43 typedef unsigned int v2usi __attribute__ ((vector_size (8)));
44 typedef unsigned int v4usi __attribute__ ((vector_size (16)));
45 typedef unsigned int v8usi __attribute__ ((vector_size (32)));
46 typedef unsigned int v16usi __attribute__ ((vector_size (64)));
47 typedef unsigned int v32usi __attribute__ ((vector_size (128)));
48 typedef unsigned int v64usi __attribute__ ((vector_size (256)));
49
50 typedef long v2di __attribute__ ((vector_size (16)));
51 typedef long v4di __attribute__ ((vector_size (32)));
52 typedef long v8di __attribute__ ((vector_size (64)));
53 typedef long v16di __attribute__ ((vector_size (128)));
54 typedef long v32di __attribute__ ((vector_size (256)));
55 typedef long v64di __attribute__ ((vector_size (512)));
56
57 typedef unsigned long v2udi __attribute__ ((vector_size (16)));
58 typedef unsigned long v4udi __attribute__ ((vector_size (32)));
59 typedef unsigned long v8udi __attribute__ ((vector_size (64)));
60 typedef unsigned long v16udi __attribute__ ((vector_size (128)));
61 typedef unsigned long v32udi __attribute__ ((vector_size (256)));
62 typedef unsigned long v64udi __attribute__ ((vector_size (512)));
63
64 #ifndef STYPE
65 #define STYPE v64si
66 #define UTYPE v64usi
67 #endif
68 #ifndef N
69 #define N 64
70 #endif
71
72 STYPE a;
73 STYPE b;
74 UTYPE ua;
75 UTYPE ub;
76
77 int main()
78 {
79 int i;
80 STYPE squot, srem;
81 UTYPE usquot, usrem;
82 STYPE vquot, vrem;
83 UTYPE uvquot, uvrem;
84 STYPE vquot2, vrem2;
85 UTYPE uvquot2, uvrem2;
86 STYPE refquot, refrem;
87 UTYPE urefquot, urefrem;
88
89 for (i = 0; i < N; i++)
90 {
91 a[i] = i * (i >> 2) + (i >> 1);
92 ua[i] = a[i];
93 b[i] = i;
94 ub[i] = i;
95 }
96
97 for (i = 0; i < N; i++)
98 {
99 /* Calculate reference values using regular scalar div and mod. */
100 refquot[i] = a[i] / b[i];
101 __asm__ ("" ::: "memory");
102 refrem[i] = a[i] % b[i];
103 urefquot[i] = ua[i] / ub[i];
104 __asm__ ("" ::: "memory");
105 urefrem[i] = ua[i] % ub[i];
106 }
107
108 __asm__ ("" ::: "memory");
109 /* Scalar with divmod. */
110 for (i = 0; i < N; i++)
111 {
112 squot[i] = a[i] / b[i];
113 srem[i] = a[i] % b[i];
114 usquot[i] = ua[i] / ub[i];
115 usrem[i] = ua[i] % ub[i];
116 }
117
118 __asm__ ("" ::: "memory");
119 /* Vectorized with divmod. */
120 vquot = a / b;
121 vrem = a % b;
122 uvquot = ua / ub;
123 uvrem = ua % ub;
124
125 __asm__ ("" ::: "memory");
126 /* Vectorized with separte div and mod. */
127 vquot2 = a / b;
128 __asm__ ("" ::: "memory");
129 vrem2 = a % b;
130 uvquot2 = ua / ub;
131 __asm__ ("" ::: "memory");
132 uvrem2 = ua % ub;
133
134 #ifdef DEBUG
135 #define DUMP(VAR) \
136 __builtin_printf ("%8s: ", #VAR); \
137 for (i = 0; i < N; i++) \
138 __builtin_printf ("%d ", (int)VAR[i]); \
139 __builtin_printf ("\n");
140 DUMP (refquot)
141 DUMP (squot)
142 DUMP (vquot)
143 DUMP (vquot2)
144 __builtin_printf ("\n");
145 DUMP (urefquot)
146 DUMP (usquot)
147 DUMP (uvquot)
148 DUMP (uvquot2)
149 __builtin_printf ("\n");
150 DUMP (refrem)
151 DUMP (srem)
152 DUMP (vrem)
153 DUMP (vrem2)
154 __builtin_printf ("\n");
155 DUMP (urefrem)
156 DUMP (usrem)
157 DUMP (uvrem)
158 DUMP (uvrem2)
159 __builtin_printf ("\n");
160 #endif
161
162 for (i = 0; i < N; i++)
163 if (squot[i] != refquot[i]
164 || vquot[i] != refquot[i]
165 || vquot2[i] != refquot[i]
166 || usquot[i] != urefquot[i]
167 || uvquot[i] != urefquot[i]
168 || uvquot2[i] != urefquot[i]
169 || srem[i] != refrem[i]
170 || vrem[i] != refrem[i]
171 || vrem2[i] != refrem[i]
172 || usrem[i] != urefrem[i]
173 || uvrem[i] != urefrem[i]
174 || uvrem2[i] != urefrem[i])
175 __builtin_abort ();
176 return 0;
177 }
178
179 /* { dg-final { scan-assembler-times {__divmodv64si4@rel32@lo} 1 { xfail *-*-* } } } */
180 /* { dg-final { scan-assembler-times {__udivmodv64si4@rel32@lo} 1 { xfail *-*-* } } } */
181 /* { dg-final { scan-assembler-times {__divv64si3@rel32@lo} 1 } } */
182 /* { dg-final { scan-assembler-times {__udivv64si3@rel32@lo} 1 } } */
183 /* { dg-final { scan-assembler-times {__modv64si3@rel32@lo} 1 } } */
184 /* { dg-final { scan-assembler-times {__umodv64si3@rel32@lo} 1 } } */
185 /* { dg-final { scan-assembler-times {__divsi3@rel32@lo} 1 } } */
186 /* { dg-final { scan-assembler-times {__udivsi3@rel32@lo} 1 } } */