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_4x8(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_4x8(
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_DISABLE_TSAN
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 const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
34 float* o1 = (float*) ((uintptr_t) o0 + output_stride);
35 if XNN_UNPREDICTABLE(rows < 2) {
36 i1 = i0;
37 o1 = o0;
38 }
39 const float* i2 = (const float*) ((uintptr_t) i1 + input_stride);
40 float* o2 = (float*) ((uintptr_t) o1 + output_stride);
41 if XNN_UNPREDICTABLE(rows <= 2) {
42 i2 = i1;
43 o2 = o1;
44 }
45 const float* i3 = (const float*) ((uintptr_t) i2 + input_stride);
46 float* o3 = (float*) ((uintptr_t) o2 + output_stride);
47 if XNN_UNPREDICTABLE(rows < 4) {
48 i3 = i2;
49 o3 = o2;
50 }
51
52 const size_t input_increment = input_stride * 4 - channels;
53 const size_t output_increment = output_stride * 4 - channels;
54
55 const v128_t vzero = wasm_i32x4_splat(0);
56 do {
57 const float* w = weights;
58 size_t c = channels;
59 for (; c >= 8 * sizeof(float); c -= 8 * sizeof(float)) {
60 const v128_t vw0123 = wasm_v128_load(w);
61 const v128_t vw4567 = wasm_v128_load(w + 4);
62 w += 8;
63
64 const v128_t vi0x0123 = wasm_v128_load(i0);
65 const v128_t vi0x4567 = wasm_v128_load(i0 + 4);
66 i0 += 8;
67 const v128_t vi1x0123 = wasm_v128_load(i1);
68 const v128_t vi1x4567 = wasm_v128_load(i1 + 4);
69 i1 += 8;
70 const v128_t vi2x0123 = wasm_v128_load(i2);
71 const v128_t vi2x4567 = wasm_v128_load(i2 + 4);
72 i2 += 8;
73 const v128_t vi3x0123 = wasm_v128_load(i3);
74 const v128_t vi3x4567 = wasm_v128_load(i3 + 4);
75 i3 += 8;
76
77 v128_t vacc0x0123 = wasm_f32x4_mul(vi0x0123, vw0123);
78 const v128_t vmask0x0123 = wasm_i32x4_lt(vi0x0123, vzero);
79 v128_t vacc0x4567 = wasm_f32x4_mul(vi0x4567, vw4567);
80 const v128_t vmask0x4567 = wasm_i32x4_lt(vi0x4567, vzero);
81 v128_t vacc1x0123 = wasm_f32x4_mul(vi1x0123, vw0123);
82 const v128_t vmask1x0123 = wasm_i32x4_lt(vi1x0123, vzero);
83 v128_t vacc1x4567 = wasm_f32x4_mul(vi1x4567, vw4567);
84 const v128_t vmask1x4567 = wasm_i32x4_lt(vi1x4567, vzero);
85 v128_t vacc2x0123 = wasm_f32x4_mul(vi2x0123, vw0123);
86 const v128_t vmask2x0123 = wasm_i32x4_lt(vi2x0123, vzero);
87 v128_t vacc2x4567 = wasm_f32x4_mul(vi2x4567, vw4567);
88 const v128_t vmask2x4567 = wasm_i32x4_lt(vi2x4567, vzero);
89 v128_t vacc3x0123 = wasm_f32x4_mul(vi3x0123, vw0123);
90 const v128_t vmask3x0123 = wasm_i32x4_lt(vi3x0123, vzero);
91 v128_t vacc3x4567 = wasm_f32x4_mul(vi3x4567, vw4567);
92 const v128_t vmask3x4567 = wasm_i32x4_lt(vi3x4567, vzero);
93
94 vacc0x0123 = wasm_v128_bitselect(vacc0x0123, vi0x0123, vmask0x0123);
95 vacc0x4567 = wasm_v128_bitselect(vacc0x4567, vi0x4567, vmask0x4567);
96 vacc1x0123 = wasm_v128_bitselect(vacc1x0123, vi1x0123, vmask1x0123);
97 vacc1x4567 = wasm_v128_bitselect(vacc1x4567, vi1x4567, vmask1x4567);
98 vacc2x0123 = wasm_v128_bitselect(vacc2x0123, vi2x0123, vmask2x0123);
99 vacc2x4567 = wasm_v128_bitselect(vacc2x4567, vi2x4567, vmask2x4567);
100 vacc3x0123 = wasm_v128_bitselect(vacc3x0123, vi3x0123, vmask3x0123);
101 vacc3x4567 = wasm_v128_bitselect(vacc3x4567, vi3x4567, vmask3x4567);
102
103 wasm_v128_store(o0, vacc0x0123);
104 wasm_v128_store(o0 + 4, vacc0x4567);
105 o0 += 8;
106 wasm_v128_store(o1, vacc1x0123);
107 wasm_v128_store(o1 + 4, vacc1x4567);
108 o1 += 8;
109 wasm_v128_store(o2, vacc2x0123);
110 wasm_v128_store(o2 + 4, vacc2x4567);
111 o2 += 8;
112 wasm_v128_store(o3, vacc3x0123);
113 wasm_v128_store(o3 + 4, vacc3x4567);
114 o3 += 8;
115 }
116 for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
117 const v128_t vw0123 = wasm_v128_load(w);
118 w += 4;
119
120 const v128_t vi0x0123 = wasm_v128_load(i0);
121 i0 += 4;
122 const v128_t vi1x0123 = wasm_v128_load(i1);
123 i1 += 4;
124 const v128_t vi2x0123 = wasm_v128_load(i2);
125 i2 += 4;
126 const v128_t vi3x0123 = wasm_v128_load(i3);
127 i3 += 4;
128
129 v128_t vacc0x0123 = wasm_f32x4_mul(vi0x0123, vw0123);
130 const v128_t vmask0x0123 = wasm_i32x4_lt(vi0x0123, vzero);
131 v128_t vacc1x0123 = wasm_f32x4_mul(vi1x0123, vw0123);
132 const v128_t vmask1x0123 = wasm_i32x4_lt(vi1x0123, vzero);
133 v128_t vacc2x0123 = wasm_f32x4_mul(vi2x0123, vw0123);
134 const v128_t vmask2x0123 = wasm_i32x4_lt(vi2x0123, vzero);
135 v128_t vacc3x0123 = wasm_f32x4_mul(vi3x0123, vw0123);
136 const v128_t vmask3x0123 = wasm_i32x4_lt(vi3x0123, vzero);
137
138 vacc0x0123 = wasm_v128_bitselect(vacc0x0123, vi0x0123, vmask0x0123);
139 vacc1x0123 = wasm_v128_bitselect(vacc1x0123, vi1x0123, vmask1x0123);
140 vacc2x0123 = wasm_v128_bitselect(vacc2x0123, vi2x0123, vmask2x0123);
141 vacc3x0123 = wasm_v128_bitselect(vacc3x0123, vi3x0123, vmask3x0123);
142
143 wasm_v128_store(o0, vacc0x0123);
144 o0 += 4;
145 wasm_v128_store(o1, vacc1x0123);
146 o1 += 4;
147 wasm_v128_store(o2, vacc2x0123);
148 o2 += 4;
149 wasm_v128_store(o3, vacc3x0123);
150 o3 += 4;
151 }
152 if XNN_UNLIKELY(c != 0) {
153 const v128_t vw0123 = wasm_v128_load(w);
154 w = (const float*) ((uintptr_t) w + c);
155
156 const v128_t vi0x0123 = wasm_v128_load(i0);
157 i0 = (const float*) ((uintptr_t) i0 + c);
158 const v128_t vi1x0123 = wasm_v128_load(i1);
159 i1 = (const float*) ((uintptr_t) i1 + c);
160 const v128_t vi2x0123 = wasm_v128_load(i2);
161 i2 = (const float*) ((uintptr_t) i2 + c);
162 const v128_t vi3x0123 = wasm_v128_load(i3);
163 i3 = (const float*) ((uintptr_t) i3 + c);
164
165 v128_t vacc0x0123 = wasm_f32x4_mul(vi0x0123, vw0123);
166 const v128_t vmask0x0123 = wasm_i32x4_lt(vi0x0123, vzero);
167 v128_t vacc1x0123 = wasm_f32x4_mul(vi1x0123, vw0123);
168 const v128_t vmask1x0123 = wasm_i32x4_lt(vi1x0123, vzero);
169 v128_t vacc2x0123 = wasm_f32x4_mul(vi2x0123, vw0123);
170 const v128_t vmask2x0123 = wasm_i32x4_lt(vi2x0123, vzero);
171 v128_t vacc3x0123 = wasm_f32x4_mul(vi3x0123, vw0123);
172 const v128_t vmask3x0123 = wasm_i32x4_lt(vi3x0123, vzero);
173
174 vacc0x0123 = wasm_v128_bitselect(vacc0x0123, vi0x0123, vmask0x0123);
175 vacc1x0123 = wasm_v128_bitselect(vacc1x0123, vi1x0123, vmask1x0123);
176 vacc2x0123 = wasm_v128_bitselect(vacc2x0123, vi2x0123, vmask2x0123);
177 vacc3x0123 = wasm_v128_bitselect(vacc3x0123, vi3x0123, vmask3x0123);
178
179 if (c & (2 * sizeof(float))) {
180 *((double*) o0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
181 *((double*) o1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
182 *((double*) o2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
183 *((double*) o3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
184
185 vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
186 vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
187 vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
188 vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
189
190 o0 += 2;
191 o1 += 2;
192 o2 += 2;
193 o3 += 2;
194 }
195 if (c & (1 * sizeof(float))) {
196 *o0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
197 *o1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
198 *o2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
199 *o3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
200
201 o0 += 1;
202 o1 += 1;
203 o2 += 1;
204 o3 += 1;
205 }
206 }
207 i0 = (const float*) ((uintptr_t) i0 + input_increment);
208 o0 = (float*) ((uintptr_t) o0 + output_increment);
209 i1 = (const float*) ((uintptr_t) i1 + input_increment);
210 o1 = (float*) ((uintptr_t) o1 + output_increment);
211 if XNN_UNPREDICTABLE(rows < 6) {
212 i1 = i0;
213 o1 = o0;
214 }
215 i2 = (const float*) ((uintptr_t) i2 + input_increment);
216 o2 = (float*) ((uintptr_t) o2 + output_increment);
217 if XNN_UNPREDICTABLE(rows <= 6) {
218 i2 = i1;
219 o2 = o1;
220 }
221 i3 = (const float*) ((uintptr_t) i3 + input_increment);
222 o3 = (float*) ((uintptr_t) o3 + output_increment);
223 if XNN_UNPREDICTABLE(rows < 8) {
224 i3 = i2;
225 o3 = o2;
226 }
227 rows = doz(rows, 4);
228 } while (rows != 0);
229 }
230