1 /* { dg-do run } */
2 /* { dg-require-effective-target fma } */
3 /* { dg-options "-O2 -mfma" } */
4 
5 #include "fma-check.h"
6 
7 #include <x86intrin.h>
8 #include "m256-check.h"
9 
10 void
check_mm_fmsub_pd(__m128d __A,__m128d __B,__m128d __C)11 check_mm_fmsub_pd (__m128d __A, __m128d __B, __m128d __C)
12 {
13   union128d a, b, c, e;
14   a.x = __A;
15   b.x = __B;
16   c.x = __C;
17   double d[2];
18   int i;
19   e.x = _mm_fmsub_pd (__A, __B, __C);
20   for (i = 0; i < 2; i++)
21     {
22       d[i] = a.a[i] * b.a[i] - c.a[i];
23     }
24   if (check_union128d (e, d))
25     abort ();
26 }
27 
28 void
check_mm_fmsub_ps(__m128 __A,__m128 __B,__m128 __C)29 check_mm_fmsub_ps (__m128 __A, __m128 __B, __m128 __C)
30 {
31   union128 a, b, c, e;
32   a.x = __A;
33   b.x = __B;
34   c.x = __C;
35   float d[4];
36   int i;
37   e.x = _mm_fmsub_ps (__A, __B, __C);
38   for (i = 0; i < 4; i++)
39     {
40       d[i] = a.a[i] * b.a[i] - c.a[i];
41     }
42   if (check_union128 (e, d))
43     abort ();
44 }
45 
46 void
check_mm_fmsub_sd(__m128d __A,__m128d __B,__m128d __C)47 check_mm_fmsub_sd (__m128d __A, __m128d __B, __m128d __C)
48 {
49   union128d a, b, c, e;
50   a.x = __A;
51   b.x = __B;
52   c.x = __C;
53   double d[2];
54   int i;
55   e.x = _mm_fmsub_sd (__A, __B, __C);
56   for (i = 1; i < 2; i++)
57     {
58       d[i] = a.a[i];
59     }
60   d[0] = a.a[0] * b.a[0] - c.a[0];
61   if (check_union128d (e, d))
62     abort ();
63 }
64 
65 void
check_mm_fmsub_ss(__m128 __A,__m128 __B,__m128 __C)66 check_mm_fmsub_ss (__m128 __A, __m128 __B, __m128 __C)
67 {
68   union128 a, b, c, e;
69   a.x = __A;
70   b.x = __B;
71   c.x = __C;
72   float d[4];
73   int i;
74   e.x = _mm_fmsub_ss (__A, __B, __C);
75   for (i = 1; i < 4; i++)
76     {
77       d[i] = a.a[i];
78     }
79   d[0] = a.a[0] * b.a[0] - c.a[0];
80   if (check_union128 (e, d))
81     abort ();
82 }
83 
84 static void
fma_test(void)85 fma_test (void)
86 {
87   union128 a[3];
88   union128d b[3];
89   int i, j;
90   for (i = 0; i < 3; i++)
91     {
92       for (j = 0; j < 4; j++)
93 	a[i].a[j] = i * j + 3.5;
94       for (j = 0; j < 2; j++)
95 	b[i].a[j] = i * j + 3.5;
96     }
97   check_mm_fmsub_pd (b[0].x, b[1].x, b[2].x);
98   check_mm_fmsub_sd (b[0].x, b[1].x, b[2].x);
99   check_mm_fmsub_ps (a[0].x, a[1].x, a[2].x);
100   check_mm_fmsub_ss (a[0].x, a[1].x, a[2].x);
101 }
102