| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-f32-vcvt/wasmsimd.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2021 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/intrinsics-polyfill.h" |
| 16 |
#include "xnnpack/vcvt.h" |
| 17 |
|
| 18 |
|
| 19 |
void xnn_qu8_f32_vcvt_ukernel__wasmsimd_u8( |
| 20 |
size_t batch, |
| 21 |
const uint8_t* input, |
| 22 |
float* output, |
| 23 |
const struct xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 24 |
{ |
| 25 |
assert(batch != 0); |
| 26 |
assert(batch % sizeof(uint8_t) == 0); |
| 27 |
assert(input != NULL); |
| 28 |
assert(output != NULL); |
| 29 |
|
| 30 |
const v128_t vzero_point = wasm_v128_load16_splat(¶ms->scalar.zero_point); |
| 31 |
const v128_t vscale = wasm_v128_load32_splat(¶ms->scalar.scale); |
| 32 |
XNN_FORCE_REALIZATION(vzero_point); |
| 33 |
XNN_FORCE_REALIZATION(vscale); |
| 34 |
for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) { |
| 35 |
v128_t vx = wasm_u16x8_load8x8(input); |
| 36 |
vx = wasm_i16x8_sub(vx, vzero_point); |
| 37 |
input += 8; |
| 38 |
|
| 39 |
v128_t vy_lo = wasm_i32x4_extend_low_i16x8(vx); |
| 40 |
v128_t vy_hi = wasm_i32x4_extend_high_i16x8(vx); |
| 41 |
|
| 42 |
vy_lo = wasm_f32x4_convert_i32x4(vy_lo); |
| 43 |
vy_hi = wasm_f32x4_convert_i32x4(vy_hi); |
| 44 |
|
| 45 |
vy_lo = wasm_f32x4_mul(vy_lo, vscale); |
| 46 |
vy_hi = wasm_f32x4_mul(vy_hi, vscale); |
| 47 |
|
| 48 |
wasm_v128_store(output, vy_lo); |
| 49 |
wasm_v128_store(output + 4, vy_hi); |
| 50 |
output += 8; |
| 51 |
} |
| 52 |
if XNN_UNLIKELY(batch != 0) { |
| 53 |
assert(batch >= 1 * sizeof(uint8_t)); |
| 54 |
assert(batch <= 7 * sizeof(uint8_t)); |
| 55 |
|
| 56 |
v128_t vx = wasm_u16x8_load8x8(input); |
| 57 |
vx = wasm_i16x8_sub(vx, vzero_point); |
| 58 |
input += 8; |
| 59 |
|
| 60 |
v128_t vy = wasm_i32x4_extend_low_i16x8(vx); |
| 61 |
vy = wasm_f32x4_convert_i32x4(vy); |
| 62 |
vy = wasm_f32x4_mul(vy, vscale); |
| 63 |
|
| 64 |
if (batch & (4 * sizeof(uint8_t))) { |
| 65 |
wasm_v128_store(output, vy); output += 4; |
| 66 |
vy = wasm_i32x4_extend_high_i16x8(vx); |
| 67 |
vy = wasm_f32x4_convert_i32x4(vy); |
| 68 |
vy = wasm_f32x4_mul(vy, vscale); |
| 69 |
} |
| 70 |
if (batch & (2 * sizeof(uint8_t))) { |
| 71 |
wasm_v128_store64_lane(output, vy, 0); |
| 72 |
vy = wasm_v64x2_shuffle(vy, vy, 1, 1); |
| 73 |
output += 2; |
| 74 |
} |
| 75 |
if (batch & (1 * sizeof(uint8_t))) { |
| 76 |
wasm_v128_store32_lane(output, vy, 0); |
| 77 |
} |
| 78 |
} |
| 79 |
} |