Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021 Arm Limited. |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 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 |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell 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 all |
| 14 | * 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 THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include <cmath> |
| 25 | #include <limits> |
| 26 | |
| 27 | #if defined(__ARM_FEATURE_SVE) |
| 28 | |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 29 | #ifndef M_PI |
| 30 | #define M_PI (3.14159265358979323846) |
| 31 | #endif // M_PI |
| 32 | |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 33 | namespace arm_compute |
| 34 | { |
| 35 | inline svfloat32_t svtaylor_poly_f32_z(svbool_t pg, svfloat32_t x, const std::array<svfloat32_t, 8> &coeffs) |
| 36 | { |
| 37 | const auto A = svmla_f32_z(pg, coeffs[0], coeffs[4], x); |
| 38 | const auto B = svmla_f32_z(pg, coeffs[2], coeffs[6], x); |
| 39 | const auto C = svmla_f32_z(pg, coeffs[1], coeffs[5], x); |
| 40 | const auto D = svmla_f32_z(pg, coeffs[3], coeffs[7], x); |
| 41 | const auto x2 = svmul_f32_z(pg, x, x); |
| 42 | const auto x4 = svmul_f32_z(pg, x2, x2); |
| 43 | const auto res = svmla_f32_z(pg, svmla_f32_z(pg, A, B, x2), svmla_f32_z(pg, C, D, x2), x4); |
| 44 | return res; |
| 45 | } |
| 46 | |
| 47 | inline svfloat16_t svtaylor_poly_f16_z(svbool_t pg, svfloat16_t x, const std::array<svfloat16_t, 8> &coeffs) |
| 48 | { |
| 49 | const auto A = svmla_f16_z(pg, coeffs[0], coeffs[4], x); |
| 50 | const auto B = svmla_f16_z(pg, coeffs[2], coeffs[6], x); |
| 51 | const auto C = svmla_f16_z(pg, coeffs[1], coeffs[5], x); |
| 52 | const auto D = svmla_f16_z(pg, coeffs[3], coeffs[7], x); |
| 53 | const auto x2 = svmul_f16_z(pg, x, x); |
| 54 | const auto x4 = svmul_f16_z(pg, x2, x2); |
| 55 | const auto res = svmla_f16_z(pg, svmla_f16_z(pg, A, B, x2), svmla_f16_z(pg, C, D, x2), x4); |
| 56 | return res; |
| 57 | } |
| 58 | |
| 59 | inline svfloat16_t svinv_f16_z(svbool_t pg, svfloat16_t x) |
| 60 | { |
| 61 | auto recip = svrecpe_f16(x); |
| 62 | recip = svmul_f16_z(pg, svrecps_f16(x, recip), recip); |
| 63 | recip = svmul_f16_z(pg, svrecps_f16(x, recip), recip); |
| 64 | return recip; |
| 65 | } |
| 66 | |
| 67 | inline svfloat32_t svinv_f32_z(svbool_t pg, svfloat32_t x) |
| 68 | { |
| 69 | auto recip = svrecpe_f32(x); |
| 70 | recip = svmul_f32_z(pg, svrecps_f32(x, recip), recip); |
| 71 | recip = svmul_f32_z(pg, svrecps_f32(x, recip), recip); |
| 72 | return recip; |
| 73 | } |
| 74 | |
| 75 | inline svfloat32_t svexp_f32_z(svbool_t pg, svfloat32_t x) |
| 76 | { |
| 77 | const auto CONST_LN2 = svdup_n_f32(0.6931471805f); // ln(2) |
| 78 | const auto CONST_INV_LN2 = svdup_n_f32(1.4426950408f); // 1/ln(2) |
| 79 | const auto CONST_INF = svdup_n_f32(std::numeric_limits<float>::infinity()); |
| 80 | const auto CONST_MAX_INPUT = svdup_n_f32(88.7f); |
| 81 | const auto CONST_0 = svdup_n_f32(0.f); |
| 82 | const auto CONST_NEGATIVE_126 = svdup_n_s32(-126); |
| 83 | |
| 84 | /** Exponent polynomial coefficients */ |
| 85 | const std::array<svfloat32_t, 8> exp_tab = |
| 86 | { |
| 87 | { |
| 88 | svdup_n_f32(1.f), |
| 89 | svdup_n_f32(0.0416598916054f), |
| 90 | svdup_n_f32(0.500000596046f), |
| 91 | svdup_n_f32(0.0014122662833f), |
| 92 | svdup_n_f32(1.00000011921f), |
| 93 | svdup_n_f32(0.00833693705499f), |
| 94 | svdup_n_f32(0.166665703058f), |
| 95 | svdup_n_f32(0.000195780929062f), |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | // Perform range reduction [-log(2),log(2)] |
| 100 | auto m = svcvt_s32_f32_z(pg, svmul_f32_z(pg, x, CONST_INV_LN2)); |
| 101 | auto val = svmls_f32_z(pg, x, svcvt_f32_s32_z(pg, m), CONST_LN2); |
| 102 | |
| 103 | // Polynomial Approximation |
| 104 | auto poly = svtaylor_poly_f32_z(pg, val, exp_tab); |
| 105 | |
| 106 | // Reconstruct |
| 107 | poly = svreinterpret_f32_s32(svqadd_s32(svreinterpret_s32_f32(poly), svlsl_n_s32_z(pg, m, 23))); |
| 108 | |
| 109 | // Handle underflow |
| 110 | svbool_t ltpg = svcmplt_s32(pg, m, CONST_NEGATIVE_126); |
| 111 | poly = svsel_f32(ltpg, CONST_0, poly); |
| 112 | |
| 113 | // Handle overflow |
| 114 | svbool_t gtpg = svcmpgt_f32(pg, x, CONST_MAX_INPUT); |
| 115 | poly = svsel_f32(gtpg, CONST_INF, poly); |
| 116 | |
| 117 | return poly; |
| 118 | } |
| 119 | |
| 120 | inline svfloat16_t svexp_f16_z(svbool_t pg, svfloat16_t x) |
| 121 | { |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 122 | auto bottom = svcvt_f32_z(pg, x); |
| 123 | #if defined(__ARM_FEATURE_SVE2) |
| 124 | auto top = svcvtlt_f32_x(pg, x); |
| 125 | auto pg_top = pg; |
| 126 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 127 | auto pg_top = svptrue_b16(); |
| 128 | auto top = svcvt_f32_z(pg_top, svreinterpret_f16(svrevh_z(svptrue_b16(), svreinterpret_u32(x)))); |
| 129 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 130 | |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 131 | bottom = svexp_f32_z(pg, bottom); |
| 132 | top = svexp_f32_z(pg_top, top); |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 133 | |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 134 | #if defined(__ARM_FEATURE_SVE2) |
| 135 | return svcvtnt_f16_m(svcvt_f16_z(pg, bottom), pg_top, top); |
| 136 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 137 | return svtrn1(svcvt_f16_z(pg, bottom), svcvt_f16_z(pg_top, top)); |
| 138 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | inline svfloat32_t svtanh_f32_z(svbool_t pg, svfloat32_t val) |
| 142 | { |
| 143 | const svfloat32_t CONST_1 = svdup_n_f32(1.f); |
| 144 | const svfloat32_t CONST_2 = svdup_n_f32(2.f); |
| 145 | const svfloat32_t CONST_MIN_TANH = svdup_n_f32(-10.f); |
| 146 | const svfloat32_t CONST_MAX_TANH = svdup_n_f32(10.f); |
| 147 | |
| 148 | svfloat32_t x = svmin_f32_z(pg, svmax_f32_z(pg, val, CONST_MIN_TANH), CONST_MAX_TANH); |
| 149 | svfloat32_t exp2x = svexp_f32_z(pg, svmul_f32_z(pg, CONST_2, x)); |
| 150 | svfloat32_t num = svsub_f32_z(pg, exp2x, CONST_1); |
| 151 | svfloat32_t den = svadd_f32_z(pg, exp2x, CONST_1); |
| 152 | svfloat32_t tanh = svdiv_f32_z(pg, num, den); |
| 153 | return tanh; |
| 154 | } |
| 155 | |
| 156 | inline svfloat16_t svtanh_f16_z(svbool_t pg, svfloat16_t val) |
| 157 | { |
| 158 | const svfloat16_t CONST_1 = svdup_n_f16(1.f); |
| 159 | const svfloat16_t CONST_2 = svdup_n_f16(2.f); |
| 160 | const svfloat16_t CONST_MIN_TANH = svdup_n_f16(-10.f); |
| 161 | const svfloat16_t CONST_MAX_TANH = svdup_n_f16(10.f); |
| 162 | |
| 163 | const svfloat16_t x = svmin_f16_z(pg, svmax_f16_z(pg, val, CONST_MIN_TANH), CONST_MAX_TANH); |
| 164 | const svfloat16_t exp2x = svexp_f16_z(pg, svmul_f16_z(pg, CONST_2, x)); |
| 165 | const svfloat16_t num = svsub_f16_z(pg, exp2x, CONST_1); |
| 166 | const svfloat16_t den = svadd_f16_z(pg, exp2x, CONST_1); |
| 167 | const svfloat16_t tanh = svdiv_f16_z(pg, num, den); |
| 168 | return tanh; |
| 169 | } |
| 170 | |
| 171 | inline svfloat32_t svlog_f32_z(svbool_t pg, svfloat32_t x) |
| 172 | { |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 173 | /** Logarithm polynomial coefficients */ |
| 174 | const std::array<svfloat32_t, 8> log_tab = |
| 175 | { |
| 176 | { |
| 177 | svdup_n_f32(-2.29561495781f), |
| 178 | svdup_n_f32(-2.47071170807f), |
| 179 | svdup_n_f32(-5.68692588806f), |
| 180 | svdup_n_f32(-0.165253549814f), |
| 181 | svdup_n_f32(5.17591238022f), |
| 182 | svdup_n_f32(0.844007015228f), |
| 183 | svdup_n_f32(4.58445882797f), |
| 184 | svdup_n_f32(0.0141278216615f), |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | const auto CONST_127 = svdup_n_s32(127); // 127 |
| 189 | const auto CONST_LN2 = svdup_n_f32(0.6931471805f); // ln(2) |
| 190 | |
| 191 | // Extract exponent |
| 192 | auto m = svsub_s32_z(pg, svasr_n_s32_z(pg, svreinterpret_s32_f32(x), 23), CONST_127); |
| 193 | auto val = svreinterpret_f32_s32(svsub_s32_z(pg, svreinterpret_s32_f32(x), svlsl_n_s32_z(pg, m, 23))); |
| 194 | |
| 195 | // Polynomial Approximation |
| 196 | auto poly = svtaylor_poly_f32_z(pg, val, log_tab); |
| 197 | |
| 198 | // Reconstruct |
| 199 | poly = svmla_f32_z(pg, poly, svcvt_f32_s32_z(pg, m), CONST_LN2); |
| 200 | |
| 201 | return poly; |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | inline svfloat16_t svlog_f16_z(svbool_t pg, svfloat16_t x) |
| 205 | { |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 206 | auto bottom = svcvt_f32_z(pg, x); |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 207 | #if defined(__ARM_FEATURE_SVE2) |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 208 | auto top = svcvtlt_f32_x(pg, x); |
| 209 | auto pg_top = pg; |
| 210 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 211 | auto pg_top = svptrue_b16(); |
| 212 | auto top = svcvt_f32_z(pg_top, svreinterpret_f16(svrevh_z(svptrue_b16(), svreinterpret_u32(x)))); |
| 213 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 214 | |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 215 | bottom = svlog_f32_z(pg, bottom); |
| 216 | top = svlog_f32_z(pg_top, top); |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 217 | |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 218 | #if defined(__ARM_FEATURE_SVE2) |
| 219 | return svcvtnt_f16_m(svcvt_f16_z(pg, bottom), pg_top, top); |
| 220 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 221 | return svtrn1(svcvt_f16_z(pg, bottom), svcvt_f16_z(pg_top, top)); |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 222 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
| 223 | } |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 224 | |
| 225 | inline svfloat32_t svsin_f32_z(svbool_t pg, svfloat32_t val) |
| 226 | { |
| 227 | using ScalarType = float; |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 228 | using IntType = uint32_t; |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 229 | |
| 230 | constexpr float te_sin_coeff2 = 0.166666666666f; // 1/(2*3) |
| 231 | constexpr float te_sin_coeff3 = 0.05f; // 1/(4*5) |
| 232 | constexpr float te_sin_coeff4 = 0.023809523810f; // 1/(6*7) |
| 233 | constexpr float te_sin_coeff5 = 0.013888888889f; // 1/(8*9) |
| 234 | |
| 235 | const auto pi_v = wrapper::svdup_n(ScalarType(M_PI)); |
| 236 | const auto pio2_v = wrapper::svdup_n(ScalarType(M_PI / 2)); |
| 237 | const auto ipi_v = wrapper::svdup_n(ScalarType(1 / M_PI)); |
| 238 | |
| 239 | //Find positive or negative |
| 240 | const auto c_v = svabs_z(pg, wrapper::svcvt_z<int32_t>(pg, svmul_z(pg, val, ipi_v))); |
| 241 | const auto sign_v = svcmple(pg, val, wrapper::svdup_n(ScalarType(0))); |
| 242 | const auto odd_v = svcmpne(pg, svand_z(pg, wrapper::svreinterpret<IntType>(c_v), wrapper::svdup_n(IntType(1))), wrapper::svdup_n(IntType(0))); |
| 243 | |
| 244 | auto neg_v = sveor_z(pg, odd_v, sign_v); |
| 245 | |
| 246 | //Modulus a - (n * int(a*(1/n))) |
| 247 | auto ma = svsub_z(pg, svabs_z(pg, val), svmul_z(pg, pi_v, wrapper::svcvt_z<ScalarType>(pg, c_v))); |
| 248 | const auto reb_v = svcmpge(pg, ma, pio2_v); |
| 249 | |
| 250 | //Rebase a between 0 and pi/2 |
| 251 | ma = svsel(reb_v, svsub_z(pg, pi_v, ma), ma); |
| 252 | |
| 253 | //Taylor series |
| 254 | const auto ma2 = svmul_z(pg, ma, ma); |
| 255 | |
| 256 | //2nd elem: x^3 / 3! |
| 257 | auto elem = svmul_z(pg, svmul_z(pg, ma, ma2), wrapper::svdup_n(ScalarType(te_sin_coeff2))); |
| 258 | auto res = svsub_z(pg, ma, elem); |
| 259 | |
| 260 | //3rd elem: x^5 / 5! |
| 261 | elem = svmul_z(pg, svmul_z(pg, elem, ma2), wrapper::svdup_n(ScalarType(te_sin_coeff3))); |
| 262 | res = svadd_z(pg, res, elem); |
| 263 | |
| 264 | //4th elem: x^7 / 7!float32x2_t vsin_f32(float32x2_t val) |
| 265 | elem = svmul_z(pg, svmul_z(pg, elem, ma2), wrapper::svdup_n(ScalarType(te_sin_coeff4))); |
| 266 | res = svsub_z(pg, res, elem); |
| 267 | |
| 268 | //5th elem: x^9 / 9! |
| 269 | elem = svmul_z(pg, svmul_z(pg, elem, ma2), wrapper::svdup_n(ScalarType(te_sin_coeff5))); |
| 270 | res = svadd_z(pg, res, elem); |
| 271 | |
| 272 | //Change of sign |
| 273 | res = svneg_m(res, neg_v, res); |
| 274 | return res; |
| 275 | } |
| 276 | |
| 277 | inline svfloat16_t svsin_f16_z(svbool_t pg, svfloat16_t val) |
| 278 | { |
| 279 | auto bottom = svcvt_f32_z(pg, val); |
| 280 | #if defined(__ARM_FEATURE_SVE2) |
| 281 | auto top = svcvtlt_f32_x(pg, val); |
| 282 | auto pg_top = pg; |
| 283 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 284 | auto pg_top = svptrue_b16(); |
| 285 | auto top = svcvt_f32_z(pg_top, svreinterpret_f16(svrevh_z(svptrue_b16(), svreinterpret_u32(val)))); |
| 286 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
| 287 | |
| 288 | bottom = svsin_f32_z(pg, bottom); |
| 289 | top = svsin_f32_z(pg_top, top); |
| 290 | |
| 291 | #if defined(__ARM_FEATURE_SVE2) |
| 292 | return svcvtnt_f16_m(svcvt_f16_z(pg, bottom), pg_top, top); |
| 293 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 294 | return svtrn1(svcvt_f16_z(pg, bottom), svcvt_f16_z(pg_top, top)); |
| 295 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
| 296 | } |
| 297 | |
| 298 | inline svfloat32_t svpow_f32_z(svbool_t pg, svfloat32_t a, svfloat32_t b) |
| 299 | { |
| 300 | return svexp_f32_z(pg, svmul_z(pg, b, svlog_f32_z(pg, a))); |
| 301 | } |
| 302 | |
| 303 | inline svfloat16_t svpow_f16_z(svbool_t pg, svfloat16_t a, svfloat16_t b) |
| 304 | { |
| 305 | auto a_bottom = svcvt_f32_z(pg, a); |
| 306 | auto b_bottom = svcvt_f32_z(pg, b); |
| 307 | |
| 308 | #if defined(__ARM_FEATURE_SVE2) |
| 309 | auto pg_top = pg; |
| 310 | auto a_top = svcvtlt_f32_x(pg, a); |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 311 | auto b_top = svcvtlt_f32_x(pg, b); |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 312 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 313 | auto pg_top = svptrue_b16(); |
| 314 | auto a_top = svcvt_f32_z(pg_top, svreinterpret_f16(svrevh_z(svptrue_b16(), svreinterpret_u32(a)))); |
| 315 | auto b_top = svcvt_f32_z(pg_top, svreinterpret_f16(svrevh_z(svptrue_b16(), svreinterpret_u32(b)))); |
| 316 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
| 317 | |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 318 | auto res_bottom = svpow_f32_z(pg, a_bottom, b_bottom); |
| 319 | auto res_top = svpow_f32_z(pg_top, a_top, b_top); |
Sang-Hoon Park | 0870db4 | 2020-12-08 18:42:19 +0000 | [diff] [blame] | 320 | |
| 321 | #if defined(__ARM_FEATURE_SVE2) |
| 322 | return svcvtnt_f16_m(svcvt_f16_z(pg, res_bottom), pg_top, res_top); |
| 323 | #else /* defined(__ARM_FEATURE_SVE2) */ |
| 324 | return svtrn1(svcvt_f16_z(pg, res_bottom), svcvt_f16_z(pg_top, res_top)); |
| 325 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
| 326 | } |
| 327 | |
Sang-Hoon Park | dcf3c7e | 2021-03-04 17:03:46 +0000 | [diff] [blame^] | 328 | template <> |
| 329 | inline svuint8_t convert_float_to_int<svuint8_t>(const svfloat32_t &in_0, const svfloat32_t &in_1, const svfloat32_t &in_2, const svfloat32_t &in_3) |
| 330 | { |
| 331 | svuint8_t out; |
| 332 | const auto all_true_pg = svptrue_b32(); |
| 333 | auto tmp_0 = svcvt_u32_f32_z(all_true_pg, in_0); |
| 334 | auto tmp_1 = svcvt_u32_f32_z(all_true_pg, in_1); |
| 335 | auto tmp_2 = svcvt_u32_f32_z(all_true_pg, in_2); |
| 336 | auto tmp_3 = svcvt_u32_f32_z(all_true_pg, in_3); |
| 337 | |
| 338 | auto tmp_16_0 = svqxtnt_u32(svqxtnb_u32(tmp_0), tmp_1); |
| 339 | auto tmp_16_1 = svqxtnt_u32(svqxtnb_u32(tmp_2), tmp_3); |
| 340 | |
| 341 | auto tmp_16_uzp_0 = svuzp1(tmp_16_0, tmp_16_0); |
| 342 | auto tmp_16_uzp_1 = svuzp2(tmp_16_0, tmp_16_0); |
| 343 | auto tmp_16_uzp_2 = svuzp1(tmp_16_1, tmp_16_1); |
| 344 | auto tmp_16_uzp_3 = svuzp2(tmp_16_1, tmp_16_1); |
| 345 | |
| 346 | auto pg = svwhilelt_b16_s32(0, svcnth() / 2); |
| 347 | |
| 348 | tmp_16_0 = svsplice(pg, tmp_16_uzp_0, tmp_16_uzp_1); |
| 349 | tmp_16_1 = svsplice(pg, tmp_16_uzp_2, tmp_16_uzp_3); |
| 350 | |
| 351 | out = svqxtnt_u16(svqxtnb_u16(tmp_16_0), tmp_16_1); |
| 352 | |
| 353 | auto out_uzp_0 = svuzp1(out, out); |
| 354 | auto out_uzp_1 = svuzp2(out, out); |
| 355 | |
| 356 | pg = svwhilelt_b8_s32(0, svcntb() / 2); |
| 357 | out = svsplice(pg, out_uzp_0, out_uzp_1); |
| 358 | |
| 359 | return out; |
| 360 | } |
| 361 | |
| 362 | template <> |
| 363 | inline svint8_t convert_float_to_int<svint8_t>(const svfloat32_t &in_0, const svfloat32_t &in_1, const svfloat32_t &in_2, const svfloat32_t &in_3) |
| 364 | { |
| 365 | svint8_t out; |
| 366 | const auto all_true_pg = svptrue_b32(); |
| 367 | auto tmp_0 = svcvt_s32_f32_z(all_true_pg, in_0); |
| 368 | auto tmp_1 = svcvt_s32_f32_z(all_true_pg, in_1); |
| 369 | auto tmp_2 = svcvt_s32_f32_z(all_true_pg, in_2); |
| 370 | auto tmp_3 = svcvt_s32_f32_z(all_true_pg, in_3); |
| 371 | |
| 372 | auto tmp_16_0 = svqxtnt_s32(svqxtnb_s32(tmp_0), tmp_1); |
| 373 | auto tmp_16_1 = svqxtnt_s32(svqxtnb_s32(tmp_2), tmp_3); |
| 374 | |
| 375 | auto tmp_16_uzp_0 = svuzp1(tmp_16_0, tmp_16_0); |
| 376 | auto tmp_16_uzp_1 = svuzp2(tmp_16_0, tmp_16_0); |
| 377 | auto tmp_16_uzp_2 = svuzp1(tmp_16_1, tmp_16_1); |
| 378 | auto tmp_16_uzp_3 = svuzp2(tmp_16_1, tmp_16_1); |
| 379 | |
| 380 | auto pg = svwhilelt_b16_s32(0, svcnth() / 2); |
| 381 | |
| 382 | tmp_16_0 = svsplice(pg, tmp_16_uzp_0, tmp_16_uzp_1); |
| 383 | tmp_16_1 = svsplice(pg, tmp_16_uzp_2, tmp_16_uzp_3); |
| 384 | |
| 385 | out = svqxtnt_s16(svqxtnb_s16(tmp_16_0), tmp_16_1); |
| 386 | |
| 387 | auto out_uzp_0 = svuzp1(out, out); |
| 388 | auto out_uzp_1 = svuzp2(out, out); |
| 389 | |
| 390 | pg = svwhilelt_b8_s32(0, svcntb() / 2); |
| 391 | out = svsplice(pg, out_uzp_0, out_uzp_1); |
| 392 | |
| 393 | return out; |
| 394 | } |
| 395 | |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 396 | } // namespace arm_compute |
| 397 | #endif /* defined(__ARM_FEATURE_SVE) */ |