OSDN Git Service

Backport from mainline
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / powerpc / ppc-fma-3.c
1 /* { dg-do compile { target { powerpc*-*-* } } } */
2 /* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
3 /* { dg-require-effective-target powerpc_altivec_ok } */
4 /* { dg-require-effective-target powerpc_fprs } */
5 /* { dg-options "-O3 -ftree-vectorize -mcpu=power6 -maltivec -ffast-math" } */
6 /* { dg-final { scan-assembler-times "vmaddfp" 2 } } */
7 /* { dg-final { scan-assembler-times "fmadd " 2 } } */
8 /* { dg-final { scan-assembler-times "fmadds" 2 } } */
9 /* { dg-final { scan-assembler-times "fmsub " 1 } } */
10 /* { dg-final { scan-assembler-times "fmsubs" 1 } } */
11 /* { dg-final { scan-assembler-times "fnmadd " 1 } } */
12 /* { dg-final { scan-assembler-times "fnmadds" 1 } } */
13 /* { dg-final { scan-assembler-times "fnmsub " 1 } } */
14 /* { dg-final { scan-assembler-times "fnmsubs" 1 } } */
15
16 /* All functions should generate an appropriate (a * b) + c instruction
17    since -mfused-madd is on by default.  */
18
19 double
20 builtin_fma (double b, double c, double d)
21 {
22   return __builtin_fma (b, c, d);                       /* fmadd */
23 }
24
25 double
26 builtin_fms (double b, double c, double d)
27 {
28   return __builtin_fma (b, c, -d);                      /* fmsub */
29 }
30
31 double
32 builtin_fnma (double b, double c, double d)
33 {
34   return - __builtin_fma (b, c, d);                     /* fnmadd */
35 }
36
37 double
38 builtin_fnms (double b, double c, double d)
39 {
40   return - __builtin_fma (b, c, -d);                    /* fnmsub */
41 }
42
43 float
44 builtin_fmaf (float b, float c, float d)
45 {
46   return __builtin_fmaf (b, c, d);                      /* fmadds */
47 }
48
49 float
50 builtin_fmsf (float b, float c, float d)
51 {
52   return __builtin_fmaf (b, c, -d);                     /* fmsubs */
53 }
54
55 float
56 builtin_fnmaf (float b, float c, float d)
57 {
58   return - __builtin_fmaf (b, c, d);                    /* fnmadds */
59 }
60
61 float
62 builtin_fnmsf (float b, float c, float d)
63 {
64   return - __builtin_fmaf (b, c, -d);                   /* fnmsubs */
65 }
66
67 double
68 normal_fma (double b, double c, double d)
69 {
70   return (b * c) + d;                                   /* fmadd */
71 }
72
73 float
74 normal_fmaf (float b, float c, float d)
75 {
76   return (b * c) + d;                                   /* fmadds */
77 }
78
79 #ifndef SIZE
80 #define SIZE 1024
81 #endif
82
83 float vfa[SIZE] __attribute__((__aligned__(32)));
84 float vfb[SIZE] __attribute__((__aligned__(32)));
85 float vfc[SIZE] __attribute__((__aligned__(32)));
86 float vfd[SIZE] __attribute__((__aligned__(32)));
87
88 void
89 vector_fmaf (void)
90 {
91   int i;
92
93   for (i = 0; i < SIZE; i++)
94     vfa[i] = __builtin_fmaf (vfb[i], vfc[i], vfd[i]);   /* vaddfp */
95 }
96
97 void
98 vnormal_fmaf (void)
99 {
100   int i;
101
102   for (i = 0; i < SIZE; i++)
103     vfa[i] = (vfb[i] * vfc[i]) + vfd[i];                /* vaddfp */
104 }