1 /* 2 3 Copyright (c) 2009, 2010, 2011, 2013 STMicroelectronics 4 Written by Christophe Lyon 5 6 Permission is hereby granted, free of charge, to any person obtaining a copy 7 of this software and associated documentation files (the "Software"), to deal 8 in the Software without restriction, including without limitation the rights 9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 copies of the Software, and to permit persons to whom the Software is 11 furnished to do so, subject to the following conditions: 12 13 The above copyright notice and this permission notice shall be included in 14 all copies or substantial portions of the Software. 15 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 THE SOFTWARE. 23 24 */ 25 26 #if defined(__arm__) || defined(__aarch64__) 27 #include <arm_neon.h> 28 #else 29 #include "stm-arm-neon.h" 30 #endif 31 32 #include "stm-arm-neon-ref.h" 33 #include <math.h> 34 35 36 #define FNNAME1(NAME) void exec_ ## NAME (void) 37 #define FNNAME(NAME) FNNAME1(NAME) 38 39 FNNAME (INSN_NAME) 40 { 41 int i; 42 43 /* Basic test: y=vcomp(x,x), then store the result. */ 44 #define TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N) \ 45 VECT_VAR(vector_res, T3, W, N) = \ 46 INSN##Q##_##T2##W(VECT_VAR(vector, T1, W, N), \ 47 VECT_VAR(vector2, T1, W, N)); \ 48 vst1##Q##_u##W(VECT_VAR(result, T3, W, N), VECT_VAR(vector_res, T3, W, N)) 49 50 #define TEST_VCOMP(INSN, Q, T1, T2, T3, W, N) \ 51 TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N) 52 53 /* With ARM RVCT, we need to declare variables before any executable 54 statement */ 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 DECL_VARIABLE(vector, float, 32, 2); 63 DECL_VARIABLE(vector, int, 8, 16); 64 DECL_VARIABLE(vector, int, 16, 8); 65 DECL_VARIABLE(vector, int, 32, 4); 66 DECL_VARIABLE(vector, uint, 8, 16); 67 DECL_VARIABLE(vector, uint, 16, 8); 68 DECL_VARIABLE(vector, uint, 32, 4); 69 DECL_VARIABLE(vector, float, 32, 4); 70 71 DECL_VARIABLE(vector2, int, 8, 8); 72 DECL_VARIABLE(vector2, int, 16, 4); 73 DECL_VARIABLE(vector2, int, 32, 2); 74 DECL_VARIABLE(vector2, uint, 8, 8); 75 DECL_VARIABLE(vector2, uint, 16, 4); 76 DECL_VARIABLE(vector2, uint, 32, 2); 77 DECL_VARIABLE(vector2, float, 32, 2); 78 DECL_VARIABLE(vector2, int, 8, 16); 79 DECL_VARIABLE(vector2, int, 16, 8); 80 DECL_VARIABLE(vector2, int, 32, 4); 81 DECL_VARIABLE(vector2, uint, 8, 16); 82 DECL_VARIABLE(vector2, uint, 16, 8); 83 DECL_VARIABLE(vector2, uint, 32, 4); 84 DECL_VARIABLE(vector2, float, 32, 4); 85 86 DECL_VARIABLE(vector_res, uint, 8, 8); 87 DECL_VARIABLE(vector_res, uint, 16, 4); 88 DECL_VARIABLE(vector_res, uint, 32, 2); 89 DECL_VARIABLE(vector_res, uint, 8, 16); 90 DECL_VARIABLE(vector_res, uint, 16, 8); 91 DECL_VARIABLE(vector_res, uint, 32, 4); 92 93 clean_results (); 94 95 /* There is no 64 bits variant, we can't use the generic initializer */ 96 VLOAD(vector, buffer, , int, s, 8, 8); 97 VLOAD(vector, buffer, , int, s, 16, 4); 98 VLOAD(vector, buffer, , int, s, 32, 2); 99 VLOAD(vector, buffer, , uint, u, 8, 8); 100 VLOAD(vector, buffer, , uint, u, 16, 4); 101 VLOAD(vector, buffer, , uint, u, 32, 2); 102 VLOAD(vector, buffer, , float, f, 32, 2); 103 104 VLOAD(vector, buffer, q, int, s, 8, 16); 105 VLOAD(vector, buffer, q, int, s, 16, 8); 106 VLOAD(vector, buffer, q, int, s, 32, 4); 107 VLOAD(vector, buffer, q, uint, u, 8, 16); 108 VLOAD(vector, buffer, q, uint, u, 16, 8); 109 VLOAD(vector, buffer, q, uint, u, 32, 4); 110 VLOAD(vector, buffer, q, float, f, 32, 4); 111 112 /* Choose init value arbitrarily, will be used for vector 113 comparison */ 114 VDUP(vector2, , int, s, 8, 8, -10); 115 VDUP(vector2, , int, s, 16, 4, -14); 116 VDUP(vector2, , int, s, 32, 2, -16); 117 VDUP(vector2, , uint, u, 8, 8, 0xF3); 118 VDUP(vector2, , uint, u, 16, 4, 0xFFF2); 119 VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF1); 120 VDUP(vector2, , float, f, 32, 2, -15.0f); 121 122 VDUP(vector2, q, int, s, 8, 16, -4); 123 VDUP(vector2, q, int, s, 16, 8, -10); 124 VDUP(vector2, q, int, s, 32, 4, -14); 125 VDUP(vector2, q, uint, u, 8, 16, 0xF4); 126 VDUP(vector2, q, uint, u, 16, 8, 0xFFF6); 127 VDUP(vector2, q, uint, u, 32, 4, 0xFFFFFFF2); 128 VDUP(vector2, q, float, f, 32, 4, -14.0f); 129 130 /* The same result buffers are used multiple times, so output them 131 before overwriting them */ 132 fprintf(ref_file, "\n%s output:\n", TEST_MSG); 133 fprintf(gcc_tests_file, "\n%s output:\n", TEST_MSG); 134 TEST_VCOMP(INSN_NAME, , int, s, uint, 8, 8); 135 TEST_VCOMP(INSN_NAME, , int, s, uint, 16, 4); 136 TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2); 137 DUMP(TEST_MSG, uint, 8, 8, PRIx8); 138 DUMP(TEST_MSG, uint, 16, 4, PRIx16); 139 DUMP(TEST_MSG, uint, 32, 2, PRIx32); 140 141 TEST_VCOMP(INSN_NAME, , uint, u, uint, 8, 8); 142 TEST_VCOMP(INSN_NAME, , uint, u, uint, 16, 4); 143 TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2); 144 DUMP(TEST_MSG, uint, 8, 8, PRIx8); 145 DUMP(TEST_MSG, uint, 16, 4, PRIx16); 146 DUMP(TEST_MSG, uint, 32, 2, PRIx32); 147 148 TEST_VCOMP(INSN_NAME, q, int, s, uint, 8, 16); 149 TEST_VCOMP(INSN_NAME, q, int, s, uint, 16, 8); 150 TEST_VCOMP(INSN_NAME, q, int, s, uint, 32, 4); 151 DUMP(TEST_MSG, uint, 8, 16, PRIx8); 152 DUMP(TEST_MSG, uint, 16, 8, PRIx16); 153 DUMP(TEST_MSG, uint, 32, 4, PRIx32); 154 155 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 8, 16); 156 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 16, 8); 157 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 32, 4); 158 DUMP(TEST_MSG, uint, 8, 16, PRIx8); 159 DUMP(TEST_MSG, uint, 16, 8, PRIx16); 160 DUMP(TEST_MSG, uint, 32, 4, PRIx32); 161 162 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 163 DUMP(TEST_MSG, uint, 32, 2, PRIx32); 164 165 TEST_VCOMP(INSN_NAME, q, float, f, uint, 32, 4); 166 DUMP(TEST_MSG, uint, 32, 4, PRIx32); 167 168 /* Extra tests to have 100% coverage on all the variants */ 169 VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF0); 170 TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2); 171 DUMP(TEST_MSG, uint, 32, 2, PRIx32); 172 173 VDUP(vector2, , int, s, 32, 2, -15); 174 TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2); 175 DUMP(TEST_MSG, uint, 32, 2, PRIx32); 176 177 VDUP(vector2, , float, f, 32, 2, -16.0f); 178 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 179 DUMP(TEST_MSG, uint, 32, 2, PRIx32); 180 181 182 /* Extra FP tests with special values (NaN, ....) */ 183 VDUP(vector, , float, f, 32, 2, 1.0); 184 VDUP(vector2, , float, f, 32, 2, NAN); 185 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 186 DUMP(TEST_MSG " FP special (NaN)", uint, 32, 2, PRIx32); 187 188 VDUP(vector, , float, f, 32, 2, 1.0); 189 VDUP(vector2, , float, f, 32, 2, -NAN); 190 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 191 DUMP(TEST_MSG " FP special (-NaN)", uint, 32, 2, PRIx32); 192 193 VDUP(vector, , float, f, 32, 2, NAN); 194 VDUP(vector2, , float, f, 32, 2, 1.0); 195 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 196 DUMP(TEST_MSG " FP special (NaN)", uint, 32, 2, PRIx32); 197 198 VDUP(vector, , float, f, 32, 2, 1.0); 199 VDUP(vector2, , float, f, 32, 2, HUGE_VALF); 200 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 201 DUMP(TEST_MSG " FP special (inf)", uint, 32, 2, PRIx32); 202 203 VDUP(vector, , float, f, 32, 2, 1.0); 204 VDUP(vector2, , float, f, 32, 2, -HUGE_VALF); 205 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 206 DUMP(TEST_MSG " FP special (-inf)", uint, 32, 2, PRIx32); 207 208 VDUP(vector, , float, f, 32, 2, HUGE_VALF); 209 VDUP(vector2, , float, f, 32, 2, 1.0); 210 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 211 DUMP(TEST_MSG " FP special (inf)", uint, 32, 2, PRIx32); 212 213 VDUP(vector, , float, f, 32, 2, -0.0); 214 VDUP(vector2, , float, f, 32, 2, 0.0); 215 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2); 216 DUMP(TEST_MSG " FP special (-0.0)", uint, 32, 2, PRIx32); 217 218 #ifdef EXTRA_TESTS 219 EXTRA_TESTS(); 220 #endif 221 } 222