b3556f46c26bc96672f7321a7398b42b40191bb7
[gcc.git] / gcc / testsuite / gcc.target / aarch64 / advsimd-intrinsics / vqshrn_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. */
6 int VECT_VAR(expected_cumulative_sat,int,16,8) = 0;
7 int VECT_VAR(expected_cumulative_sat,int,32,4) = 0;
8 int VECT_VAR(expected_cumulative_sat,int,64,2) = 0;
9 int VECT_VAR(expected_cumulative_sat,uint,16,8) = 1;
10 int VECT_VAR(expected_cumulative_sat,uint,32,4) = 1;
11 int VECT_VAR(expected_cumulative_sat,uint,64,2) = 1;
12
13 /* Expected results. */
14 VECT_VAR_DECL(expected,int,8,8) [] = { 0xf8, 0xf8, 0xf9, 0xf9,
15 0xfa, 0xfa, 0xfb, 0xfb };
16 VECT_VAR_DECL(expected,int,16,4) [] = { 0xfff8, 0xfff8, 0xfff9, 0xfff9 };
17 VECT_VAR_DECL(expected,int,32,2) [] = { 0xfffffffc, 0xfffffffc };
18 VECT_VAR_DECL(expected,uint,8,8) [] = { 0xff, 0xff, 0xff, 0xff,
19 0xff, 0xff, 0xff, 0xff };
20 VECT_VAR_DECL(expected,uint,16,4) [] = { 0xffff, 0xffff, 0xffff, 0xffff };
21 VECT_VAR_DECL(expected,uint,32,2) [] = { 0xffffffff, 0xffffffff };
22
23 /* Expected values of cumulative_saturation flag with max input value
24 shifted by 3. */
25 int VECT_VAR(expected_cumulative_sat_max_sh3,int,16,8) = 1;
26 int VECT_VAR(expected_cumulative_sat_max_sh3,int,32,4) = 1;
27 int VECT_VAR(expected_cumulative_sat_max_sh3,int,64,2) = 1;
28 int VECT_VAR(expected_cumulative_sat_max_sh3,uint,16,8) = 1;
29 int VECT_VAR(expected_cumulative_sat_max_sh3,uint,32,4) = 1;
30 int VECT_VAR(expected_cumulative_sat_max_sh3,uint,64,2) = 1;
31
32 /* Expected results with max input value shifted by 3. */
33 VECT_VAR_DECL(expected_max_sh3,int,8,8) [] = { 0x7f, 0x7f, 0x7f, 0x7f,
34 0x7f, 0x7f, 0x7f, 0x7f };
35 VECT_VAR_DECL(expected_max_sh3,int,16,4) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff };
36 VECT_VAR_DECL(expected_max_sh3,int,32,2) [] = { 0x7fffffff, 0x7fffffff };
37 VECT_VAR_DECL(expected_max_sh3,uint,8,8) [] = { 0xff, 0xff, 0xff, 0xff,
38 0xff, 0xff, 0xff, 0xff };
39 VECT_VAR_DECL(expected_max_sh3,uint,16,4) [] = { 0xffff, 0xffff,
40 0xffff, 0xffff };
41 VECT_VAR_DECL(expected_max_sh3,uint,32,2) [] = { 0xffffffff, 0xffffffff };
42
43 /* Expected values of cumulative_saturation flag with max input value
44 shifted by type size. */
45 int VECT_VAR(expected_cumulative_sat_max_shmax,int,16,8) = 0;
46 int VECT_VAR(expected_cumulative_sat_max_shmax,int,32,4) = 0;
47 int VECT_VAR(expected_cumulative_sat_max_shmax,int,64,2) = 0;
48 int VECT_VAR(expected_cumulative_sat_max_shmax,uint,16,8) = 0;
49 int VECT_VAR(expected_cumulative_sat_max_shmax,uint,32,4) = 0;
50 int VECT_VAR(expected_cumulative_sat_max_shmax,uint,64,2) = 0;
51
52 /* Expected results with max input value shifted by type size. */
53 VECT_VAR_DECL(expected_max_shmax,int,8,8) [] = { 0x7f, 0x7f, 0x7f, 0x7f,
54 0x7f, 0x7f, 0x7f, 0x7f };
55 VECT_VAR_DECL(expected_max_shmax,int,16,4) [] = { 0x7fff, 0x7fff,
56 0x7fff, 0x7fff };
57 VECT_VAR_DECL(expected_max_shmax,int,32,2) [] = { 0x7fffffff, 0x7fffffff };
58 VECT_VAR_DECL(expected_max_shmax,uint,8,8) [] = { 0xff, 0xff, 0xff, 0xff,
59 0xff, 0xff, 0xff, 0xff };
60 VECT_VAR_DECL(expected_max_shmax,uint,16,4) [] = { 0xffff, 0xffff,
61 0xffff, 0xffff };
62 VECT_VAR_DECL(expected_max_shmax,uint,32,2) [] = { 0xffffffff, 0xffffffff };
63
64 #define INSN vqshrn_n
65 #define TEST_MSG "VQSHRN_N"
66
67 #define FNNAME1(NAME) void exec_ ## NAME (void)
68 #define FNNAME(NAME) FNNAME1(NAME)
69
70 FNNAME (INSN)
71 {
72 /* Basic test: y=vqshrn_n(x,v), then store the result. */
73 #define TEST_VQSHRN_N2(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT) \
74 Set_Neon_Cumulative_Sat(0, VECT_VAR(vector_res, T1, W2, N)); \
75 VECT_VAR(vector_res, T1, W2, N) = \
76 INSN##_##T2##W(VECT_VAR(vector, T1, W, N), \
77 V); \
78 vst1_##T2##W2(VECT_VAR(result, T1, W2, N), \
79 VECT_VAR(vector_res, T1, W2, N)); \
80 CHECK_CUMULATIVE_SAT(TEST_MSG, T1, W, N, EXPECTED_CUMULATIVE_SAT, CMT)
81
82 /* Two auxliary macros are necessary to expand INSN */
83 #define TEST_VQSHRN_N1(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT) \
84 TEST_VQSHRN_N2(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT)
85
86 #define TEST_VQSHRN_N(T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT) \
87 TEST_VQSHRN_N1(INSN, T1, T2, W, W2, N, V, EXPECTED_CUMULATIVE_SAT, CMT)
88
89
90 /* vector is twice as large as vector_res. */
91 DECL_VARIABLE(vector, int, 16, 8);
92 DECL_VARIABLE(vector, int, 32, 4);
93 DECL_VARIABLE(vector, int, 64, 2);
94 DECL_VARIABLE(vector, uint, 16, 8);
95 DECL_VARIABLE(vector, uint, 32, 4);
96 DECL_VARIABLE(vector, uint, 64, 2);
97
98 DECL_VARIABLE(vector_res, int, 8, 8);
99 DECL_VARIABLE(vector_res, int, 16, 4);
100 DECL_VARIABLE(vector_res, int, 32, 2);
101 DECL_VARIABLE(vector_res, uint, 8, 8);
102 DECL_VARIABLE(vector_res, uint, 16, 4);
103 DECL_VARIABLE(vector_res, uint, 32, 2);
104
105 clean_results ();
106
107 VLOAD(vector, buffer, q, int, s, 16, 8);
108 VLOAD(vector, buffer, q, int, s, 32, 4);
109 VLOAD(vector, buffer, q, int, s, 64, 2);
110 VLOAD(vector, buffer, q, uint, u, 16, 8);
111 VLOAD(vector, buffer, q, uint, u, 32, 4);
112 VLOAD(vector, buffer, q, uint, u, 64, 2);
113
114 /* Choose shift amount arbitrarily. */
115 #define CMT ""
116 TEST_VQSHRN_N(int, s, 16, 8, 8, 1, expected_cumulative_sat, CMT);
117 TEST_VQSHRN_N(int, s, 32, 16, 4, 1, expected_cumulative_sat, CMT);
118 TEST_VQSHRN_N(int, s, 64, 32, 2, 2, expected_cumulative_sat, CMT);
119 TEST_VQSHRN_N(uint, u, 16, 8, 8, 2, expected_cumulative_sat, CMT);
120 TEST_VQSHRN_N(uint, u, 32, 16, 4, 3, expected_cumulative_sat, CMT);
121 TEST_VQSHRN_N(uint, u, 64, 32, 2, 3, expected_cumulative_sat, CMT);
122
123 CHECK(TEST_MSG, int, 8, 8, PRIx8, expected, CMT);
124 CHECK(TEST_MSG, int, 16, 4, PRIx16, expected, CMT);
125 CHECK(TEST_MSG, int, 32, 2, PRIx32, expected, CMT);
126 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected, CMT);
127 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected, CMT);
128 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected, CMT);
129
130
131 /* Use max possible value as input. */
132 VDUP(vector, q, int, s, 16, 8, 0x7FFF);
133 VDUP(vector, q, int, s, 32, 4, 0x7FFFFFFF);
134 VDUP(vector, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
135 VDUP(vector, q, uint, u, 16, 8, 0xFFFF);
136 VDUP(vector, q, uint, u, 32, 4, 0xFFFFFFFF);
137 VDUP(vector, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
138
139 #undef CMT
140 #define CMT " (check saturation: shift by 3)"
141 TEST_VQSHRN_N(int, s, 16, 8, 8, 3, expected_cumulative_sat_max_sh3, CMT);
142 TEST_VQSHRN_N(int, s, 32, 16, 4, 3, expected_cumulative_sat_max_sh3, CMT);
143 TEST_VQSHRN_N(int, s, 64, 32, 2, 3, expected_cumulative_sat_max_sh3, CMT);
144 TEST_VQSHRN_N(uint, u, 16, 8, 8, 3, expected_cumulative_sat_max_sh3, CMT);
145 TEST_VQSHRN_N(uint, u, 32, 16, 4, 3, expected_cumulative_sat_max_sh3, CMT);
146 TEST_VQSHRN_N(uint, u, 64, 32, 2, 3, expected_cumulative_sat_max_sh3, CMT);
147
148 CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_max_sh3, CMT);
149 CHECK(TEST_MSG, int, 16, 4, PRIx16, expected_max_sh3, CMT);
150 CHECK(TEST_MSG, int, 32, 2, PRIx32, expected_max_sh3, CMT);
151 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_max_sh3, CMT);
152 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_max_sh3, CMT);
153 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_max_sh3, CMT);
154
155
156 #undef CMT
157 #define CMT " (check saturation: shift by max)"
158 TEST_VQSHRN_N(int, s, 16, 8, 8, 8, expected_cumulative_sat_max_shmax, CMT);
159 TEST_VQSHRN_N(int, s, 32, 16, 4, 16, expected_cumulative_sat_max_shmax, CMT);
160 TEST_VQSHRN_N(int, s, 64, 32, 2, 32, expected_cumulative_sat_max_shmax, CMT);
161 TEST_VQSHRN_N(uint, u, 16, 8, 8, 8, expected_cumulative_sat_max_shmax, CMT);
162 TEST_VQSHRN_N(uint, u, 32, 16, 4, 16, expected_cumulative_sat_max_shmax, CMT);
163 TEST_VQSHRN_N(uint, u, 64, 32, 2, 32, expected_cumulative_sat_max_shmax, CMT);
164
165 CHECK(TEST_MSG, int, 8, 8, PRIx8, expected_max_shmax, CMT);
166 CHECK(TEST_MSG, int, 16, 4, PRIx16, expected_max_shmax, CMT);
167 CHECK(TEST_MSG, int, 32, 2, PRIx32, expected_max_shmax, CMT);
168 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_max_shmax, CMT);
169 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_max_shmax, CMT);
170 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_max_shmax, CMT);
171 }
172
173 int main (void)
174 {
175 exec_vqshrn_n ();
176 return 0;
177 }