2016-12-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / avx512f-vgetmantpd-2.c
blobcb24b97f1597e7a6afa4619eae28c634d575c737
1 /* { dg-do run } */
2 /* { dg-options "-O2 -mavx512f -std=c99" } */
3 /* { dg-require-effective-target avx512f } */
4 /* { dg-require-effective-target c99_runtime } */
6 #define AVX512F
8 #include "avx512f-helper.h"
10 #define SIZE (AVX512F_LEN / 64)
11 #include "avx512f-mask-type.h"
12 #include <math.h>
14 #ifndef GET_NORM_MANT
15 #define GET_NORM_MANT
17 union fp_int_t
19 long long int int_val;
20 double fp_val;
23 double
24 get_norm_mant (double source, int signctrl, int interv)
26 long long src, sign, exp, fraction;
27 union fp_int_t bin_conv;
29 bin_conv.fp_val = source;
30 src = bin_conv.int_val;
31 sign = (signctrl & 0x1) ? 0 : (src >> 63);
32 exp = (src & 0x7ff0000000000000) >> 52;
33 fraction = (src & 0xfffffffffffff);
35 if (isnan (source))
36 return signbit (source) ? -NAN : NAN;
37 if (source == 0.0 || source == -0.0 || isinf (source))
38 return sign ? -1.0 : 1.0;
39 if (signbit (source) && (signctrl & 0x2))
40 return -NAN;
41 if (!isnormal (source))
43 src = (src & 0xfff7ffffffffffff);
44 exp = 0x3ff;
45 while (!(src & 0x8000000000000))
47 src += fraction & 0x8000000000000;
48 fraction = fraction << 1;
49 exp--;
53 switch (interv)
55 case 0:
56 exp = 0x3ff;
57 break;
58 case 1:
59 exp = ((exp - 0x3ff) & 0x1) ? 0x3fe : 0x3ff;
60 break;
61 case 2:
62 exp = 0x3fe;
63 break;
64 case 3:
65 exp = (fraction & 0x8000000000000) ? 0x3fe : 0x3ff;
66 break;
67 default:
68 abort ();
71 bin_conv.int_val = (sign << 63) | (exp << 52) | fraction;
72 return bin_conv.fp_val;
74 #endif
76 void static
77 CALC (double *r, double *s, int interv, int signctrl)
79 int i;
80 for (i = 0; i < SIZE; i++)
82 r[i] = get_norm_mant (s[i], signctrl, interv);
86 void
87 TEST (void)
89 int i, sign;
90 UNION_TYPE (AVX512F_LEN, d) res1, res2, res3, src;
91 MASK_TYPE mask = MASK_VALUE;
92 double res_ref[SIZE];
93 int interv = _MM_MANT_NORM_p5_1;
94 int signctrl = _MM_MANT_SIGN_src;
96 sign = -1;
97 for (i = 0; i < SIZE; i++)
99 src.a[i] = 34.67 * i * sign;
100 sign = sign * -1;
102 for (i = 0; i < SIZE; i++)
103 res2.a[i] = DEFAULT_VALUE;
105 res1.x = INTRINSIC (_getmant_pd) (src.x, interv, signctrl);
106 res2.x =
107 INTRINSIC (_mask_getmant_pd) (res2.x, mask, src.x, interv,
108 signctrl);
109 res3.x =
110 INTRINSIC (_maskz_getmant_pd) (mask, src.x, interv, signctrl);
112 CALC (res_ref, src.a, interv, signctrl);
114 if (UNION_CHECK (AVX512F_LEN, d) (res1, res_ref))
115 abort ();
117 MASK_MERGE (d) (res_ref, mask, SIZE);
118 if (UNION_CHECK (AVX512F_LEN, d) (res2, res_ref))
119 abort ();
121 MASK_ZERO (d) (res_ref, mask, SIZE);
122 if (UNION_CHECK (AVX512F_LEN, d) (res3, res_ref))
123 abort ();