1 /* { dg-do run { target avx512fp16 } } */
2 /* { dg-options "-O2 -mavx512fp16 -mavx512dq" } */
3
4 #define AVX512FP16
5 #include "avx512fp16-helper.h"
6
7 #define N_ELEMS (AVX512F_LEN / 16)
8
9 void NOINLINE
EMULATE(mul_ph)10 EMULATE(mul_ph) (V512 * dest, V512 op1, V512 op2,
11 __mmask32 k, int zero_mask)
12 {
13 V512 v1, v2, v3, v4, v5, v6, v7, v8;
14 int i;
15 __mmask16 m1, m2;
16
17 m1 = k & 0xffff;
18 m2 = (k >> 16) & 0xffff;
19
20 unpack_ph_2twops(op1, &v1, &v2);
21 unpack_ph_2twops(op2, &v3, &v4);
22 unpack_ph_2twops(*dest, &v7, &v8);
23
24 for (i = 0; i < 16; i++) {
25 if (((1 << i) & m1) == 0) {
26 if (zero_mask) {
27 v5.f32[i] = 0;
28 }
29 else {
30 v5.u32[i] = v7.u32[i];
31 }
32 }
33 else {
34 v5.f32[i] = v1.f32[i] * v3.f32[i];
35 }
36
37 if (((1 << i) & m2) == 0) {
38 if (zero_mask) {
39 v6.f32[i] = 0;
40 }
41 else {
42 v6.u32[i] = v8.u32[i];
43 }
44 }
45 else {
46 v6.f32[i] = v2.f32[i] * v4.f32[i];
47 }
48
49 }
50 *dest = pack_twops_2ph(v5, v6);
51 }
52
53 void
TEST(void)54 TEST (void)
55 {
56 V512 res;
57 V512 exp;
58
59 init_src();
60
61 EMULATE(mul_ph) (&exp, src1, src2, NET_MASK, 0);
62 HF(res) = INTRINSIC (_mul_ph) (HF(src1), HF(src2));
63 CHECK_RESULT (&res, &exp, N_ELEMS, _mul_ph);
64
65 init_dest(&res, &exp);
66 EMULATE(mul_ph) (&exp, src1, src2, MASK_VALUE, 0);
67 HF(res) = INTRINSIC (_mask_mul_ph) (HF(res), MASK_VALUE, HF(src1), HF(src2));
68 CHECK_RESULT (&res, &exp, N_ELEMS, _mask_mul_ph);
69
70 EMULATE(mul_ph) (&exp, src1, src2, ZMASK_VALUE, 1);
71 HF(res) = INTRINSIC (_maskz_mul_ph) (ZMASK_VALUE, HF(src1), HF(src2));
72 CHECK_RESULT (&res, &exp, N_ELEMS, _maskz_mul_ph);
73
74 #if AVX512F_LEN == 512
75 EMULATE(mul_ph) (&exp, src1, src2, NET_MASK, 0);
76 HF(res) = INTRINSIC (_mul_round_ph) (HF(src1), HF(src2), _ROUND_NINT);
77 CHECK_RESULT (&res, &exp, N_ELEMS, _mul_ph);
78
79 init_dest(&res, &exp);
80 EMULATE(mul_ph) (&exp, src1, src2, MASK_VALUE, 0);
81 HF(res) = INTRINSIC (_mask_mul_round_ph) (HF(res), MASK_VALUE, HF(src1), HF(src2), _ROUND_NINT);
82 CHECK_RESULT (&res, &exp, N_ELEMS, _mask_mul_ph);
83
84 EMULATE(mul_ph) (&exp, src1, src2, ZMASK_VALUE, 1);
85 HF(res) = INTRINSIC (_maskz_mul_round_ph) (ZMASK_VALUE, HF(src1), HF(src2), _ROUND_NINT);
86 CHECK_RESULT (&res, &exp, N_ELEMS, _maskz_mul_ph);
87 #endif
88
89 if (n_errs != 0) {
90 abort ();
91 }
92 }
93