Debian Codegraph @

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