summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/avx512f-vgetmantps-2.c
blob: b8ea24d891b86f27fca5c6516d1c5de46a733732 (plain)
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
123
/* { dg-do run } */
/* { dg-options "-O2 -mavx512f" } */
/* { dg-require-effective-target avx512f } */

#define AVX512F

#include "avx512f-helper.h"

#define SIZE (AVX512F_LEN / 32)
#include "avx512f-mask-type.h"
#include <math.h>

#ifndef GET_NORM_MANT
#define GET_NORM_MANT

union fp_int_t
{
  int int_val;
  float fp_val;
};

float
get_norm_mant (float source, int signctrl, int interv)
{
  int 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 >> 31);
  exp = (src & 0x7f800000) >> 23;
  fraction = (src & 0x7fffff);

  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 & 0xffbfffff);
      exp = 0x7f;
      while (!(src & 0x400000))
	{
	  src += fraction & 0x400000;
	  fraction = fraction << 1;
	  exp--;
	}
    }

  switch (interv)
    {
    case 0:
      exp = 0x7f;
      break;
    case 1:
      exp = ((exp - 0x7f) & 0x1) ? 0x7e : 0x7f;
      break;
    case 2:
      exp = 0x7e;
      break;
    case 3:
      exp = (fraction & 0x400000) ? 0x7e : 0x7f;
      break;
    default:
      abort ();
    }

  bin_conv.int_val = (sign << 31) | (exp << 23) | fraction;
  
  return bin_conv.fp_val;
}
#endif

CALC (float *r, float *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,) res1, res2, res3, src;
  MASK_TYPE mask = MASK_VALUE;
  float 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_ps) (src.x, interv, signctrl);
  res2.x =
    INTRINSIC (_mask_getmant_ps) (res2.x, mask, src.x, interv,
				  signctrl);
  res3.x =
    INTRINSIC (_maskz_getmant_ps) (mask, src.x, interv, signctrl);

  CALC (res_ref, src.a, interv, signctrl);

  if (UNION_CHECK (AVX512F_LEN,) (res1, res_ref))
    abort ();

  MASK_MERGE ()(res_ref, mask, SIZE);
  if (UNION_CHECK (AVX512F_LEN,) (res2, res_ref))
    abort ();

  MASK_ZERO ()(res_ref, mask, SIZE);
  if (UNION_CHECK (AVX512F_LEN,) (res3, res_ref))
    abort ();
}