xref: /aosp_15_r20/external/XNNPACK/src/qu8-vlrelu/gen/vlrelu-wasmrelaxedsimd-x86-x8.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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_x8(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_x8(
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 >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
34     v128_t vacc = wasm_u16x8_load8x8(x);
35     v128_t vmultiplier = wasm_i16x8_gt(vacc, vinput_zero_point);
36     vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
37     vmultiplier = wasm_v128_and(vmultiplier, vmultiplier_diff);
38     vacc = wasm_i16x8_shl(vacc, 7);
39     vmultiplier = wasm_v128_xor(vmultiplier, vmultiplier_base);
40     vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
41     vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
42     x += 8;
43 
44     const v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
45     wasm_v128_store64_lane(y, vy, 0);
46     y += 8;
47   }
48   if XNN_UNLIKELY(n != 0) {
49     assert(n >= 1 * sizeof(uint8_t));
50     assert(n <= 7 * sizeof(uint8_t));
51 
52     v128_t vacc = wasm_u16x8_load8x8(x);
53     v128_t vmultiplier = wasm_i16x8_gt(vacc, vinput_zero_point);
54     vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
55     vmultiplier = wasm_v128_and(vmultiplier, vmultiplier_diff);
56     vacc = wasm_i16x8_shl(vacc, 7);
57     vmultiplier = wasm_v128_xor(vmultiplier, vmultiplier_base);
58     vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
59     vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
60 
61     v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
62     if (n & (4 * sizeof(uint8_t))) {
63       wasm_v128_store32_lane(y, vy, 0);
64       vy = wasm_u64x2_shr(vy, 32);
65       y += 4;
66     }
67     if (n & (2 * sizeof(uint8_t))) {
68       wasm_v128_store16_lane(y, vy, 0);
69       vy = wasm_u32x4_shr(vy, 16);
70       y += 2;
71     }
72     if (n & (1 * sizeof(uint8_t))) {
73       wasm_v128_store8_lane(y, vy, 0);
74     }
75   }
76 }
77