1 /* { dg-do run } */
2 /* { dg-options "-O3 --save-temps" } */
3
4 #include <arm_neon.h>
5
6 #define DELTA 0.0001
7
8 extern double fabs (double);
9
10 extern void abort (void);
11
12 #define TEST_VMLA(q1, q2, size, in1_lanes, in2_lanes) \
13 static void \
14 __attribute__((noipa,noinline)) \
15 test_vfma##q1##_lane##q2##_f##size (float##size##_t * res, \
16 const float##size##_t *in1, \
17 const float##size##_t *in2) \
18 { \
19 float##size##x##in1_lanes##_t a = vld1##q1##_f##size (res); \
20 float##size##x##in1_lanes##_t b = vld1##q1##_f##size (in1); \
21 float##size##x##in2_lanes##_t c; \
22 if (in2_lanes > 1) \
23 { \
24 c = vld1##q2##_f##size (in2); \
25 a = vfma##q1##_lane##q2##_f##size (a, b, c, 1); \
26 } \
27 else \
28 { \
29 c = vld1##q2##_f##size (in2 + 1); \
30 a = vfma##q1##_lane##q2##_f##size (a, b, c, 0); \
31 } \
32 vst1##q1##_f##size (res, a); \
33 }
34
35 #define BUILD_VARS(width, n_lanes, n_half_lanes) \
36 TEST_VMLA ( , , width, n_half_lanes, n_half_lanes) \
37 TEST_VMLA (q, , width, n_lanes, n_half_lanes) \
38 TEST_VMLA ( , q, width, n_half_lanes, n_lanes) \
39 TEST_VMLA (q, q, width, n_lanes, n_lanes) \
40
41 BUILD_VARS (32, 4, 2)
42 BUILD_VARS (64, 2, 1)
43
44 #define POOL2 {0.0, 1.0}
45 #define POOL4 {0.0, 1.0, 2.0, 3.0}
46 #define EMPTY2 {0.0, 0.0}
47 #define EMPTY4 {0.0, 0.0, 0.0, 0.0}
48
49 #define BUILD_TEST(size, lanes) \
50 static void \
51 test_f##size (void) \
52 { \
53 int i; \
54 float##size##_t pool[lanes] = POOL##lanes; \
55 float##size##_t res[lanes] = EMPTY##lanes; \
56 float##size##_t res2[lanes] = EMPTY##lanes; \
57 float##size##_t res3[lanes] = EMPTY##lanes; \
58 float##size##_t res4[lanes] = EMPTY##lanes; \
59 \
60 /* Forecfully avoid optimization. */ \
61 asm volatile ("" : : : "memory"); \
62 test_vfma_lane_f##size (res, pool, pool); \
63 for (i = 0; i < lanes / 2; i++) \
64 if (fabs (res[i] - pool[i]) > DELTA) \
65 abort (); \
66 \
67 /* Forecfully avoid optimization. */ \
68 asm volatile ("" : : : "memory"); \
69 test_vfmaq_lane_f##size (res2, pool, pool); \
70 for (i = 0; i < lanes; i++) \
71 if (fabs (res2[i] - pool[i]) > DELTA) \
72 abort (); \
73 \
74 /* Forecfully avoid optimization. */ \
75 asm volatile ("" : : : "memory"); \
76 test_vfma_laneq_f##size (res3, pool, pool); \
77 for (i = 0; i < lanes / 2; i++) \
78 if (fabs (res3[i] - pool[i]) > DELTA) \
79 abort (); \
80 \
81 /* Forecfully avoid optimization. */ \
82 asm volatile ("" : : : "memory"); \
83 test_vfmaq_laneq_f##size (res4, pool, pool); \
84 for (i = 0; i < lanes; i++) \
85 if (fabs (res4[i] - pool[i]) > DELTA) \
86 abort (); \
87 }
88
89 BUILD_TEST (32, 4)
90 BUILD_TEST (64, 2)
91
92 int
93 main (int argc, char **argv)
94 {
95 test_f32 ();
96 test_f64 ();
97 return 0;
98 }
99
100 /* vfma_laneq_f32.
101 vfma_lane_f32. */
102 /* { dg-final { scan-assembler-times "fmla\\tv\[0-9\]+\.2s, v\[0-9\]+\.2s, v\[0-9\]+\.s\\\[\[0-9\]+\\\]" 2 } } */
103
104 /* vfmaq_lane_f32.
105 vfmaq_laneq_f32. */
106 /* { dg-final { scan-assembler-times "fmla\\tv\[0-9\]+\.4s, v\[0-9\]+\.4s, v\[0-9\]+\.s\\\[\[0-9\]+\\\]" 2 } } */
107
108 /* vfma_lane_f64.
109 vfma_laneq_f64. */
110 /* { dg-final { scan-assembler-times "fmadd\\td\[0-9\]+\, d\[0-9\]+\, d\[0-9\]+\, d\[0-9\]+" 1 { target aarch64_big_endian } } } */
111 /* { dg-final { scan-assembler-times "fmadd\\td\[0-9\]+\, d\[0-9\]+\, d\[0-9\]+\, d\[0-9\]+" 2 { target aarch64_little_endian } } } */
112
113 /* vfmaq_lane_f64.
114 vfmaq_laneq_f64. */
115 /* { dg-final { scan-assembler-times "fmla\\tv\[0-9\]+\.2d, v\[0-9\]+\.2d, v\[0-9\]+\.d\\\[\[0-9\]+\\\]" 3 { target aarch64_big_endian } } } */
116 /* { dg-final { scan-assembler-times "fmla\\tv\[0-9\]+\.2d, v\[0-9\]+\.2d, v\[0-9\]+\.d\\\[\[0-9\]+\\\]" 2 { target aarch64_little_endian } } } */
117
118