libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-fma-1.c
blob27d206d9fa0601812b09a3ead2ee9730623e97e4
1 /* { dg-require-effective-target scalar_all_fma } */
3 #include "tree-vect.h"
5 #define N (VECTOR_BITS * 11 / 64 + 3)
7 #define DEF(INV) \
8 void __attribute__ ((noipa)) \
9 f_##INV (double *restrict a, double *restrict b, \
10 double *restrict c, double *restrict d) \
11 { \
12 for (int i = 0; i < N; ++i) \
13 { \
14 double mb = (INV & 1 ? -b[i] : b[i]); \
15 double mc = c[i]; \
16 double md = (INV & 2 ? -d[i] : d[i]); \
17 double fma = __builtin_fma (mb, mc, md); \
18 a[i] = (INV & 4 ? -fma : fma); \
19 } \
22 #define TEST(INV) \
23 { \
24 f_##INV (a, b, c, d); \
25 _Pragma("GCC novector") \
26 for (int i = 0; i < N; ++i) \
27 { \
28 double mb = (INV & 1 ? -b[i] : b[i]); \
29 double mc = c[i]; \
30 double md = (INV & 2 ? -d[i] : d[i]); \
31 double fma = __builtin_fma (mb, mc, md); \
32 double expected = (INV & 4 ? -fma : fma); \
33 if (a[i] != expected) \
34 __builtin_abort (); \
35 asm volatile ("" ::: "memory"); \
36 } \
39 #define FOR_EACH_INV(T) \
40 T (0) T (1) T (2) T (3) T (4) T (5) T (6) T (7)
42 FOR_EACH_INV (DEF)
44 int
45 main (void)
47 double a[N], b[N], c[N], d[N];
48 for (int i = 0; i < N; ++i)
50 b[i] = i % 17;
51 c[i] = i % 9 + 11;
52 d[i] = i % 13 + 14;
53 asm volatile ("" ::: "memory");
55 FOR_EACH_INV (TEST)
56 return 0;
59 /* { dg-final { scan-tree-dump-times "LOOP VECTORIZED" 8 "vect" { target vect_double } } } */