OSDN Git Service

PR target/50740
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / avx-rint-vec.c
1 /* { dg-do run } */
2 /* { dg-options "-O2 -ffast-math -ftree-vectorize -mavx" } */
3 /* { dg-require-effective-target avx } */
4 /* { dg-skip-if "no M_PI" { vxworks_kernel } } */
5
6 #include "avx-check.h"
7
8 #include <math.h>
9
10 extern double rint (double);
11
12 #define NUM 64
13
14 static void
15 __attribute__((__target__("fpmath=sse")))
16 init_src (double *src)
17 {
18   int i, sign = 1;
19   double f = rand ();
20
21   for (i = 0; i < NUM; i++)
22     {
23       src[i] = (i + 1) * f * M_PI * sign;
24       if (i < (NUM / 2))
25         {
26           if ((i % 6) == 0)
27             f = f * src[i];
28         }
29       else if (i == (NUM / 2))
30         f = rand ();
31       else if ((i % 6) == 0)
32         f = 1 / (f * (i + 1) * src[i] * M_PI * sign);
33       sign = -sign;
34     }
35 }
36
37 static void
38 __attribute__((__target__("fpmath=387")))
39 avx_test (void)
40 {
41   double a[NUM];
42   double r[NUM];
43   int i;
44
45   init_src (a);
46
47   for (i = 0; i < NUM; i++)
48     r[i] = rint (a[i]);
49
50   /* check results:  */
51   for (i = 0; i < NUM; i++)
52     if (r[i] != rint (a[i]))
53       abort();
54 }