1 /* { dg-do run } */
2 /* { dg-options "-O3 --save-temps" } */
3
4 #include <arm_neon.h>
5
6 extern void abort (void);
7
8 #define ETYPE(size) int##size##_t
9 #define VTYPE(size, lanes) int##size##x##lanes##_t
10
11 #define TEST_VABS(q, size, lanes) \
12 static void \
13 test_vabs##q##_##size (ETYPE (size) * res, \
14 const ETYPE (size) *in1) \
15 { \
16 VTYPE (size, lanes) a = vld1##q##_s##size (res); \
17 VTYPE (size, lanes) b = vld1##q##_s##size (in1); \
18 a = vabs##q##_s##size (b); \
19 vst1##q##_s##size (res, a); \
20 }
21
22 #define BUILD_VARS(width, n_lanes, n_half_lanes) \
23 TEST_VABS (, width, n_half_lanes) \
24 TEST_VABS (q, width, n_lanes) \
25
26 BUILD_VARS (64, 2, 1)
27 BUILD_VARS (32, 4, 2)
28 BUILD_VARS (16, 8, 4)
29 BUILD_VARS (8, 16, 8)
30
31 #define POOL1 {-10}
32 #define POOL2 {2, -10}
33 #define POOL4 {0, -10, 2, -3}
34 #define POOL8 {0, -10, 2, -3, 4, -50, 6, -70}
35 #define POOL16 {0, -10, 2, -3, 4, -50, 6, -70, \
36 -5, 10, -2, 3, -4, 50, -6, 70}
37
38 #define EXPECTED1 {10}
39 #define EXPECTED2 {2, 10}
40 #define EXPECTED4 {0, 10, 2, 3}
41 #define EXPECTED8 {0, 10, 2, 3, 4, 50, 6, 70}
42 #define EXPECTED16 {0, 10, 2, 3, 4, 50, 6, 70, \
43 5, 10, 2, 3, 4, 50, 6, 70}
44
45 #define BUILD_TEST(size, lanes_64, lanes_128) \
46 static void \
47 test_##size (void) \
48 { \
49 int i; \
50 ETYPE (size) pool1[lanes_64] = POOL##lanes_64; \
51 ETYPE (size) res1[lanes_64] = {0}; \
52 ETYPE (size) expected1[lanes_64] = EXPECTED##lanes_64; \
53 ETYPE (size) pool2[lanes_128] = POOL##lanes_128; \
54 ETYPE (size) res2[lanes_128] = {0}; \
55 ETYPE (size) expected2[lanes_128] = EXPECTED##lanes_128; \
56 \
57 /* Forcefully avoid optimization. */ \
58 asm volatile ("" : : : "memory"); \
59 test_vabs_##size (res1, pool1); \
60 for (i = 0; i < lanes_64; i++) \
61 if (res1[i] != expected1[i]) \
62 abort (); \
63 \
64 /* Forcefully avoid optimization. */ \
65 asm volatile ("" : : : "memory"); \
66 test_vabsq_##size (res2, pool2); \
67 for (i = 0; i < lanes_128; i++) \
68 if (res2[i] != expected2[i]) \
69 abort (); \
70 }
71
72 /* { dg-final { scan-assembler-times "abs\\tv\[0-9\]+\.8b, v\[0-9\]+\.8b" 1 } } */
73 /* { dg-final { scan-assembler-times "abs\\tv\[0-9\]+\.16b, v\[0-9\]+\.16b" 1 } } */
74 BUILD_TEST (8 , 8, 16)
75
76 /* { dg-final { scan-assembler-times "abs\\tv\[0-9\]+\.4h, v\[0-9\]+\.4h" 1 } } */
77 /* { dg-final { scan-assembler-times "abs\\tv\[0-9\]+\.8h, v\[0-9\]+\.8h" 1 } } */
78 BUILD_TEST (16, 4, 8)
79
80 /* { dg-final { scan-assembler-times "abs\\tv\[0-9\]+\.2s, v\[0-9\]+\.2s" 1 } } */
81 /* { dg-final { scan-assembler-times "abs\\tv\[0-9\]+\.4s, v\[0-9\]+\.4s" 1 } } */
82 BUILD_TEST (32, 2, 4)
83
84 /* { dg-final { scan-assembler-times "abs\\tv\[0-9\]+\.2d, v\[0-9\]+\.2d" 1 } } */
85 BUILD_TEST (64, 1, 2)
86
87 #undef BUILD_TEST
88
89 #define BUILD_TEST(size) test_##size ()
90
91 int
main(int argc,char ** argv)92 main (int argc, char **argv)
93 {
94 BUILD_TEST (8);
95 BUILD_TEST (16);
96 BUILD_TEST (32);
97 BUILD_TEST (64);
98 return 0;
99 }
100
101