• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-vaddc/wasmsimd.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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/vadd.h>
15 
16 
xnn_qu8_vaddc_minmax_ukernel__wasmsimd_x32(size_t n,const uint8_t * input_a,const uint8_t * input_b,uint8_t * output,const union xnn_qu8_add_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qu8_vaddc_minmax_ukernel__wasmsimd_x32(
18     size_t n,
19     const uint8_t* input_a,
20     const uint8_t* input_b,
21     uint8_t* output,
22     const union xnn_qu8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24   const v128_t va_multiplier = wasm_v128_load64_splat(params->wasmsimd.a_multiplier);
25   const uint32_t vshift = params->wasmsimd.shift;
26   const v128_t voutput_zero_point = wasm_v128_load64_splat(params->wasmsimd.output_zero_point);
27   const v128_t voutput_min = wasm_v128_load64_splat(params->wasmsimd.output_min);
28   const v128_t voutput_max = wasm_v128_load64_splat(params->wasmsimd.output_max);
29 
30   v128_t vbias = wasm_i32x4_splat((int32_t) *input_b * params->wasmsimd.b_multiplier[0]);
31   vbias = wasm_i32x4_add(vbias, wasm_v128_load64_splat(params->wasmsimd.bias));
32 
33   for (; n >= 32 * sizeof(uint8_t); n -= 32 * sizeof(uint8_t)) {
34     const v128_t va01234567 = wasm_u16x8_load8x8(input_a);
35     const v128_t va89ABCDEF = wasm_u16x8_load8x8(input_a + 8);
36     const v128_t vaGHIJKLMN = wasm_u16x8_load8x8(input_a + 16);
37     const v128_t vaOPQRSTUV = wasm_u16x8_load8x8(input_a + 24);
38     input_a += 32;
39 
40     v128_t vacc0123 = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_low_u16x8(va01234567), va_multiplier));
41     v128_t vacc4567 = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_high_u16x8(va01234567), va_multiplier));
42     v128_t vacc89AB = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_low_u16x8(va89ABCDEF), va_multiplier));
43     v128_t vaccCDEF = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_high_u16x8(va89ABCDEF), va_multiplier));
44     v128_t vaccGHIJ = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_low_u16x8(vaGHIJKLMN), va_multiplier));
45     v128_t vaccKLMN = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_high_u16x8(vaGHIJKLMN), va_multiplier));
46     v128_t vaccOPQR = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_low_u16x8(vaOPQRSTUV), va_multiplier));
47     v128_t vaccSTUV = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_high_u16x8(vaOPQRSTUV), va_multiplier));
48 
49     vacc0123 = wasm_i32x4_shr(vacc0123, vshift);
50     vacc4567 = wasm_i32x4_shr(vacc4567, vshift);
51     vacc89AB = wasm_i32x4_shr(vacc89AB, vshift);
52     vaccCDEF = wasm_i32x4_shr(vaccCDEF, vshift);
53     vaccGHIJ = wasm_i32x4_shr(vaccGHIJ, vshift);
54     vaccKLMN = wasm_i32x4_shr(vaccKLMN, vshift);
55     vaccOPQR = wasm_i32x4_shr(vaccOPQR, vshift);
56     vaccSTUV = wasm_i32x4_shr(vaccSTUV, vshift);
57 
58     v128_t vout01234567 = wasm_i16x8_add_sat(wasm_i16x8_narrow_i32x4(vacc0123, vacc4567), voutput_zero_point);
59     v128_t vout89ABCDEF = wasm_i16x8_add_sat(wasm_i16x8_narrow_i32x4(vacc89AB, vaccCDEF), voutput_zero_point);
60     v128_t voutGHIJKLMN = wasm_i16x8_add_sat(wasm_i16x8_narrow_i32x4(vaccGHIJ, vaccKLMN), voutput_zero_point);
61     v128_t voutOPQRSTUV = wasm_i16x8_add_sat(wasm_i16x8_narrow_i32x4(vaccOPQR, vaccSTUV), voutput_zero_point);
62 
63     v128_t vout0123456789ABCDEF = wasm_u8x16_narrow_i16x8(vout01234567, vout89ABCDEF);
64     v128_t voutGHIJKLMNOPQRSTUV = wasm_u8x16_narrow_i16x8(voutGHIJKLMN, voutOPQRSTUV);
65 
66     vout0123456789ABCDEF = wasm_u8x16_max(vout0123456789ABCDEF, voutput_min);
67     voutGHIJKLMNOPQRSTUV = wasm_u8x16_max(voutGHIJKLMNOPQRSTUV, voutput_min);
68 
69     vout0123456789ABCDEF = wasm_u8x16_min(vout0123456789ABCDEF, voutput_max);
70     voutGHIJKLMNOPQRSTUV = wasm_u8x16_min(voutGHIJKLMNOPQRSTUV, voutput_max);
71 
72     wasm_v128_store(output, vout0123456789ABCDEF);
73     wasm_v128_store(output + 16, voutGHIJKLMNOPQRSTUV);
74     output += 32;
75   }
76   if XNN_UNLIKELY(n != 0) {
77     do {
78       const v128_t va01234567 = wasm_u16x8_load8x8(input_a);
79       input_a += 8;
80 
81       v128_t vacc0123 = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_low_u16x8(va01234567), va_multiplier));
82       v128_t vacc4567 = wasm_i32x4_add(vbias, wasm_i32x4_mul(wasm_u32x4_extend_high_u16x8(va01234567), va_multiplier));
83 
84       vacc0123 = wasm_i32x4_shr(vacc0123, vshift);
85       vacc4567 = wasm_i32x4_shr(vacc4567, vshift);
86 
87       v128_t vout01234567 = wasm_i16x8_add_sat(wasm_i16x8_narrow_i32x4(vacc0123, vacc4567), voutput_zero_point);
88 
89       v128_t vout0123456701234567 = wasm_u8x16_narrow_i16x8(vout01234567, vout01234567);
90       vout0123456701234567 = wasm_u8x16_max(vout0123456701234567, voutput_min);
91       vout0123456701234567 = wasm_u8x16_min(vout0123456701234567, voutput_max);
92 
93       if XNN_LIKELY(n >= (8 * sizeof(uint8_t))) {
94         *((double*) output) = wasm_f64x2_extract_lane(vout0123456701234567, 0);
95         output += 8;
96         n -= 8 * sizeof(uint8_t);
97       } else {
98         if (n & (4 * sizeof(uint8_t))) {
99           *((float*) output) = (float) wasm_f32x4_extract_lane(vout0123456701234567, 0);
100           vout0123456701234567 = wasm_u64x2_shr(vout0123456701234567, 32);
101           output += 4;
102         }
103         uint32_t vout0123 = wasm_i32x4_extract_lane(vout0123456701234567, 0);
104         if (n & (2 * sizeof(uint8_t))) {
105           *((uint16_t*) output) = (uint16_t) vout0123;
106           vout0123 >>= 16;
107           output += 2;
108         }
109         if (n & (1 * sizeof(uint8_t))) {
110           *output = (uint8_t) vout0123;
111         }
112         n = 0;
113       }
114     } while (n != 0);
115   }
116 }
117