Marat Dukhan | 93d1ba1 | 2020-06-26 12:33:35 -0700 | [diff] [blame] | 1 | // Auto-generated file. Do not edit! |
| 2 | // Template: src/f32-vbinary/vop-wasmsimd.c.in |
| 3 | // Generator: tools/xngen |
| 4 | // |
| 5 | // Copyright 2020 Google LLC |
| 6 | // |
| 7 | // This source code is licensed under the BSD-style license found in the |
| 8 | // LICENSE file in the root directory of this source tree. |
| 9 | |
| 10 | #include <assert.h> |
| 11 | |
| 12 | #include <wasm_simd128.h> |
| 13 | |
| 14 | #include <xnnpack/common.h> |
| 15 | #include <xnnpack/vbinary.h> |
| 16 | |
| 17 | |
| 18 | void xnn_f32_vdiv_minmax_ukernel__wasmsimd_x86_x8( |
| 19 | size_t n, |
| 20 | const float* a, |
| 21 | const float* b, |
| 22 | float* y, |
| 23 | const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN |
| 24 | { |
| 25 | assert(n != 0); |
| 26 | assert(n % sizeof(float) == 0); |
Frank Barchard | 0822dde | 2020-07-04 12:47:24 -0700 | [diff] [blame] | 27 | assert(a != NULL); |
| 28 | assert(b != NULL); |
| 29 | assert(y != NULL); |
Marat Dukhan | 93d1ba1 | 2020-06-26 12:33:35 -0700 | [diff] [blame] | 30 | |
Marat Dukhan | ee029b2 | 2021-06-30 12:47:02 -0700 | [diff] [blame] | 31 | const v128_t vy_min = wasm_v128_load32_splat(¶ms->scalar.min); |
| 32 | const v128_t vy_max = wasm_v128_load32_splat(¶ms->scalar.max); |
Marat Dukhan | 93d1ba1 | 2020-06-26 12:33:35 -0700 | [diff] [blame] | 33 | |
| 34 | for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) { |
| 35 | const v128_t va0123 = wasm_v128_load(a); |
| 36 | const v128_t va4567 = wasm_v128_load(a + 4); |
| 37 | a += 8; |
| 38 | |
| 39 | const v128_t vb0123 = wasm_v128_load(b); |
| 40 | const v128_t vb4567 = wasm_v128_load(b + 4); |
| 41 | b += 8; |
| 42 | |
| 43 | v128_t vy0123 = wasm_f32x4_div(va0123, vb0123); |
| 44 | v128_t vy4567 = wasm_f32x4_div(va4567, vb4567); |
| 45 | |
| 46 | |
| 47 | const v128_t vltmask0123 = wasm_f32x4_lt(vy0123, vy_min); |
| 48 | const v128_t vltmask4567 = wasm_f32x4_lt(vy4567, vy_min); |
| 49 | |
| 50 | const v128_t vngtmask0123 = wasm_f32x4_le(vy0123, vy_max); |
| 51 | vy0123 = wasm_v128_bitselect(vy_min, vy0123, vltmask0123); |
| 52 | const v128_t vngtmask4567 = wasm_f32x4_le(vy4567, vy_max); |
| 53 | vy4567 = wasm_v128_bitselect(vy_min, vy4567, vltmask4567); |
| 54 | |
| 55 | vy0123 = wasm_v128_bitselect(vy0123, vy_max, vngtmask0123); |
| 56 | vy4567 = wasm_v128_bitselect(vy4567, vy_max, vngtmask4567); |
| 57 | |
| 58 | wasm_v128_store(y, vy0123); |
| 59 | wasm_v128_store(y + 4, vy4567); |
| 60 | y += 8; |
| 61 | } |
| 62 | for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) { |
| 63 | const v128_t va = wasm_v128_load(a); |
| 64 | a += 4; |
| 65 | |
| 66 | const v128_t vb = wasm_v128_load(b); |
| 67 | b += 4; |
| 68 | |
| 69 | v128_t vy = wasm_f32x4_div(va, vb); |
| 70 | |
| 71 | const v128_t vltmask = wasm_f32x4_lt(vy, vy_min); |
| 72 | const v128_t vngtmask = wasm_f32x4_le(vy, vy_max); |
| 73 | vy = wasm_v128_bitselect(vy_min, vy, vltmask); |
| 74 | vy = wasm_v128_bitselect(vy, vy_max, vngtmask); |
| 75 | |
| 76 | wasm_v128_store(y, vy); |
| 77 | y += 4; |
| 78 | } |
| 79 | if XNN_UNLIKELY(n != 0) { |
| 80 | const v128_t va = wasm_v128_load(a); |
| 81 | const v128_t vb = wasm_v128_load(b); |
| 82 | |
| 83 | v128_t vy = wasm_f32x4_div(va, vb); |
| 84 | |
| 85 | const v128_t vltmask = wasm_f32x4_lt(vy, vy_min); |
| 86 | const v128_t vngtmask = wasm_f32x4_le(vy, vy_max); |
| 87 | vy = wasm_v128_bitselect(vy_min, vy, vltmask); |
| 88 | vy = wasm_v128_bitselect(vy, vy_max, vngtmask); |
| 89 | |
| 90 | if (n & (2 * sizeof(float))) { |
| 91 | *((double*) y) = wasm_f64x2_extract_lane(vy, 0); |
| 92 | vy = wasm_v32x4_shuffle(vy, vy, 2, 3, 2, 3); |
| 93 | y += 2; |
| 94 | } |
| 95 | if (n & (1 * sizeof(float))) { |
| 96 | *y = wasm_f32x4_extract_lane(vy, 0); |
| 97 | } |
| 98 | } |
| 99 | } |