| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-mavx512f -O2 -std=c99" } */ |
| 3 |
/* { dg-require-effective-target avx512f } */ |
| 4 |
/* { dg-require-effective-target c99_runtime } */ |
| 5 |
|
| 6 |
#include "avx512f-check.h" |
| 7 |
#include <math.h> |
| 8 |
#include "avx512f-helper.h" |
| 9 |
|
| 10 |
#define SIZE (128/64) |
| 11 |
#include "avx512f-mask-type.h" |
| 12 |
|
| 13 |
union fp_int_t |
| 14 |
{ |
| 15 |
long long int int_val; |
| 16 |
double fp_val; |
| 17 |
}; |
| 18 |
|
| 19 |
double |
| 20 |
get_norm_mant (double source, int signctrl, int interv) |
| 21 |
{ |
| 22 |
long long src, sign, exp, fraction; |
| 23 |
|
| 24 |
union fp_int_t bin_conv; |
| 25 |
|
| 26 |
bin_conv.fp_val = source; |
| 27 |
src = bin_conv.int_val; |
| 28 |
sign = (signctrl & 0x1) ? 0 : (src >> 63); |
| 29 |
exp = (src & 0x7ff0000000000000) >> 52; |
| 30 |
fraction = (src & 0xfffffffffffff); |
| 31 |
|
| 32 |
if (isnan (source)) |
| 33 |
return signbit (source) ? -NAN : NAN; |
| 34 |
if (source == 0.0 || source == -0.0 || isinf (source)) |
| 35 |
return sign ? -1.0 : 1.0; |
| 36 |
if (signbit (source) && (signctrl & 0x2)) |
| 37 |
return -NAN; |
| 38 |
if (!isnormal (source)) |
| 39 |
{ |
| 40 |
src = (src & 0xfff7ffffffffffff); |
| 41 |
exp = 0x3ff; |
| 42 |
while (!(src & 0x8000000000000)) |
| 43 |
{ |
| 44 |
src += fraction & 0x8000000000000; |
| 45 |
fraction = fraction << 1; |
| 46 |
exp--; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
switch (interv) |
| 51 |
{ |
| 52 |
case 0: |
| 53 |
exp = 0x3ff; |
| 54 |
break; |
| 55 |
case 1: |
| 56 |
exp = ((exp - 0x3ff) & 0x1) ? 0x3fe : 0x3ff; |
| 57 |
break; |
| 58 |
case 2: |
| 59 |
exp = 0x3fe; |
| 60 |
break; |
| 61 |
case 3: |
| 62 |
exp = (fraction & 0x8000000000000) ? 0x3fe : 0x3ff; |
| 63 |
break; |
| 64 |
default: |
| 65 |
abort (); |
| 66 |
} |
| 67 |
|
| 68 |
bin_conv.int_val = (sign << 63) | (exp << 52) | fraction; |
| 69 |
return bin_conv.fp_val; |
| 70 |
} |
| 71 |
|
| 72 |
static void |
| 73 |
compute_vgetmantsd (double *r, double *s1, double *s2, int interv, |
| 74 |
int signctrl) |
| 75 |
{ |
| 76 |
r[0] = get_norm_mant (s2[0], signctrl, interv); |
| 77 |
r[1] = s1[1]; |
| 78 |
} |
| 79 |
|
| 80 |
static void |
| 81 |
avx512f_test (void) |
| 82 |
{ |
| 83 |
union128d res1, res2, res3, res4, res5, res6, src1, src2; |
| 84 |
double res_ref[2]; |
| 85 |
MASK_TYPE mask = MASK_VALUE; |
| 86 |
|
| 87 |
src1.x = _mm_set_pd (-3.0, 111.111); |
| 88 |
src2.x = _mm_set_pd (222.222, -2.0); |
| 89 |
|
| 90 |
int i; |
| 91 |
for (i = 0; i < SIZE; i++) |
| 92 |
{ |
| 93 |
res2.a[i] = DEFAULT_VALUE; |
| 94 |
res5.a[i] = DEFAULT_VALUE; |
| 95 |
} |
| 96 |
|
| 97 |
res1.x = _mm_getmant_sd (src1.x, src2.x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src); |
| 98 |
res2.x = _mm_mask_getmant_sd (res2.x, mask, src1.x, src2.x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src); |
| 99 |
res3.x = _mm_maskz_getmant_sd (mask, src1.x, src2.x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src); |
| 100 |
res4.x = _mm_getmant_round_sd (src1.x, src2.x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src, _MM_FROUND_NO_EXC); |
| 101 |
res5.x = _mm_mask_getmant_round_sd (res5.x, mask, src1.x, src2.x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src, _MM_FROUND_NO_EXC); |
| 102 |
res6.x = _mm_maskz_getmant_round_sd (mask, src1.x, src2.x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src, _MM_FROUND_NO_EXC); |
| 103 |
|
| 104 |
compute_vgetmantsd (res_ref, src1.a, src2.a, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src); |
| 105 |
|
| 106 |
if (check_union128d (res1, res_ref)) |
| 107 |
abort (); |
| 108 |
|
| 109 |
MASK_MERGE (d) (res_ref, mask, 1); |
| 110 |
if (check_union128d (res2, res_ref)) |
| 111 |
abort (); |
| 112 |
|
| 113 |
MASK_ZERO (d) (res_ref, mask, 1); |
| 114 |
if (check_union128d (res3, res_ref)) |
| 115 |
abort (); |
| 116 |
|
| 117 |
compute_vgetmantsd (res_ref, src1.a, src2.a, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src); |
| 118 |
|
| 119 |
if (check_union128d (res4, res_ref)) |
| 120 |
abort (); |
| 121 |
|
| 122 |
MASK_MERGE (d) (res_ref, mask, 1); |
| 123 |
if (check_union128d (res5, res_ref)) |
| 124 |
abort (); |
| 125 |
|
| 126 |
MASK_ZERO (d) (res_ref, mask, 1); |
| 127 |
if (check_union128d (res6, res_ref)) |
| 128 |
abort (); |
| 129 |
|
| 130 |
} |