Debian Codegraph @

gcc/testsuite/gcc.target/i386/avx512fp16-reduce-op-1.c

raw
1 /* { dg-do run { target avx512fp16 } } */
2 /* { dg-options "-O2 -mavx512fp16" } */
3
4 static void do_test (void);
5
6 #define DO_TEST do_test
7 #define AVX512FP16
8
9 #include <immintrin.h>
10 #include "avx512-check.h"
11
12 __m512h a1 = { -39.3f16, -180.9f16, 13.4f16, 35.4f16, -41.1f16, -14.4f16, 24.5f16, 53.54f16,
13 238.4f16, -134.8f16, 24.5f16, 35.6f16, -346.7f16, -43.4f16, -535.3f16, 324.7f16,
14 82.5f16, 21.4f16, 24.4f16, 53.4f16, 23.5f16, -24.4f16, -34.5f16, -32.5f16,
15 23.6f16, -13.4f16, 24.5f16, 35.5f16, -34.4f16, -24.5f16, -34.5f16, 13.5f16 };
16
17 __m512h a2 = { 1.25f16, 2.25f16, -0.25f16, 4.0f16, -2.0f16, 4.0f16, -3.0f16, 2.0f16,
18 -0.5f16, -1.0f16, 1.0f16, -1.0f16, 1.0f16, 1.0f16, 2.0f16, 4.0f16,
19 1.25f16, 2.25f16, -4.25f16, 4.0f16, -2.4f16, 4.0f16, -3.0f, 2.0f16,
20 -4.5f16, 7.6f16, 0.7f16, -8.2f16, 2.1f16, 2.4f16, -2.0f16, 19.4f16 };
21
22 __attribute__((noinline, noclone)) _Float16
23 test_reduce_add_ph (__m512h a)
24 {
25 return _mm512_reduce_add_ph (a);
26 }
27
28 __attribute__((noinline, noclone)) _Float16
29 test_reduce_mul_ph (__m512h a)
30 {
31 return _mm512_reduce_mul_ph (a);
32 }
33
34 __attribute__((noinline, noclone)) _Float16
35 test_reduce_max_ph (__m512h a)
36 {
37 return _mm512_reduce_max_ph (a);
38 }
39
40 __attribute__((noinline, noclone)) _Float16
41 test_reduce_min_ph (__m512h a)
42 {
43 return _mm512_reduce_min_ph (a);
44 }
45
46 #define SIZE 32
47 #define REF_ADDMUL(op, a) \
48 __m256h __a1 = _mm256_setzero_ph (); \
49 for (int i =0; i < 16; i++) { \
50 __a1[i] = (_Float16) a[i] op (_Float16) a[i + 16]; \
51 } \
52 __m128h __a2 = _mm_setzero_ph (); \
53 for (int i =0; i < 8; i++) { \
54 __a2[i] = (_Float16) __a1[i] op (_Float16) __a1[i + 8]; \
55 } \
56 _Float16 __c0 = __a2[0] op __a2[4]; \
57 _Float16 __c1 = __a2[1] op __a2[5]; \
58 _Float16 __c2 = __a2[2] op __a2[6]; \
59 _Float16 __c3 = __a2[3] op __a2[7]; \
60 _Float16 __d0 = __c0 op __c2; \
61 _Float16 __d1 = __c1 op __c3; \
62 _Float16 __e0 = __d0 op __d1; \
63 r3 = __e0
64
65 #define TESTOP(opname, op, a) \
66 do { \
67 _Float16 r1 = _mm512_reduce_##opname##_ph (a); \
68 _Float16 r2 = test_reduce_##opname##_ph (a); \
69 _Float16 r3 = a[0]; \
70 if (r1 != r2) { \
71 __builtin_abort (); \
72 } \
73 REF_ADDMUL (op, a); \
74 if (r1 != r3) { \
75 __builtin_abort (); \
76 } \
77 } while (0)
78
79 #define TEST_ADDMUL_PH(a) \
80 do { \
81 TESTOP (add, +, a); \
82 TESTOP (mul, *, a); \
83 } while (0)
84
85 static void
86 test_512_addmul_ph (void)
87 {
88 TEST_ADDMUL_PH (a1);
89 TEST_ADDMUL_PH (a2);
90 }
91
92 #undef TESTOP
93 #define TESTOP(opname, op, a) \
94 do { \
95 _Float16 r1 = _mm512_reduce_##opname##_ph (a); \
96 _Float16 r2 = test_reduce_##opname##_ph (a); \
97 _Float16 r3 = a[0]; \
98 if (r1 != r2) { \
99 __builtin_abort (); \
100 } \
101 for (int i = 1; i < SIZE; i++) \
102 r3 = r3 op a[i]; \
103 if (r1 != r3) { \
104 __builtin_abort (); \
105 } \
106 } while (0)
107
108 #define TEST_MINMAX_PH(a) \
109 do { \
110 TESTOP (min, < a[i] ? r3 :, a); \
111 TESTOP (max, > a[i] ? r3 :, a); \
112 } while (0)
113
114 static void
115 test_512_minmax_ph (void)
116 {
117 TEST_MINMAX_PH (a1);
118 TEST_MINMAX_PH (a2);
119 }
120
121 static void
122 do_test (void)
123 {
124 test_512_addmul_ph();
125 test_512_minmax_ph();
126 }
127
128 #undef SIZE
129 #undef REF_ADDMUL
130 #undef TESTOP
131 #undef TEST_ADDMUL_PH
132 #undef TEST_MINMAX_PH