xref: /aosp_15_r20/external/XNNPACK/src/qu8-vcvt/gen/vcvt-wasmrelaxedsimd-x16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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 
xnn_qu8_vcvt_ukernel__wasmrelaxedsimd_x16(size_t n,const uint8_t * x,uint8_t * y,const union xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_vcvt_ukernel__wasmrelaxedsimd_x16(
19     size_t n,
20     const uint8_t* x,
21     uint8_t* y,
22     const union xnn_qu8_cvt_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.input_zero_point);
30   const v128_t vmultiplier = wasm_v128_load64_splat(params->wasmsimd.multiplier);
31   const v128_t voutput_zero_point = wasm_v128_load64_splat(params->wasmsimd.output_zero_point);
32   for (; n >= 16 * sizeof(uint8_t); n -= 16 * sizeof(uint8_t)) {
33     v128_t vacc0 = wasm_u16x8_load8x8(x);
34     v128_t vacc1 = wasm_u16x8_load8x8(x + 8);
35     x += 16;
36 
37     vacc0 = wasm_i16x8_sub(vinput_zero_point, vacc0);
38     vacc1 = wasm_i16x8_sub(vinput_zero_point, vacc1);
39 
40     vacc0 = wasm_i16x8_shl(vacc0, 7);
41     vacc1 = wasm_i16x8_shl(vacc1, 7);
42 
43     vacc0 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc0, vmultiplier);
44     vacc1 = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc1, vmultiplier);
45 
46     vacc0 = wasm_i16x8_add_sat(vacc0, voutput_zero_point);
47     vacc1 = wasm_i16x8_add_sat(vacc1, voutput_zero_point);
48 
49     const v128_t vy0 = wasm_u8x16_narrow_i16x8(vacc0, vacc1);
50 
51     wasm_v128_store(y, vy0);
52     y += 16;
53   }
54   for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
55     v128_t vacc = wasm_u16x8_load8x8(x);
56     vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
57     vacc = wasm_i16x8_shl(vacc, 7);
58     vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
59     vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
60     x += 8;
61 
62     const v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
63     wasm_v128_store64_lane(y, vy, 0);
64     y += 8;
65   }
66   if XNN_UNLIKELY(n != 0) {
67     assert(n >= 1 * sizeof(uint8_t));
68     assert(n <= 7 * sizeof(uint8_t));
69 
70     v128_t vacc = wasm_u16x8_load8x8(x);
71     vacc = wasm_i16x8_sub(vinput_zero_point, vacc);
72     vacc = wasm_i16x8_shl(vacc, 7);
73     vacc = __builtin_wasm_relaxed_q15mulr_s_i16x8(vacc, vmultiplier);
74     vacc = wasm_i16x8_add_sat(vacc, voutput_zero_point);
75 
76     v128_t vy = wasm_u8x16_narrow_i16x8(vacc, vacc);
77     if (n & (4 * sizeof(uint8_t))) {
78       wasm_v128_store32_lane(y, vy, 0);
79       vy = wasm_u64x2_shr(vy, 32);
80       y += 4;
81     }
82     if (n & (2 * sizeof(uint8_t))) {
83       wasm_v128_store16_lane(y, vy, 0);
84       vy = wasm_u32x4_shr(vy, 16);
85       y += 2;
86     }
87     if (n & (1 * sizeof(uint8_t))) {
88       wasm_v128_store8_lane(y, vy, 0);
89     }
90   }
91 }
92