1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vlrelu/wasmsimd-arm.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_vlrelu_ukernel__wasmrelaxedsimd_arm_x32(size_t n,const uint8_t * x,uint8_t * y,const union xnn_qu8_lrelu_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_vlrelu_ukernel__wasmrelaxedsimd_arm_x32(
19 size_t n,
20 const uint8_t* x,
21 uint8_t* y,
22 const union xnn_qu8_lrelu_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_arm.input_zero_point);
30 const v128_t vpositive_multiplier = wasm_v128_load64_splat(params->wasmsimd_arm.positive_multiplier);
31 const v128_t vnegative_multiplier = wasm_v128_load64_splat(params->wasmsimd_arm.negative_multiplier);
32 const v128_t voutput_zero_point = wasm_v128_load64_splat(params->wasmsimd_arm.output_zero_point);
33 for (; n >= 32 * sizeof(uint8_t); n -= 32 * sizeof(uint8_t)) {
34 v128_t vx0 = wasm_v128_load(x);
35 v128_t vx1 = wasm_v128_load(x + 16);
36 x += 32;
37
38 v128_t vacc0 = wasm_i16x8_sub(vinput_zero_point, wasm_u16x8_extend_low_u8x16(vx0));
39 v128_t vacc1 = wasm_i16x8_sub(vinput_zero_point, wasm_u16x8_extend_high_u8x16(vx0));
40 v128_t vmultiplier0 = wasm_i16x8_shr(vacc0, 15);
41 v128_t vmultiplier1 = wasm_i16x8_shr(vacc1, 15);
42 v128_t vacc2 = wasm_i16x8_sub(vinput_zero_point, wasm_u16x8_extend_low_u8x16(vx1));
43 v128_t vacc3 = wasm_i16x8_sub(vinput_zero_point, wasm_u16x8_extend_high_u8x16(vx1));
44 v128_t vmultiplier2 = wasm_i16x8_shr(vacc2, 15);
45 v128_t vmultiplier3 = wasm_i16x8_shr(vacc3, 15);
46
47 vacc0 = wasm_i16x8_shl(vacc0, 7);
48 vmultiplier0 = wasm_v128_bitselect(vpositive_multiplier, vnegative_multiplier, vmultiplier0);
49 vacc1 = wasm_i16x8_shl(vacc1, 7);
50 vmultiplier1 = wasm_v128_bitselect(vpositive_multiplier, vnegative_multiplier, vmultiplier1);
51 vacc2 = wasm_i16x8_shl(vacc2, 7);
52 vmultiplier2 = wasm_v128_bitselect(vpositive_multiplier, vnegative_multiplier, vmultiplier2);
53 vacc3 = wasm_i16x8_shl(vacc3, 7);
54 vmultiplier3 = wasm_v128_bitselect(vpositive_multiplier, vnegative_multiplier, vmultiplier3);
55
56 vacc0 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc0, vmultiplier0);
57 vacc1 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc1, vmultiplier1);
58 vacc2 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc2, vmultiplier2);
59 vacc3 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc3, vmultiplier3);
60
61 vacc0 = wasm_i16x8_add_sat(vacc0, voutput_zero_point);
62 vacc1 = wasm_i16x8_add_sat(vacc1, voutput_zero_point);
63 vacc2 = wasm_i16x8_add_sat(vacc2, voutput_zero_point);
64 vacc3 = wasm_i16x8_add_sat(vacc3, voutput_zero_point);
65
66 const v128_t vy0 = wasm_u8x16_narrow_i16x8(vacc0, vacc1);
67 const v128_t vy1 = wasm_u8x16_narrow_i16x8(vacc2, vacc3);
68
69 wasm_v128_store(y, vy0);
70 wasm_v128_store((y + 16), vy1);
71 y += 32;
72 }
73 for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
74 const v128_t vx = wasm_u16x8_load8x8(x);
75 v128_t vacc = wasm_i16x8_sub(vinput_zero_point, vx);
76 v128_t vmultiplier = wasm_i16x8_shr(vacc, 15);
77 vacc = wasm_i16x8_shl(vacc, 7);
78 vmultiplier = wasm_v128_bitselect(vpositive_multiplier, vnegative_multiplier, vmultiplier);
79 vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
80 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
81 x += 8;
82
83 const v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
84 wasm_v128_store64_lane(y, vy, 0);
85 y += 8;
86 }
87 if XNN_UNLIKELY(n != 0) {
88 assert(n >= 1 * sizeof(uint8_t));
89 assert(n <= 7 * sizeof(uint8_t));
90
91 const v128_t vx = wasm_u16x8_load8x8(x);
92 v128_t vacc = wasm_i16x8_sub(vinput_zero_point, vx);
93 v128_t vmultiplier = wasm_i16x8_shr(vacc, 15);
94 vacc = wasm_i16x8_shl(vacc, 7);
95 vmultiplier = wasm_v128_bitselect(vpositive_multiplier, vnegative_multiplier, vmultiplier);
96 vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
97 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
98
99 v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
100 if (n & (4 * sizeof(uint8_t))) {
101 wasm_v128_store32_lane(y, vy, 0);
102 vy = wasm_u64x2_shr(vy, 32);
103 y += 4;
104 }
105 if (n & (2 * sizeof(uint8_t))) {
106 wasm_v128_store16_lane(y, vy, 0);
107 vy = wasm_u32x4_shr(vy, 16);
108 y += 2;
109 }
110 if (n & (1 * sizeof(uint8_t))) {
111 wasm_v128_store8_lane(y, vy, 0);
112 }
113 }
114 }
115