summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/avx512er-vrcp28ps-3.c
blob: e08bea41c3e3f634df4cf109637a1190c041e3be (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
/* { dg-do run } */
/* { dg-require-effective-target avx512er } */
/* { dg-options "-O2 -ffast-math -ftree-vectorize -mavx512er" } */

#include "avx512er-check.h"

#define MAX 1000
#define EPS 0.00001

__attribute__ ((noinline, optimize (0)))
void static
compute_rcp_ref (float *a, float *b, float *r)
{
  for (int i = 0; i < MAX; i++)
    r[i] = a[i] / b[i];
}

__attribute__ ((noinline))
void static
compute_rcp_exp (float *a, float *b, float *r)
{
  for (int i = 0; i < MAX; i++)
    r[i] = a[i] / b[i];
}

void static
avx512er_test (void)
{
  float a[MAX];
  float b[MAX];
  float ref[MAX];
  float exp[MAX];

  for (int i = 0; i < MAX; i++)
    {
      a[i] = 179.345 - 6.5645 * i;
      b[i] = 8765.987 - 8.6756 * i;
    }

  compute_rcp_ref (a, b, ref);
  compute_rcp_exp (a, b, exp);

  for (int i = 0; i < MAX; i++)
    {
      float rel_err = (ref[i] - exp[i]) / ref[i];
      rel_err = rel_err > 0.0 ? rel_err : -rel_err;
      if (rel_err > EPS)
	abort ();
    }
}