1 /* { dg-do run } */
2 /* { dg-require-effective-target avx512f } */
3 /* { dg-options "-O3 -mavx512f -mprefer-vector-width=512 -save-temps" } */
4
5 #include "fma-check.h"
6 void __attribute__((noipa))
check_fmaddsub(double * __restrict a,double * b,double * c,int n)7 check_fmaddsub (double * __restrict a, double *b, double *c, int n)
8 {
9 for (int i = 0; i < n; ++i)
10 {
11 a[8*i + 0] = b[8*i + 0] * c[8*i + 0] + a[8*i + 0];
12 a[8*i + 1] = b[8*i + 1] * c[8*i + 1] - a[8*i + 1];
13 a[8*i + 2] = b[8*i + 2] * c[8*i + 2] + a[8*i + 2];
14 a[8*i + 3] = b[8*i + 3] * c[8*i + 3] - a[8*i + 3];
15 a[8*i + 4] = b[8*i + 4] * c[8*i + 4] + a[8*i + 4];
16 a[8*i + 5] = b[8*i + 5] * c[8*i + 5] - a[8*i + 5];
17 a[8*i + 6] = b[8*i + 6] * c[8*i + 6] + a[8*i + 6];
18 a[8*i + 7] = b[8*i + 7] * c[8*i + 7] - a[8*i + 7];
19 }
20 }
21
22 static void
fma_test(void)23 fma_test (void)
24 {
25 if (!__builtin_cpu_supports ("avx512f"))
26 return;
27 double a[8], b[8], c[8];
28 for (int i = 0; i < 8; ++i)
29 {
30 a[i] = i;
31 b[i] = 3*i;
32 c[i] = 7*i;
33 }
34 check_fmaddsub (a, b, c, 1);
35 const double d[8] = { 0., 20., 86., 186., 340., 520., 762., 1022.};
36 for (int i = 0; i < 8; ++i)
37 if (a[i] != d[i])
38 __builtin_abort ();
39 }
40
41 /* { dg-final { scan-assembler {(?n)fmsubadd...pd[ \t].*%zmm[0-9]} } } */
42