xref: /aosp_15_r20/external/XNNPACK/src/f32-prelu/gen/wasmsimd-bitselect-1x16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-prelu/wasmsimd-bitselect.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/math.h>
15 #include <xnnpack/prelu.h>
16 
17 
xnn_f32_prelu_ukernel__wasmsimd_bitselect_1x16(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride)18 void xnn_f32_prelu_ukernel__wasmsimd_bitselect_1x16(
19     size_t rows,
20     size_t channels,
21     const float*restrict input,
22     size_t input_stride,
23     const float*restrict weights,
24     float*restrict output,
25     size_t output_stride) XNN_OOB_READS
26 {
27   assert(rows != 0);
28   assert(channels != 0);
29   assert(channels % sizeof(float) == 0);
30 
31   const float* i0 = input;
32   float* o0 = output;
33 
34   const size_t input_increment = input_stride * 1 - channels;
35   const size_t output_increment = output_stride * 1 - channels;
36 
37   do {
38 
39     const float* w = weights;
40     size_t c = channels;
41     for (; c >= 16 * sizeof(float); c -= 16 * sizeof(float)) {
42       const v128_t vw0123 = wasm_v128_load(w);
43       const v128_t vw4567 = wasm_v128_load(w + 4);
44       const v128_t vw89AB = wasm_v128_load(w + 8);
45       const v128_t vwCDEF = wasm_v128_load(w + 12);
46       w += 16;
47 
48       const v128_t vi0x0123 = wasm_v128_load(i0);
49       const v128_t vi0x4567 = wasm_v128_load(i0 + 4);
50       const v128_t vi0x89AB = wasm_v128_load(i0 + 8);
51       const v128_t vi0xCDEF = wasm_v128_load(i0 + 12);
52       i0 += 16;
53 
54       v128_t vacc0x0123 = wasm_f32x4_mul(vi0x0123, vw0123);
55       const v128_t vmask0x0123 = wasm_i32x4_shr(vi0x0123, 31);
56       v128_t vacc0x4567 = wasm_f32x4_mul(vi0x4567, vw4567);
57       const v128_t vmask0x4567 = wasm_i32x4_shr(vi0x4567, 31);
58       v128_t vacc0x89AB = wasm_f32x4_mul(vi0x89AB, vw89AB);
59       const v128_t vmask0x89AB = wasm_i32x4_shr(vi0x89AB, 31);
60       v128_t vacc0xCDEF = wasm_f32x4_mul(vi0xCDEF, vwCDEF);
61       const v128_t vmask0xCDEF = wasm_i32x4_shr(vi0xCDEF, 31);
62 
63       vacc0x0123 = wasm_v128_bitselect(vacc0x0123, vi0x0123, vmask0x0123);
64       vacc0x4567 = wasm_v128_bitselect(vacc0x4567, vi0x4567, vmask0x4567);
65       vacc0x89AB = wasm_v128_bitselect(vacc0x89AB, vi0x89AB, vmask0x89AB);
66       vacc0xCDEF = wasm_v128_bitselect(vacc0xCDEF, vi0xCDEF, vmask0xCDEF);
67 
68       wasm_v128_store(o0, vacc0x0123);
69       wasm_v128_store(o0 + 4, vacc0x4567);
70       wasm_v128_store(o0 + 8, vacc0x89AB);
71       wasm_v128_store(o0 + 12, vacc0xCDEF);
72       o0 += 16;
73     }
74     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
75       const v128_t vw0123 = wasm_v128_load(w);
76       w += 4;
77 
78       const v128_t vi0x0123 = wasm_v128_load(i0);
79       i0 += 4;
80 
81       v128_t vacc0x0123 = wasm_f32x4_mul(vi0x0123, vw0123);
82       const v128_t vmask0x0123 = wasm_i32x4_shr(vi0x0123, 31);
83 
84       vacc0x0123 = wasm_v128_bitselect(vacc0x0123, vi0x0123, vmask0x0123);
85 
86       wasm_v128_store(o0, vacc0x0123);
87       o0 += 4;
88     }
89     if XNN_UNLIKELY(c != 0) {
90       const v128_t vw0123 = wasm_v128_load(w);
91       w = (const float*) ((uintptr_t) w + c);
92 
93       const v128_t vi0x0123 = wasm_v128_load(i0);
94       i0 = (const float*) ((uintptr_t) i0 + c);
95 
96       v128_t vacc0x0123 = wasm_f32x4_mul(vi0x0123, vw0123);
97       const v128_t vmask0x0123 = wasm_i32x4_shr(vi0x0123, 31);
98 
99       vacc0x0123 = wasm_v128_bitselect(vacc0x0123, vi0x0123, vmask0x0123);
100 
101       if (c & (2 * sizeof(float))) {
102         *((double*) o0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
103 
104         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
105 
106         o0 += 2;
107       }
108       if (c & (1 * sizeof(float))) {
109         *o0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
110 
111         o0 += 1;
112       }
113     }
114     i0 = (const float*) ((uintptr_t) i0 + input_increment);
115     o0 = (float*) ((uintptr_t) o0 + output_increment);
116     rows = doz(rows, 1);
117   } while (rows != 0);
118 }
119