1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vlrelu/wasmsimd-x86.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_x86_x16(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_x86_x16(
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_x86.input_zero_point);
30 const v128_t vmultiplier_diff = wasm_v128_load64_splat(params->wasmsimd_x86.multiplier_diff);
31 const v128_t vmultiplier_base = wasm_v128_load64_splat(params->wasmsimd_x86.multiplier_base);
32 const v128_t voutput_zero_point = wasm_v128_load64_splat(params->wasmsimd_x86.output_zero_point);
33 for (; n >= 16 * sizeof(uint8_t); n -= 16 * sizeof(uint8_t)) {
34 v128_t vacc0 = wasm_u16x8_load8x8(x);
35 v128_t vacc1 = wasm_u16x8_load8x8(x + 8);
36 x += 16;
37
38 v128_t vmultiplier0 = wasm_i16x8_gt(vacc0, vinput_zero_point);
39 vacc0 = wasm_i16x8_sub(vinput_zero_point, vacc0);
40 v128_t vmultiplier1 = wasm_i16x8_gt(vacc1, vinput_zero_point);
41 vacc1 = wasm_i16x8_sub(vinput_zero_point, vacc1);
42
43 vmultiplier0 = wasm_v128_and(vmultiplier0, vmultiplier_diff);
44 vacc0 = wasm_i16x8_shl(vacc0, 7);
45 vmultiplier0 = wasm_v128_xor(vmultiplier0, vmultiplier_base);
46 vmultiplier1 = wasm_v128_and(vmultiplier1, vmultiplier_diff);
47 vacc1 = wasm_i16x8_shl(vacc1, 7);
48 vmultiplier1 = wasm_v128_xor(vmultiplier1, vmultiplier_base);
49
50 vacc0 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc0, vmultiplier0);
51 vacc1 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc1, vmultiplier1);
52
53 vacc0 = wasm_i16x8_add_sat(vacc0, voutput_zero_point);
54 vacc1 = wasm_i16x8_add_sat(vacc1, voutput_zero_point);
55
56 const v128_t vy0 = wasm_u8x16_narrow_i16x8(vacc0, vacc1);
57
58 wasm_v128_store(y, vy0);
59 y += 16;
60 }
61 for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
62 v128_t vacc = wasm_u16x8_load8x8(x);
63 v128_t vmultiplier = wasm_i16x8_gt(vacc, vinput_zero_point);
64 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
65 vmultiplier = wasm_v128_and(vmultiplier, vmultiplier_diff);
66 vacc = wasm_i16x8_shl(vacc, 7);
67 vmultiplier = wasm_v128_xor(vmultiplier, vmultiplier_base);
68 vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
69 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
70 x += 8;
71
72 const v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
73 wasm_v128_store64_lane(y, vy, 0);
74 y += 8;
75 }
76 if XNN_UNLIKELY(n != 0) {
77 assert(n >= 1 * sizeof(uint8_t));
78 assert(n <= 7 * sizeof(uint8_t));
79
80 v128_t vacc = wasm_u16x8_load8x8(x);
81 v128_t vmultiplier = wasm_i16x8_gt(vacc, vinput_zero_point);
82 vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
83 vmultiplier = wasm_v128_and(vmultiplier, vmultiplier_diff);
84 vacc = wasm_i16x8_shl(vacc, 7);
85 vmultiplier = wasm_v128_xor(vmultiplier, vmultiplier_base);
86 vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
87 vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
88
89 v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
90 if (n & (4 * sizeof(uint8_t))) {
91 wasm_v128_store32_lane(y, vy, 0);
92 vy = wasm_u64x2_shr(vy, 32);
93 y += 4;
94 }
95 if (n & (2 * sizeof(uint8_t))) {
96 wasm_v128_store16_lane(y, vy, 0);
97 vy = wasm_u32x4_shr(vy, 16);
98 y += 2;
99 }
100 if (n & (1 * sizeof(uint8_t))) {
101 wasm_v128_store8_lane(y, vy, 0);
102 }
103 }
104 }
105