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