1 /* Test that the compiler properly generates floating point multiply
2 and add instructions FMA4 systems. */
3
4 /* { dg-do compile { target { ! ia32 } } } */
5 /* { dg-options "-O2 -mfma4 -mno-fma" } */
6
7 #ifndef __FP_FAST_FMAF
8 # error "__FP_FAST_FMAF should be defined"
9 #endif
10 #ifndef __FP_FAST_FMA
11 # error "__FP_FAST_FMA should be defined"
12 #endif
13
14 float
flt_mul_add(float a,float b,float c)15 flt_mul_add (float a, float b, float c)
16 {
17 return __builtin_fmaf (a, b, c);
18 }
19
20 double
dbl_mul_add(double a,double b,double c)21 dbl_mul_add (double a, double b, double c)
22 {
23 return __builtin_fma (a, b, c);
24 }
25
26 float
flt_mul_sub(float a,float b,float c)27 flt_mul_sub (float a, float b, float c)
28 {
29 return __builtin_fmaf (a, b, -c);
30 }
31
32 double
dbl_mul_sub(double a,double b,double c)33 dbl_mul_sub (double a, double b, double c)
34 {
35 return __builtin_fma (a, b, -c);
36 }
37
38 float
flt_neg_mul_add_1(float a,float b,float c)39 flt_neg_mul_add_1 (float a, float b, float c)
40 {
41 return __builtin_fmaf (-a, b, c);
42 }
43
44 double
dbl_neg_mul_add_1(double a,double b,double c)45 dbl_neg_mul_add_1 (double a, double b, double c)
46 {
47 return __builtin_fma (-a, b, c);
48 }
49
50 float
flt_neg_mul_add_2(float a,float b,float c)51 flt_neg_mul_add_2 (float a, float b, float c)
52 {
53 return __builtin_fmaf (a, -b, c);
54 }
55
56 double
dbl_neg_mul_add_2(double a,double b,double c)57 dbl_neg_mul_add_2 (double a, double b, double c)
58 {
59 return __builtin_fma (a, -b, c);
60 }
61
62 float
flt_neg_mul_sub(float a,float b,float c)63 flt_neg_mul_sub (float a, float b, float c)
64 {
65 return __builtin_fmaf (-a, b, -c);
66 }
67
68 double
dbl_neg_mul_sub(double a,double b,double c)69 dbl_neg_mul_sub (double a, double b, double c)
70 {
71 return __builtin_fma (-a, b, -c);
72 }
73
74 /* { dg-final { scan-assembler-times "vfmaddss" 1 } } */
75 /* { dg-final { scan-assembler-times "vfmaddsd" 1 } } */
76 /* { dg-final { scan-assembler-times "vfmsubss" 1 } } */
77 /* { dg-final { scan-assembler-times "vfmsubsd" 1 } } */
78 /* { dg-final { scan-assembler-times "vfnmaddss" 2 } } */
79 /* { dg-final { scan-assembler-times "vfnmaddsd" 2 } } */
80 /* { dg-final { scan-assembler-times "vfnmsubss" 1 } } */
81 /* { dg-final { scan-assembler-times "vfnmsubsd" 1 } } */
82