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