1#include <arm_neon.h> 2#include "arm-neon-ref.h" 3#include "compute-ref-data.h" 4#include <math.h> 5 6/* Additional expected results declaration, they are initialized in 7 each test file. */ 8extern ARRAY(expected_uint, uint, 8, 8); 9extern ARRAY(expected_uint, uint, 16, 4); 10extern ARRAY(expected_uint, uint, 32, 2); 11extern ARRAY(expected_q_uint, uint, 8, 16); 12extern ARRAY(expected_q_uint, uint, 16, 8); 13extern ARRAY(expected_q_uint, uint, 32, 4); 14#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 15extern ARRAY(expected_float, uint, 16, 4); 16extern ARRAY(expected_q_float, uint, 16, 8); 17extern ARRAY(expected_nan, uint, 16, 4); 18extern ARRAY(expected_mnan, uint, 16, 4); 19extern ARRAY(expected_nan2, uint, 16, 4); 20extern ARRAY(expected_inf, uint, 16, 4); 21extern ARRAY(expected_minf, uint, 16, 4); 22extern ARRAY(expected_inf2, uint, 16, 4); 23extern ARRAY(expected_mzero, uint, 16, 4); 24#endif 25extern ARRAY(expected_float, uint, 32, 2); 26extern ARRAY(expected_q_float, uint, 32, 4); 27extern ARRAY(expected_uint2, uint, 32, 2); 28extern ARRAY(expected_uint3, uint, 32, 2); 29extern ARRAY(expected_uint4, uint, 32, 2); 30extern ARRAY(expected_nan, uint, 32, 2); 31extern ARRAY(expected_mnan, uint, 32, 2); 32extern ARRAY(expected_nan2, uint, 32, 2); 33extern ARRAY(expected_inf, uint, 32, 2); 34extern ARRAY(expected_minf, uint, 32, 2); 35extern ARRAY(expected_inf2, uint, 32, 2); 36extern ARRAY(expected_mzero, uint, 32, 2); 37extern ARRAY(expected_p8, uint, 8, 8); 38extern ARRAY(expected_q_p8, uint, 8, 16); 39 40#define FNNAME1(NAME) exec_ ## NAME 41#define FNNAME(NAME) FNNAME1(NAME) 42 43void FNNAME (INSN_NAME) (void) 44{ 45 /* Basic test: y=vcomp(x1,x2), then store the result. */ 46#define TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N) \ 47 VECT_VAR(vector_res, T3, W, N) = \ 48 INSN##Q##_##T2##W(VECT_VAR(vector, T1, W, N), \ 49 VECT_VAR(vector2, T1, W, N)); \ 50 vst1##Q##_u##W(VECT_VAR(result, T3, W, N), VECT_VAR(vector_res, T3, W, N)) 51 52#define TEST_VCOMP(INSN, Q, T1, T2, T3, W, N) \ 53 TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N) 54 55 /* No need for 64 bits elements. */ 56 DECL_VARIABLE(vector, int, 8, 8); 57 DECL_VARIABLE(vector, int, 16, 4); 58 DECL_VARIABLE(vector, int, 32, 2); 59 DECL_VARIABLE(vector, uint, 8, 8); 60 DECL_VARIABLE(vector, uint, 16, 4); 61 DECL_VARIABLE(vector, uint, 32, 2); 62#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 63 DECL_VARIABLE (vector, float, 16, 4); 64#endif 65 DECL_VARIABLE(vector, float, 32, 2); 66 DECL_VARIABLE(vector, int, 8, 16); 67 DECL_VARIABLE(vector, int, 16, 8); 68 DECL_VARIABLE(vector, int, 32, 4); 69 DECL_VARIABLE(vector, uint, 8, 16); 70 DECL_VARIABLE(vector, uint, 16, 8); 71 DECL_VARIABLE(vector, uint, 32, 4); 72#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 73 DECL_VARIABLE (vector, float, 16, 8); 74#endif 75 DECL_VARIABLE(vector, float, 32, 4); 76 77 DECL_VARIABLE(vector2, int, 8, 8); 78 DECL_VARIABLE(vector2, int, 16, 4); 79 DECL_VARIABLE(vector2, int, 32, 2); 80 DECL_VARIABLE(vector2, uint, 8, 8); 81 DECL_VARIABLE(vector2, uint, 16, 4); 82 DECL_VARIABLE(vector2, uint, 32, 2); 83#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 84 DECL_VARIABLE (vector2, float, 16, 4); 85#endif 86 DECL_VARIABLE(vector2, float, 32, 2); 87 DECL_VARIABLE(vector2, int, 8, 16); 88 DECL_VARIABLE(vector2, int, 16, 8); 89 DECL_VARIABLE(vector2, int, 32, 4); 90 DECL_VARIABLE(vector2, uint, 8, 16); 91 DECL_VARIABLE(vector2, uint, 16, 8); 92 DECL_VARIABLE(vector2, uint, 32, 4); 93#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 94 DECL_VARIABLE (vector2, float, 16, 8); 95#endif 96 DECL_VARIABLE(vector2, float, 32, 4); 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 DECL_VARIABLE(vector_res, uint, 8, 16); 102 DECL_VARIABLE(vector_res, uint, 16, 8); 103 DECL_VARIABLE(vector_res, uint, 32, 4); 104 105 clean_results (); 106 107 /* There is no 64 bits variant, don't use the generic initializer. */ 108 VLOAD(vector, buffer, , int, s, 8, 8); 109 VLOAD(vector, buffer, , int, s, 16, 4); 110 VLOAD(vector, buffer, , int, s, 32, 2); 111 VLOAD(vector, buffer, , uint, u, 8, 8); 112 VLOAD(vector, buffer, , uint, u, 16, 4); 113 VLOAD(vector, buffer, , uint, u, 32, 2); 114#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 115 VLOAD (vector, buffer, , float, f, 16, 4); 116#endif 117 VLOAD(vector, buffer, , float, f, 32, 2); 118 119 VLOAD(vector, buffer, q, int, s, 8, 16); 120 VLOAD(vector, buffer, q, int, s, 16, 8); 121 VLOAD(vector, buffer, q, int, s, 32, 4); 122 VLOAD(vector, buffer, q, uint, u, 8, 16); 123 VLOAD(vector, buffer, q, uint, u, 16, 8); 124 VLOAD(vector, buffer, q, uint, u, 32, 4); 125#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 126 VLOAD (vector, buffer, q, float, f, 16, 8); 127#endif 128 VLOAD(vector, buffer, q, float, f, 32, 4); 129 130 /* Choose init value arbitrarily, will be used for vector 131 comparison. */ 132 VDUP(vector2, , int, s, 8, 8, -10); 133 VDUP(vector2, , int, s, 16, 4, -14); 134 VDUP(vector2, , int, s, 32, 2, -16); 135 VDUP(vector2, , uint, u, 8, 8, 0xF3); 136 VDUP(vector2, , uint, u, 16, 4, 0xFFF2); 137 VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF1); 138#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 139 VDUP (vector2, , float, f, 16, 4, -15.0f); 140#endif 141 VDUP(vector2, , float, f, 32, 2, -15.0f); 142 143 VDUP(vector2, q, int, s, 8, 16, -4); 144 VDUP(vector2, q, int, s, 16, 8, -10); 145 VDUP(vector2, q, int, s, 32, 4, -14); 146 VDUP(vector2, q, uint, u, 8, 16, 0xF4); 147 VDUP(vector2, q, uint, u, 16, 8, 0xFFF6); 148 VDUP(vector2, q, uint, u, 32, 4, 0xFFFFFFF2); 149#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 150 VDUP (vector2, q, float, f, 16, 8, -14.0f); 151#endif 152 VDUP(vector2, q, float, f, 32, 4, -14.0f); 153 154 /* The comparison operators produce only unsigned results, which 155 means that our tests with uint* inputs write their results in the 156 same vectors as the int* variants. As a consequence, we have to 157 execute and test the int* first, then the uint* ones. 158 Same thing for float and poly8. 159 */ 160 161 /* Apply operator named INSN_NAME. */ 162 TEST_VCOMP(INSN_NAME, , int, s, uint, 8, 8); 163 TEST_VCOMP(INSN_NAME, , int, s, uint, 16, 4); 164 TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2); 165 TEST_VCOMP(INSN_NAME, q, int, s, uint, 8, 16); 166 TEST_VCOMP(INSN_NAME, q, int, s, uint, 16, 8); 167 TEST_VCOMP(INSN_NAME, q, int, s, uint, 32, 4); 168 169 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected, ""); 170 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected, ""); 171 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected, ""); 172 CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected, ""); 173 CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected, ""); 174 CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected, ""); 175 176 /* Now the uint* variants. */ 177 TEST_VCOMP(INSN_NAME, , uint, u, uint, 8, 8); 178 TEST_VCOMP(INSN_NAME, , uint, u, uint, 16, 4); 179 TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2); 180 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 8, 16); 181 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 16, 8); 182 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 32, 4); 183 184 CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_uint, ""); 185 CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_uint, ""); 186 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint, ""); 187 CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_q_uint, ""); 188 CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_q_uint, ""); 189 CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_q_uint, ""); 190 191 /* The float variants. */ 192#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 193 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 194 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_float, ""); 195#endif 196 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 197 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_float, ""); 198 199#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 200 TEST_VCOMP (INSN_NAME, q, float, f, uint, 16, 8); 201 CHECK (TEST_MSG, uint, 16, 8, PRIx16, expected_q_float, ""); 202#endif 203 TEST_VCOMP(INSN_NAME, q, float, f, uint, 32, 4); 204 CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_q_float, ""); 205 206 /* Some "special" input values to test some corner cases. */ 207 /* Extra tests to have 100% coverage on all the variants. */ 208 VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF0); 209 TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2); 210 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint2, "uint 0xfffffff0"); 211 212 VDUP(vector2, , int, s, 32, 2, -15); 213 TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2); 214 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint3, "int -15"); 215 216 VDUP(vector2, , float, f, 32, 2, -16.0f); 217 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 218 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint4, "float -16.0f"); 219 220 221 /* Extra FP tests with special values (NaN, ....). */ 222#if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) 223 VDUP (vector, , float, f, 16, 4, 1.0); 224 VDUP (vector2, , float, f, 16, 4, NAN); 225 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 226 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_nan, "FP special (NaN)"); 227 228 VDUP (vector, , float, f, 16, 4, 1.0); 229 VDUP (vector2, , float, f, 16, 4, -NAN); 230 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 231 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_mnan, " FP special (-NaN)"); 232 233 VDUP (vector, , float, f, 16, 4, NAN); 234 VDUP (vector2, , float, f, 16, 4, 1.0); 235 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 236 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_nan2, " FP special (NaN)"); 237 238 VDUP (vector, , float, f, 16, 4, 1.0); 239 VDUP (vector2, , float, f, 16, 4, HUGE_VALF); 240 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 241 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_inf, " FP special (inf)"); 242 243 VDUP (vector, , float, f, 16, 4, 1.0); 244 VDUP (vector2, , float, f, 16, 4, -HUGE_VALF); 245 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 246 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_minf, " FP special (-inf)"); 247 248 VDUP (vector, , float, f, 16, 4, HUGE_VALF); 249 VDUP (vector2, , float, f, 16, 4, 1.0); 250 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 251 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_inf2, " FP special (inf)"); 252 253 VDUP (vector, , float, f, 16, 4, -0.0); 254 VDUP (vector2, , float, f, 16, 4, 0.0); 255 TEST_VCOMP (INSN_NAME, , float, f, uint, 16, 4); 256 CHECK (TEST_MSG, uint, 16, 4, PRIx16, expected_mzero, " FP special (-0.0)"); 257#endif 258 259 VDUP(vector, , float, f, 32, 2, 1.0); 260 VDUP(vector2, , float, f, 32, 2, NAN); 261 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 262 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_nan, "FP special (NaN)"); 263 264 VDUP(vector, , float, f, 32, 2, 1.0); 265 VDUP(vector2, , float, f, 32, 2, -NAN); 266 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 267 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_mnan, " FP special (-NaN)"); 268 269 VDUP(vector, , float, f, 32, 2, NAN); 270 VDUP(vector2, , float, f, 32, 2, 1.0); 271 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 272 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_nan2, " FP special (NaN)"); 273 274 VDUP(vector, , float, f, 32, 2, 1.0); 275 VDUP(vector2, , float, f, 32, 2, HUGE_VALF); 276 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 277 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_inf, " FP special (inf)"); 278 279 VDUP(vector, , float, f, 32, 2, 1.0); 280 VDUP(vector2, , float, f, 32, 2, -HUGE_VALF); 281 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 282 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_minf, " FP special (-inf)"); 283 284 VDUP(vector, , float, f, 32, 2, HUGE_VALF); 285 VDUP(vector2, , float, f, 32, 2, 1.0); 286 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 287 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_inf2, " FP special (inf)"); 288 289 VDUP(vector, , float, f, 32, 2, -0.0); 290 VDUP(vector2, , float, f, 32, 2, 0.0); 291 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 292 CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_mzero, " FP special (-0.0)"); 293 294#ifdef EXTRA_TESTS 295 EXTRA_TESTS(); 296#endif 297} 298 299int main (void) 300{ 301 FNNAME (INSN_NAME) (); 302 303 return 0; 304} 305