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 "avx512f-helper.h"
8 #include <math.h>
9
10 union fp_int_t
11 {
12 int int_val;
13 float fp_val;
14 };
15
16 float
get_norm_mant(float source,int signctrl,int interv)17 get_norm_mant (float source, int signctrl, int interv)
18 {
19 int src, sign, exp, fraction;
20 union fp_int_t bin_conv;
21
22 bin_conv.fp_val = source;
23 src = bin_conv.int_val;
24 sign = (signctrl & 0x1) ? 0 : (src >> 31);
25 exp = (src & 0x7f800000) >> 23;
26 fraction = (src & 0x7fffff);
27
28 if (isnan (source))
29 return signbit (source) ? -NAN : NAN;
30 if (source == 0.0 || source == -0.0 || isinf (source))
31 return sign ? -1.0 : 1.0;
32 if (signbit (source) && (signctrl & 0x2))
33 return -NAN;
34 if (!isnormal (source))
35 {
36 src = (src & 0xffbfffff);
37 exp = 0x7f;
38 while (!(src & 0x400000))
39 {
40 src += fraction & 0x400000;
41 fraction = fraction << 1;
42 exp--;
43 }
44 }
45
46 switch (interv)
47 {
48 case 0:
49 exp = 0x7f;
50 break;
51 case 1:
52 exp = ((exp - 0x7f) & 0x1) ? 0x7e : 0x7f;
53 break;
54 case 2:
55 exp = 0x7e;
56 break;
57 case 3:
58 exp = (fraction & 0x400000) ? 0x7e : 0x7f;
59 break;
60 default:
61 abort ();
62 }
63
64 bin_conv.int_val = (sign << 31) | (exp << 23) | fraction;
65
66 return bin_conv.fp_val;
67
68 }
69
70 static void
compute_vgetmantss(float * r,float * s1,float * s2,int interv,int signctrl)71 compute_vgetmantss (float *r, float *s1, float *s2, int interv,
72 int signctrl)
73 {
74 int i;
75 r[0] = get_norm_mant (s2[0], signctrl, interv);
76 for (i = 1; i < 4; i++)
77 {
78 r[i] = s1[i];
79 }
80 }
81
82 static void
avx512f_test(void)83 avx512f_test (void)
84 {
85 int i, sign;
86 union128 res1, src1, src2;
87 float res_ref[4];
88 int interv = _MM_MANT_NORM_p5_1;
89 int signctrl = _MM_MANT_SIGN_src;
90
91 src1.x = _mm_set_ps (-24.043, 68.346, -43.35, 546.46);
92 src2.x = _mm_set_ps (222.222, 333.333, 444.444, -2.0);
93
94 res1.x = _mm_getmant_ss (src1.x, src2.x, interv, signctrl);
95
96 compute_vgetmantss (res_ref, src1.a, src2.a, interv, signctrl);
97
98 if (check_union128 (res1, res_ref))
99 abort ();
100 }
101