vqrshrun_n.c: New file.
[gcc.git] / gcc / testsuite / gcc.target / aarch64 / advsimd-intrinsics / vqrshrun_n.c
1 #include <arm_neon.h>
2 #include "arm-neon-ref.h"
3 #include "compute-ref-data.h"
4
5 /* Expected values of cumulative_saturation flag with negative unput. */
6 int VECT_VAR(expected_cumulative_sat_neg,int,16,8) = 0;
7 int VECT_VAR(expected_cumulative_sat_neg,int,32,4) = 0;
8 int VECT_VAR(expected_cumulative_sat_neg,int,64,2) = 1;
9
10 /* Expected results with negative input. */
11 VECT_VAR_DECL(expected_neg,uint,8,8) [] = { 0x0, 0x0, 0x0, 0x0,
12 0x0, 0x0, 0x0, 0x0 };
13 VECT_VAR_DECL(expected_neg,uint,16,4) [] = { 0x0, 0x0, 0x0, 0x0 };
14 VECT_VAR_DECL(expected_neg,uint,32,2) [] = { 0x0, 0x0 };
15
16 /* Expected values of cumulative_saturation flag with max input value
17 shifted by 1. */
18 int VECT_VAR(expected_cumulative_sat_max_sh1,int,16,8) = 1;
19 int VECT_VAR(expected_cumulative_sat_max_sh1,int,32,4) = 1;
20 int VECT_VAR(expected_cumulative_sat_max_sh1,int,64,2) = 1;
21
22 /* Expected results with max input value shifted by 1. */
23 VECT_VAR_DECL(expected_max_sh1,uint,8,8) [] = { 0xff, 0xff, 0xff, 0xff,
24 0xff, 0xff, 0xff, 0xff };
25 VECT_VAR_DECL(expected_max_sh1,uint,16,4) [] = { 0xffff, 0xffff,
26 0xffff, 0xffff };
27 VECT_VAR_DECL(expected_max_sh1,uint,32,2) [] = { 0xffffffff, 0xffffffff };
28 VECT_VAR_DECL(expected_max_sh1,uint,64,1) [] = { 0x3333333333333333 };
29
30 /* Expected values of cumulative_saturation flag with max input value
31 shifted by max amount. */
32 int VECT_VAR(expected_cumulative_sat_max_shmax,int,16,8) = 0;
33 int VECT_VAR(expected_cumulative_sat_max_shmax,int,32,4) = 0;
34 int VECT_VAR(expected_cumulative_sat_max_shmax,int,64,2) = 0;
35
36 /* Expected results with max input value shifted by max amount. */
37 VECT_VAR_DECL(expected_max_shmax,uint,8,8) [] = { 0x80, 0x80, 0x80, 0x80,
38 0x80, 0x80, 0x80, 0x80 };
39 VECT_VAR_DECL(expected_max_shmax,uint,16,4) [] = { 0x8000, 0x8000,
40 0x8000, 0x8000 };
41 VECT_VAR_DECL(expected_max_shmax,uint,32,2) [] = { 0x80000000, 0x80000000 };
42
43 /* Expected values of cumulative_saturation flag with min input value
44 shifted by max amount. */
45 int VECT_VAR(expected_cumulative_sat_min_shmax,int,16,8) = 1;
46 int VECT_VAR(expected_cumulative_sat_min_shmax,int,32,4) = 1;
47 int VECT_VAR(expected_cumulative_sat_min_shmax,int,64,2) = 1;
48
49 /* Expected results with min input value shifted by max amount. */
50 VECT_VAR_DECL(expected_min_shmax,uint,8,8) [] = { 0x0, 0x0, 0x0, 0x0,
51 0x0, 0x0, 0x0, 0x0 };
52 VECT_VAR_DECL(expected_min_shmax,uint,16,4) [] = { 0x0, 0x0, 0x0, 0x0 };
53 VECT_VAR_DECL(expected_min_shmax,uint,32,2) [] = { 0x0, 0x0 };
54
55 /* Expected values of cumulative_saturation flag with inputs in usual
56 range. */
57 int VECT_VAR(expected_cumulative_sat,int,16,8) = 0;
58 int VECT_VAR(expected_cumulative_sat,int,32,4) = 1;
59 int VECT_VAR(expected_cumulative_sat,int,64,2) = 0;
60
61 /* Expected results with inputs in usual range. */
62 VECT_VAR_DECL(expected,uint,8,8) [] = { 0x49, 0x49, 0x49, 0x49,
63 0x49, 0x49, 0x49, 0x49 };
64 VECT_VAR_DECL(expected,uint,16,4) [] = { 0x0, 0x0, 0x0, 0x0 };
65 VECT_VAR_DECL(expected,uint,32,2) [] = { 0xdeadbf, 0xdeadbf };
66
67 #define INSN vqrshrun_n
68 #define TEST_MSG "VQRSHRUN_N"
69
70 #define FNNAME1(NAME) void exec_ ## NAME (void)
71 #define FNNAME(NAME) FNNAME1(NAME)
72
73 FNNAME (INSN)
74 {
75 /* Basic test: y=vqrshrun_n(x,v), then store the result. */
76 #define TEST_VQRSHRUN_N2(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT) \
77 Set_Neon_Cumulative_Sat(0, VECT_VAR(vector_res, uint, W2, N)); \
78 VECT_VAR(vector_res, uint, W2, N) = \
79 INSN##_##T2##W(VECT_VAR(vector, T1, W, N), \
80 V); \
81 vst1_u##W2(VECT_VAR(result, uint, W2, N), \
82 VECT_VAR(vector_res, uint, W2, N)); \
83 CHECK_CUMULATIVE_SAT(TEST_MSG, T1, W, N, EXPECTED_CUMULATIVE_SAT, CMT)
84
85 /* Two auxliary macros are necessary to expand INSN */
86 #define TEST_VQRSHRUN_N1(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT) \
87 TEST_VQRSHRUN_N2(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT)
88
89 #define TEST_VQRSHRUN_N(T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT) \
90 TEST_VQRSHRUN_N1(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT)
91
92
93 /* vector is twice as large as vector_res. */
94 DECL_VARIABLE(vector, int, 16, 8);
95 DECL_VARIABLE(vector, int, 32, 4);
96 DECL_VARIABLE(vector, int, 64, 2);
97
98 DECL_VARIABLE(vector_res, uint, 8, 8);
99 DECL_VARIABLE(vector_res, uint, 16, 4);
100 DECL_VARIABLE(vector_res, uint, 32, 2);
101
102 clean_results ();
103
104 /* Fill input vector with negative values, to check saturation on
105 limits. */
106 VDUP(vector, q, int, s, 16, 8, -2);
107 VDUP(vector, q, int, s, 32, 4, -3);
108 VDUP(vector, q, int, s, 64, 2, -4);
109
110 /* Choose shift amount arbitrarily. */
111 #define CMT " (negative input)"
112 TEST_VQRSHRUN_N(int, s, 16, 8, 8, 3, expected_cumulative_sat_neg, CMT);
113 TEST_VQRSHRUN_N(int, s, 32, 16, 4, 4, expected_cumulative_sat_neg, CMT);
114 TEST_VQRSHRUN_N(int, s, 64, 32, 2, 2, expected_cumulative_sat_neg, CMT);
115
116 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_neg, CMT);
117 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_neg, CMT);
118 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_neg, CMT);
119
120
121 /* Fill input vector with max value, to check saturation on
122 limits. */
123 VDUP(vector, q, int, s, 16, 8, 0x7FFF);
124 VDUP(vector, q, int, s, 32, 4, 0x7FFFFFFF);
125 VDUP(vector, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
126
127 /* shift by 1. */
128 #undef CMT
129 #define CMT " (check cumulative saturation: shift by 1)"
130 TEST_VQRSHRUN_N(int, s, 16, 8, 8, 1, expected_cumulative_sat_max_sh1, CMT);
131 TEST_VQRSHRUN_N(int, s, 32, 16, 4, 1, expected_cumulative_sat_max_sh1, CMT);
132 TEST_VQRSHRUN_N(int, s, 64, 32, 2, 1, expected_cumulative_sat_max_sh1, CMT);
133
134 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_max_sh1, CMT);
135 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_max_sh1, CMT);
136 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_max_sh1, CMT);
137
138
139 /* shift by max. */
140 #undef CMT
141 #define CMT " (check cumulative saturation: shift by max, positive input)"
142 TEST_VQRSHRUN_N(int, s, 16, 8, 8, 8, expected_cumulative_sat_max_shmax, CMT);
143 TEST_VQRSHRUN_N(int, s, 32, 16, 4, 16, expected_cumulative_sat_max_shmax, CMT);
144 TEST_VQRSHRUN_N(int, s, 64, 32, 2, 32, expected_cumulative_sat_max_shmax, CMT);
145
146 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_max_shmax, CMT);
147 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_max_shmax, CMT);
148 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_max_shmax, CMT);
149
150
151 /* Fill input vector with min value, to check saturation on limits. */
152 VDUP(vector, q, int, s, 16, 8, 0x8000);
153 VDUP(vector, q, int, s, 32, 4, 0x80000000);
154 VDUP(vector, q, int, s, 64, 2, 0x8000000000000000LL);
155
156 /* shift by max */
157 #undef CMT
158 #define CMT " (check cumulative saturation: shift by max, negative input)"
159 TEST_VQRSHRUN_N(int, s, 16, 8, 8, 8, expected_cumulative_sat_min_shmax, CMT);
160 TEST_VQRSHRUN_N(int, s, 32, 16, 4, 16, expected_cumulative_sat_min_shmax, CMT);
161 TEST_VQRSHRUN_N(int, s, 64, 32, 2, 32, expected_cumulative_sat_min_shmax, CMT);
162
163 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_min_shmax, CMT);
164 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_min_shmax, CMT);
165 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_min_shmax, CMT);
166
167
168 /* Fill input vector with positive values, to check normal case. */
169 VDUP(vector, q, int, s, 16, 8, 0x1234);
170 VDUP(vector, q, int, s, 32, 4, 0x87654321);
171 VDUP(vector, q, int, s, 64, 2, 0xDEADBEEF);
172
173 /* shift arbitrary amount. */
174 #undef CMT
175 #define CMT ""
176 TEST_VQRSHRUN_N(int, s, 16, 8, 8, 6, expected_cumulative_sat, CMT);
177 TEST_VQRSHRUN_N(int, s, 32, 16, 4, 7, expected_cumulative_sat, CMT);
178 TEST_VQRSHRUN_N(int, s, 64, 32, 2, 8, expected_cumulative_sat, CMT);
179
180 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected, CMT);
181 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected, CMT);
182 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected, CMT);
183 }
184
185 int main (void)
186 {
187 exec_vqrshrun_n ();
188 return 0;
189 }