Stop only if there aren't any usable algorithms
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / fma4-maccXX.c
blob4b4c00596a795db10bb53f61705ce055c070975e
1 /* { dg-do run } */
2 /* { dg-require-effective-target fma4 } */
3 /* { dg-options "-O0 -mfma4" } */
5 #include "fma4-check.h"
7 #include <x86intrin.h>
8 #include <string.h>
10 #define NUM 20
12 union
14 __m128 x[NUM];
15 float f[NUM * 4];
16 __m128d y[NUM];
17 double d[NUM * 2];
18 } dst, res, src1, src2, src3;
21 /* Note that in macc*,msub*,mnmacc* and mnsub* instructions, the intermdediate
22 product is not rounded, only the addition is rounded. */
24 static void
25 init_maccps ()
27 int i;
28 for (i = 0; i < NUM * 4; i++)
30 src1.f[i] = i;
31 src2.f[i] = i + 10;
32 src3.f[i] = i + 20;
36 static void
37 init_maccpd ()
39 int i;
40 for (i = 0; i < NUM * 4; i++)
42 src1.d[i] = i;
43 src2.d[i] = i + 10;
44 src3.d[i] = i + 20;
48 static int
49 check_maccps ()
51 int i, j, check_fails = 0;
52 for (i = 0; i < NUM * 4; i = i + 4)
53 for (j = 0; j < 4; j++)
55 res.f[i + j] = (src1.f[i + j] * src2.f[i + j]) + src3.f[i + j];
56 if (dst.f[i + j] != res.f[i + j])
57 check_fails++;
59 return check_fails++;
62 static int
63 check_maccpd ()
65 int i, j, check_fails = 0;
66 for (i = 0; i < NUM * 2; i = i + 2)
67 for (j = 0; j < 2; j++)
69 res.d[i + j] = (src1.d[i + j] * src2.d[i + j]) + src3.d[i + j];
70 if (dst.d[i + j] != res.d[i + j])
71 check_fails++;
73 return check_fails++;
77 static int
78 check_maccss ()
80 int i, j, check_fails = 0;
81 for (i = 0; i < NUM * 4; i= i + 4)
83 res.f[i] = (src1.f[i] * src2.f[i]) + src3.f[i];
84 if (dst.f[i] != res.f[i])
85 check_fails++;
87 return check_fails++;
90 static int
91 check_maccsd ()
93 int i, j, check_fails = 0;
94 for (i = 0; i < NUM * 2; i = i + 2)
96 res.d[i] = (src1.d[i] * src2.d[i]) + src3.d[i];
97 if (dst.d[i] != res.d[i])
98 check_fails++;
100 return check_fails++;
103 static void
104 fma4_test (void)
106 int i;
108 init_maccps ();
110 for (i = 0; i < NUM; i++)
111 dst.x[i] = _mm_macc_ps (src1.x[i], src2.x[i], src3.x[i]);
113 if (check_maccps ())
114 abort ();
116 for (i = 0; i < NUM; i++)
117 dst.x[i] = _mm_macc_ss (src1.x[i], src2.x[i], src3.x[i]);
119 if (check_maccss ())
120 abort ();
122 init_maccpd ();
124 for (i = 0; i < NUM; i++)
125 dst.y[i] = _mm_macc_pd (src1.y[i], src2.y[i], src3.y[i]);
127 if (check_maccpd ())
128 abort ();
130 for (i = 0; i < NUM; i++)
131 dst.y[i] = _mm_macc_sd (src1.y[i], src2.y[i], src3.y[i]);
133 if (check_maccsd ())
134 abort ();