Debian Codegraph @

src/qu8-vcvt/gen/qu8-vcvt-wasmrelaxedsimd-u8.c

raw
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
18 void xnn_qu8_vcvt_ukernel__wasmrelaxedsimd_u8(
19 size_t batch,
20 const uint8_t* input,
21 uint8_t* output,
22 const struct xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(uint8_t) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const v128_t vinput_zero_point = wasm_v128_load16_splat(&params->scalar.input_zero_point);
30 const v128_t vmultiplier = wasm_i16x8_splat(-params->scalar.multiplier);
31 const v128_t voutput_zero_point = wasm_v128_load16_splat(&params->scalar.output_zero_point);
32 XNN_FORCE_REALIZATION(vinput_zero_point);
33 XNN_FORCE_REALIZATION(vmultiplier);
34 XNN_FORCE_REALIZATION(voutput_zero_point);
35 for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) {
36 v128_t vacc = wasm_u16x8_load8x8(input);
37 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
38 vacc = wasm_i16x8_shl(vacc, 7);
39 vacc = wasm_i16x8_relaxed_q15mulr(vacc, vmultiplier);
40 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
41 input += 8;
42
43 const v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
44 wasm_v128_store64_lane(output, vy, 0);
45 output += 8;
46 }
47 if XNN_UNLIKELY(batch != 0) {
48 assert(batch >= 1 * sizeof(uint8_t));
49 assert(batch <= 7 * sizeof(uint8_t));
50
51 v128_t vacc = wasm_u16x8_load8x8(input);
52 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
53 vacc = wasm_i16x8_shl(vacc, 7);
54 vacc = wasm_i16x8_relaxed_q15mulr(vacc, vmultiplier);
55 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
56
57 v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
58 if (batch & (4 * sizeof(uint8_t))) {
59 wasm_v128_store32_lane(output, vy, 0);
60 vy = wasm_u64x2_shr(vy, 32);
61 output += 4;
62 }
63 if (batch & (2 * sizeof(uint8_t))) {
64 wasm_v128_store16_lane(output, vy, 0);
65 vy = wasm_u32x4_shr(vy, 16);
66 output += 2;
67 }
68 if (batch & (1 * sizeof(uint8_t))) {
69 wasm_v128_store8_lane(output, vy, 0);
70 }
71 }
72 }