| 1 |
/* { dg-do run { target avx512fp16 } } */ |
| 2 |
/* { dg-options "-O3 -mavx512fp16 -mavx512vl -ffast-math" } */ |
| 3 |
|
| 4 |
static void recip_op_test (void); |
| 5 |
#define DO_TEST recip_op_test |
| 6 |
#define AVX512FP16 |
| 7 |
#define AVX512VL |
| 8 |
#include "avx512f-check.h" |
| 9 |
#include "avx512fp16-recip-1.c" |
| 10 |
|
| 11 |
_Float16 a[32], b[32], vexp[32], vref[32], sa, sb, sexp, sref; |
| 12 |
|
| 13 |
#define NO_FAST_ATTR \ |
| 14 |
__attribute__((noinline, noclone, \ |
| 15 |
optimize("fast-math,trapping-math"))) |
| 16 |
|
| 17 |
_Float16 NO_FAST_ATTR |
| 18 |
scalar_hf_rcp_no_fast (_Float16 a, _Float16 b) |
| 19 |
{ |
| 20 |
return a / b; |
| 21 |
} |
| 22 |
|
| 23 |
_Float16 NO_FAST_ATTR |
| 24 |
scalar_hf_rsqrt_no_fast (_Float16 a, _Float16 b) |
| 25 |
{ |
| 26 |
return a / __builtin_sqrtf16 (b); |
| 27 |
} |
| 28 |
|
| 29 |
void NO_FAST_ATTR |
| 30 |
vector_hf_rcp_no_fast (_Float16 * restrict a, _Float16 * restrict b, |
| 31 |
_Float16 * restrict c, int n) |
| 32 |
{ |
| 33 |
int i; |
| 34 |
for (i = 0; i < n; i++) |
| 35 |
c[i] = a[i] / b[i]; |
| 36 |
} |
| 37 |
|
| 38 |
void NO_FAST_ATTR |
| 39 |
vector_hf_rsqrt_no_fast (_Float16 * restrict a, _Float16 * restrict b, |
| 40 |
_Float16 * restrict c, int n) |
| 41 |
{ |
| 42 |
int i; |
| 43 |
for (i = 0; i < n; i++) |
| 44 |
c[i] = a[i] / __builtin_sqrtf16 (b[i]); |
| 45 |
} |
| 46 |
|
| 47 |
void init() |
| 48 |
{ |
| 49 |
int i; |
| 50 |
sa = 3.75; |
| 51 |
sb = 6.25; |
| 52 |
sexp = sref = 2.75; |
| 53 |
for (i = 0; i < 32; i++) |
| 54 |
{ |
| 55 |
a[i] = i + 0.5; |
| 56 |
b[i] = i * 1.5; |
| 57 |
vexp[i] = vref[i] = 2.75 * i; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
int check_cond(void *a, void *b, int size) |
| 62 |
{ |
| 63 |
int i; |
| 64 |
unsigned short *pa = (unsigned short *)a, |
| 65 |
*pb = (unsigned short *)b; |
| 66 |
for (i = 0; i < size; i++) |
| 67 |
if (pa[i] != pb[i]) |
| 68 |
return 0; |
| 69 |
return 1; |
| 70 |
} |
| 71 |
|
| 72 |
static void recip_op_test() |
| 73 |
{ |
| 74 |
init (); |
| 75 |
sexp = scalar_hf_rcp_fast (sa, sb); |
| 76 |
sref = scalar_hf_rcp_no_fast (sa, sb); |
| 77 |
if (!check_cond (&sexp, &sref, 1)) |
| 78 |
abort (); |
| 79 |
|
| 80 |
init (); |
| 81 |
sexp = scalar_hf_rsqrt_fast (sa, sb); |
| 82 |
sref = scalar_hf_rsqrt_no_fast (sa, sb); |
| 83 |
if (!check_cond (&sexp, &sref, 1)) |
| 84 |
abort (); |
| 85 |
|
| 86 |
init (); |
| 87 |
vector_hf_rcp_fast (a, b, vexp, 32); |
| 88 |
vector_hf_rcp_no_fast (a, b, vref, 32); |
| 89 |
if (!check_cond (vexp, vref, 1)) |
| 90 |
abort (); |
| 91 |
|
| 92 |
init (); |
| 93 |
vector_hf_rsqrt_fast (a, b, vexp, 32); |
| 94 |
vector_hf_rsqrt_no_fast (a, b, vref, 32); |
| 95 |
if (!check_cond (vexp, vref, 1)) |
| 96 |
abort (); |
| 97 |
} |