Debian Codegraph @

src/qu8-vcvt/gen/qu8-vcvt-wasmsimd-u16.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__wasmsimd_u16(
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 >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
36 v128_t vacc0 = wasm_u16x8_load8x8(input);
37 v128_t vacc1 = wasm_u16x8_load8x8(input + 8);
38 input += 16;
39
40 vacc0 = wasm_i16x8_sub(vinput_zero_point, vacc0);
41 vacc1 = wasm_i16x8_sub(vinput_zero_point, vacc1);
42
43 vacc0 = wasm_i16x8_shl(vacc0, 7);
44 vacc1 = wasm_i16x8_shl(vacc1, 7);
45
46 vacc0 = wasm_i16x8_q15mulr_sat(vacc0, vmultiplier);
47 vacc1 = wasm_i16x8_q15mulr_sat(vacc1, vmultiplier);
48
49 vacc0 = wasm_i16x8_add_sat(vacc0, voutput_zero_point);
50 vacc1 = wasm_i16x8_add_sat(vacc1, voutput_zero_point);
51
52 const v128_t vy0 = wasm_u8x16_narrow_i16x8(vacc0, vacc1);
53
54 wasm_v128_store(output, vy0);
55 output += 16;
56 }
57 for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) {
58 v128_t vacc = wasm_u16x8_load8x8(input);
59 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
60 vacc = wasm_i16x8_shl(vacc, 7);
61 vacc = wasm_i16x8_q15mulr_sat(vacc, vmultiplier);
62 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
63 input += 8;
64
65 const v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
66 wasm_v128_store64_lane(output, vy, 0);
67 output += 8;
68 }
69 if XNN_UNLIKELY(batch != 0) {
70 assert(batch >= 1 * sizeof(uint8_t));
71 assert(batch <= 7 * sizeof(uint8_t));
72
73 v128_t vacc = wasm_u16x8_load8x8(input);
74 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
75 vacc = wasm_i16x8_shl(vacc, 7);
76 vacc = wasm_i16x8_q15mulr_sat(vacc, vmultiplier);
77 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
78
79 v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
80 if (batch & (4 * sizeof(uint8_t))) {
81 wasm_v128_store32_lane(output, vy, 0);
82 vy = wasm_u64x2_shr(vy, 32);
83 output += 4;
84 }
85 if (batch & (2 * sizeof(uint8_t))) {
86 wasm_v128_store16_lane(output, vy, 0);
87 vy = wasm_u32x4_shr(vy, 16);
88 output += 2;
89 }
90 if (batch & (1 * sizeof(uint8_t))) {
91 wasm_v128_store8_lane(output, vy, 0);
92 }
93 }
94 }