1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vcvt/wasmsimd.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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/vcvt.h>
16
17
xnn_qu8_vcvt_ukernel__wasmrelaxedsimd_x8(size_t n,const uint8_t * x,uint8_t * y,const union xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_vcvt_ukernel__wasmrelaxedsimd_x8(
19 size_t n,
20 const uint8_t* x,
21 uint8_t* y,
22 const union xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(n != 0);
25 assert(n % sizeof(uint8_t) == 0);
26 assert(x != NULL);
27 assert(y != NULL);
28
29 const v128_t vinput_zero_point = wasm_v128_load64_splat(params->wasmsimd.input_zero_point);
30 const v128_t vmultiplier = wasm_v128_load64_splat(params->wasmsimd.multiplier);
31 const v128_t voutput_zero_point = wasm_v128_load64_splat(params->wasmsimd.output_zero_point);
32 for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
33 v128_t vacc = wasm_u16x8_load8x8(x);
34 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
35 vacc = wasm_i16x8_shl(vacc, 7);
36 vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
37 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
38 x += 8;
39
40 const v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
41 wasm_v128_store64_lane(y, vy, 0);
42 y += 8;
43 }
44 if XNN_UNLIKELY(n != 0) {
45 assert(n >= 1 * sizeof(uint8_t));
46 assert(n <= 7 * sizeof(uint8_t));
47
48 v128_t vacc = wasm_u16x8_load8x8(x);
49 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
50 vacc = wasm_i16x8_shl(vacc, 7);
51 vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
52 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
53
54 v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
55 if (n & (4 * sizeof(uint8_t))) {
56 wasm_v128_store32_lane(y, vy, 0);
57 vy = wasm_u64x2_shr(vy, 32);
58 y += 4;
59 }
60 if (n & (2 * sizeof(uint8_t))) {
61 wasm_v128_store16_lane(y, vy, 0);
62 vy = wasm_u32x4_shr(vy, 16);
63 y += 2;
64 }
65 if (n & (1 * sizeof(uint8_t))) {
66 wasm_v128_store8_lane(y, vy, 0);
67 }
68 }
69 }
70