]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.target/gcn/simd-math-4.c
amdgcn: implement vector div and mod libfuncs
[thirdparty/gcc.git] / gcc / testsuite / gcc.target / gcn / simd-math-4.c
1 /* Test that signed division and modulus give the correct result with
2 different variations of signedness. */
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 char v64qi __attribute__ ((vector_size (64)));
9 typedef short v64hi __attribute__ ((vector_size (128)));
10 typedef int v64si __attribute__ ((vector_size (256)));
11 typedef long v64di __attribute__ ((vector_size (512)));
12
13 #ifndef TYPE
14 #define TYPE v64si
15 #endif
16 #define N 64
17
18 TYPE a;
19 TYPE b;
20
21 int main()
22 {
23 int i;
24 TYPE squot, srem;
25 TYPE usquot, usrem;
26 TYPE vquot, vrem;
27 TYPE vquot2, vrem2;
28 TYPE refquot, refrem;
29
30 for (i = 0; i < 64; i++)
31 {
32 a[i] = i * (i >> 2) * (i&1 ? -1 : 1);
33 b[i] = i * (i&2 ? -1 : 1);
34 }
35
36 for (i = 0; i < N; i++)
37 {
38 /* Calculate reference values using regular scalar div and mod. */
39 refquot[i] = a[i] / b[i];
40 __asm__ ("" ::: "memory");
41 refrem[i] = a[i] % b[i];
42 }
43
44 __asm__ ("" ::: "memory");
45 /* Scalar with divmod. */
46 for (i = 0; i < N; i++)
47 {
48 squot[i] = a[i] / b[i];
49 srem[i] = a[i] % b[i];
50 }
51
52 __asm__ ("" ::: "memory");
53 /* Vectorized with divmod. */
54 vquot = a / b;
55 vrem = a % b;
56
57 __asm__ ("" ::: "memory");
58 /* Vectorized with separte div and mod. */
59 vquot2 = a / b;
60 __asm__ ("" ::: "memory");
61 vrem2 = a % b;
62
63 #ifdef DEBUG
64 #define DUMP(VAR) \
65 __builtin_printf ("%8s: ", #VAR); \
66 for (i = 0; i < N; i++) \
67 __builtin_printf ("%d ", (int)VAR[i]); \
68 __builtin_printf ("\n");
69 DUMP (refquot)
70 DUMP (squot)
71 DUMP (vquot)
72 DUMP (vquot2)
73 __builtin_printf ("\n");
74 DUMP (refrem)
75 DUMP (srem)
76 DUMP (vrem)
77 DUMP (vrem2)
78 __builtin_printf ("\n");
79 #endif
80
81 for (i = 0; i < N; i++)
82 if (squot[i] != refquot[i]
83 || vquot[i] != refquot[i]
84 || vquot2[i] != refquot[i]
85 || srem[i] != refrem[i]
86 || vrem[i] != refrem[i]
87 || vrem2[i] != refrem[i])
88 __builtin_abort ();
89 return 0;
90 }
91
92 /* { dg-final { scan-assembler-times {__divmodv64si4@rel32@lo} 1 { xfail *-*-* } } } */
93 /* { dg-final { scan-assembler-times {__udivmodv64si4@rel32@lo} 0 } } */
94 /* { dg-final { scan-assembler-times {__divv64si3@rel32@lo} 1 } } */
95 /* { dg-final { scan-assembler-times {__udivv64si3@rel32@lo} 0 } } */
96 /* { dg-final { scan-assembler-times {__modv64si3@rel32@lo} 1 } } */
97 /* { dg-final { scan-assembler-times {__umodv64si3@rel32@lo} 0 } } */
98 /* { dg-final { scan-assembler-times {__divsi3@rel32@lo} 1 } } */
99 /* { dg-final { scan-assembler-times {__udivsi3@rel32@lo} 0 } } */