// Auto-generated file. Do not edit! // Template: src/f32-qs8-vcvt/wasmsimd-magic.c.in // Generator: tools/xngen // // Copyright 2021 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include #include #include "xnnpack/common.h" #include "xnnpack/intrinsics-polyfill.h" #include "xnnpack/math.h" #include "xnnpack/vcvt.h" void xnn_f32_qs8_vcvt_ukernel__wasmsimd_magic_u8( size_t batch, const float* input, int8_t* output, const struct xnn_f32_qs8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(batch != 0); assert(batch % sizeof(float) == 0); assert(input != NULL); assert(output != NULL); const float output_min_less_zero_point = (float) ((int32_t) -128 - (int32_t) params->scalar.output_zero_point); const v128_t vscale = wasm_v128_load32_splat(¶ms->scalar.scale); const v128_t vmagic_bias = wasm_f32x4_const_splat(12582912.0f); const v128_t vmagic_min = wasm_u32x4_splat(float_as_uint32(12582912.0f + output_min_less_zero_point)); const v128_t vmagic_bias_less_zero_point = wasm_i32x4_splat(INT32_C(0x4B400000) - (int32_t) params->scalar.output_zero_point); const v128_t voutput_max = wasm_u8x16_const_splat(127); XNN_FORCE_REALIZATION(vscale); XNN_FORCE_REALIZATION(vmagic_bias); XNN_FORCE_REALIZATION(vmagic_min); XNN_FORCE_REALIZATION(vmagic_bias_less_zero_point); XNN_FORCE_REALIZATION(voutput_max); for (; batch >= 8 * sizeof(float); batch -= 8 * sizeof(float)) { v128_t vx_lo = wasm_v128_load(input); v128_t vx_hi = wasm_v128_load(input + 4); input += 8; vx_lo = wasm_f32x4_mul(vx_lo, vscale); vx_hi = wasm_f32x4_mul(vx_hi, vscale); vx_lo = wasm_f32x4_add(vx_lo, vmagic_bias); vx_hi = wasm_f32x4_add(vx_hi, vmagic_bias); v128_t vacc_lo = wasm_i32x4_max(vx_lo, vmagic_min); v128_t vacc_hi = wasm_i32x4_max(vx_hi, vmagic_min); vacc_lo = wasm_i32x4_sub(vacc_lo, vmagic_bias_less_zero_point); vacc_hi = wasm_i32x4_sub(vacc_hi, vmagic_bias_less_zero_point); const v128_t vacc = wasm_i16x8_narrow_i32x4(vacc_lo, vacc_hi); v128_t vy = wasm_i8x16_narrow_i16x8(vacc, vacc); vy = wasm_i8x16_min(vy, voutput_max); wasm_v128_store64_lane(output, vy, 0); output += 8; } if XNN_UNLIKELY(batch != 0) { assert(batch >= 1 * sizeof(float)); assert(batch <= 7 * sizeof(float)); v128_t vx_lo = wasm_v128_load(input); const float* x_hi = (const float*) ((uintptr_t) input + (batch & (4 * sizeof(float)))); v128_t vx_hi = wasm_v128_load(x_hi); vx_lo = wasm_f32x4_mul(vx_lo, vscale); vx_hi = wasm_f32x4_mul(vx_hi, vscale); vx_lo = wasm_f32x4_add(vx_lo, vmagic_bias); vx_hi = wasm_f32x4_add(vx_hi, vmagic_bias); v128_t vacc_lo = wasm_i32x4_max(vx_lo, vmagic_min); v128_t vacc_hi = wasm_i32x4_max(vx_hi, vmagic_min); vacc_lo = wasm_i32x4_sub(vacc_lo, vmagic_bias_less_zero_point); vacc_hi = wasm_i32x4_sub(vacc_hi, vmagic_bias_less_zero_point); const v128_t vacc = wasm_i16x8_narrow_i32x4(vacc_lo, vacc_hi); v128_t vy = wasm_i8x16_narrow_i16x8(vacc, vacc); vy = wasm_i8x16_min(vy, voutput_max); if (batch & (4 * sizeof(float))) { wasm_v128_store32_lane(output, vy, 0); vy = wasm_u64x2_shr(vy, 32); output += 4; } if (batch & (2 * sizeof(float))) { wasm_v128_store16_lane(output, vy, 0); vy = wasm_u32x4_shr(vy, 16); output += 2; } if (batch & (1 * sizeof(float))) { wasm_v128_store8_lane(output, vy, 0); } } }