xref: /aosp_15_r20/external/XNNPACK/src/qs8-dwconv/gen/up1x25-minmax-fp32-wasm-fmagic.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-dwconv/unipass-scalar.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 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 <xnnpack/dwconv.h>
13 #include <xnnpack/math.h>
14 #include <xnnpack/unaligned.h>
15 
16 
xnn_qs8_dwconv_minmax_fp32_ukernel_up1x25__wasm_fmagic(size_t channels,size_t output_width,const int8_t ** input,const void * weights,int8_t * output,size_t input_stride,size_t output_increment,size_t input_offset,const int8_t * zero,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_dwconv_minmax_fp32_ukernel_up1x25__wasm_fmagic(
18     size_t channels,
19     size_t output_width,
20     const int8_t** input,
21     const void* weights,
22     int8_t* output,
23     size_t input_stride,
24     size_t output_increment,
25     size_t input_offset,
26     const int8_t* zero,
27     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const float vscale = params->fp32_scalar_fmagic.scale;
33   const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point;
34   const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point;
35   const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias;
36   const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point;
37   do {
38     const int8_t* i0 = input[0];
39     assert(i0 != NULL);
40     if XNN_UNPREDICTABLE(i0 != zero) {
41       i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
42     }
43     const int8_t* i1 = input[1];
44     assert(i1 != NULL);
45     if XNN_UNPREDICTABLE(i1 != zero) {
46       i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
47     }
48     const int8_t* i2 = input[2];
49     assert(i2 != NULL);
50     if XNN_UNPREDICTABLE(i2 != zero) {
51       i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
52     }
53     const int8_t* i3 = input[3];
54     assert(i3 != NULL);
55     if XNN_UNPREDICTABLE(i3 != zero) {
56       i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
57     }
58     const int8_t* i4 = input[4];
59     assert(i4 != NULL);
60     if XNN_UNPREDICTABLE(i4 != zero) {
61       i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
62     }
63     const int8_t* i5 = input[5];
64     assert(i5 != NULL);
65     if XNN_UNPREDICTABLE(i5 != zero) {
66       i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
67     }
68     const int8_t* i6 = input[6];
69     assert(i6 != NULL);
70     if XNN_UNPREDICTABLE(i6 != zero) {
71       i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
72     }
73     const int8_t* i7 = input[7];
74     assert(i7 != NULL);
75     if XNN_UNPREDICTABLE(i7 != zero) {
76       i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
77     }
78     const int8_t* i8 = input[8];
79     assert(i8 != NULL);
80     if XNN_UNPREDICTABLE(i8 != zero) {
81       i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
82     }
83     const int8_t* i9 = input[9];
84     assert(i9 != NULL);
85     if XNN_UNPREDICTABLE(i9 != zero) {
86       i9 = (const int8_t*) ((uintptr_t) i9 + input_offset);
87     }
88     const int8_t* i10 = input[10];
89     assert(i10 != NULL);
90     if XNN_UNPREDICTABLE(i10 != zero) {
91       i10 = (const int8_t*) ((uintptr_t) i10 + input_offset);
92     }
93     const int8_t* i11 = input[11];
94     assert(i11 != NULL);
95     if XNN_UNPREDICTABLE(i11 != zero) {
96       i11 = (const int8_t*) ((uintptr_t) i11 + input_offset);
97     }
98     const int8_t* i12 = input[12];
99     assert(i12 != NULL);
100     if XNN_UNPREDICTABLE(i12 != zero) {
101       i12 = (const int8_t*) ((uintptr_t) i12 + input_offset);
102     }
103     const int8_t* i13 = input[13];
104     assert(i13 != NULL);
105     if XNN_UNPREDICTABLE(i13 != zero) {
106       i13 = (const int8_t*) ((uintptr_t) i13 + input_offset);
107     }
108     const int8_t* i14 = input[14];
109     assert(i14 != NULL);
110     if XNN_UNPREDICTABLE(i14 != zero) {
111       i14 = (const int8_t*) ((uintptr_t) i14 + input_offset);
112     }
113     const int8_t* i15 = input[15];
114     assert(i15 != NULL);
115     if XNN_UNPREDICTABLE(i15 != zero) {
116       i15 = (const int8_t*) ((uintptr_t) i15 + input_offset);
117     }
118     const int8_t* i16 = input[16];
119     assert(i16 != NULL);
120     if XNN_UNPREDICTABLE(i16 != zero) {
121       i16 = (const int8_t*) ((uintptr_t) i16 + input_offset);
122     }
123     const int8_t* i17 = input[17];
124     assert(i17 != NULL);
125     if XNN_UNPREDICTABLE(i17 != zero) {
126       i17 = (const int8_t*) ((uintptr_t) i17 + input_offset);
127     }
128     const int8_t* i18 = input[18];
129     assert(i18 != NULL);
130     if XNN_UNPREDICTABLE(i18 != zero) {
131       i18 = (const int8_t*) ((uintptr_t) i18 + input_offset);
132     }
133     const int8_t* i19 = input[19];
134     assert(i19 != NULL);
135     if XNN_UNPREDICTABLE(i19 != zero) {
136       i19 = (const int8_t*) ((uintptr_t) i19 + input_offset);
137     }
138     const int8_t* i20 = input[20];
139     assert(i20 != NULL);
140     if XNN_UNPREDICTABLE(i20 != zero) {
141       i20 = (const int8_t*) ((uintptr_t) i20 + input_offset);
142     }
143     const int8_t* i21 = input[21];
144     assert(i21 != NULL);
145     if XNN_UNPREDICTABLE(i21 != zero) {
146       i21 = (const int8_t*) ((uintptr_t) i21 + input_offset);
147     }
148     const int8_t* i22 = input[22];
149     assert(i22 != NULL);
150     if XNN_UNPREDICTABLE(i22 != zero) {
151       i22 = (const int8_t*) ((uintptr_t) i22 + input_offset);
152     }
153     const int8_t* i23 = input[23];
154     assert(i23 != NULL);
155     if XNN_UNPREDICTABLE(i23 != zero) {
156       i23 = (const int8_t*) ((uintptr_t) i23 + input_offset);
157     }
158     const int8_t* i24 = input[24];
159     assert(i24 != NULL);
160     if XNN_UNPREDICTABLE(i24 != zero) {
161       i24 = (const int8_t*) ((uintptr_t) i24 + input_offset);
162     }
163     input = (const int8_t**) ((uintptr_t) input + input_stride);
164 
165     size_t c = channels;
166     const void* w = weights;
167     do {
168       int32_t vacc = unaligned_load_s32(w);
169 
170       const int32_t vi0 = (int32_t) *i0++;
171       const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
172       vacc += vi0 * vk0;
173       const int32_t vi1 = (int32_t) *i1++;
174       const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
175       vacc += vi1 * vk1;
176       const int32_t vi2 = (int32_t) *i2++;
177       const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
178       vacc += vi2 * vk2;
179       const int32_t vi3 = (int32_t) *i3++;
180       const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
181       vacc += vi3 * vk3;
182       const int32_t vi4 = (int32_t) *i4++;
183       const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
184       vacc += vi4 * vk4;
185       const int32_t vi5 = (int32_t) *i5++;
186       const int32_t vk5 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[5];
187       vacc += vi5 * vk5;
188       const int32_t vi6 = (int32_t) *i6++;
189       const int32_t vk6 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[6];
190       vacc += vi6 * vk6;
191       const int32_t vi7 = (int32_t) *i7++;
192       const int32_t vk7 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[7];
193       vacc += vi7 * vk7;
194       const int32_t vi8 = (int32_t) *i8++;
195       const int32_t vk8 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[8];
196       vacc += vi8 * vk8;
197       const int32_t vi9 = (int32_t) *i9++;
198       const int32_t vk9 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[9];
199       vacc += vi9 * vk9;
200       const int32_t vi10 = (int32_t) *i10++;
201       const int32_t vk10 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[10];
202       vacc += vi10 * vk10;
203       const int32_t vi11 = (int32_t) *i11++;
204       const int32_t vk11 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[11];
205       vacc += vi11 * vk11;
206       const int32_t vi12 = (int32_t) *i12++;
207       const int32_t vk12 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[12];
208       vacc += vi12 * vk12;
209       const int32_t vi13 = (int32_t) *i13++;
210       const int32_t vk13 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[13];
211       vacc += vi13 * vk13;
212       const int32_t vi14 = (int32_t) *i14++;
213       const int32_t vk14 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[14];
214       vacc += vi14 * vk14;
215       const int32_t vi15 = (int32_t) *i15++;
216       const int32_t vk15 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[15];
217       vacc += vi15 * vk15;
218       const int32_t vi16 = (int32_t) *i16++;
219       const int32_t vk16 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[16];
220       vacc += vi16 * vk16;
221       const int32_t vi17 = (int32_t) *i17++;
222       const int32_t vk17 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[17];
223       vacc += vi17 * vk17;
224       const int32_t vi18 = (int32_t) *i18++;
225       const int32_t vk18 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[18];
226       vacc += vi18 * vk18;
227       const int32_t vi19 = (int32_t) *i19++;
228       const int32_t vk19 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[19];
229       vacc += vi19 * vk19;
230       const int32_t vi20 = (int32_t) *i20++;
231       const int32_t vk20 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[20];
232       vacc += vi20 * vk20;
233       const int32_t vi21 = (int32_t) *i21++;
234       const int32_t vk21 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[21];
235       vacc += vi21 * vk21;
236       const int32_t vi22 = (int32_t) *i22++;
237       const int32_t vk22 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[22];
238       vacc += vi22 * vk22;
239       const int32_t vi23 = (int32_t) *i23++;
240       const int32_t vk23 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[23];
241       vacc += vi23 * vk23;
242       const int32_t vi24 = (int32_t) *i24++;
243       const int32_t vk24 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[24];
244       vacc += vi24 * vk24;
245 
246       w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 25 * sizeof(int8_t));
247 
248       float vfpacc = (float) vacc * vscale;
249 
250       vfpacc = __builtin_wasm_max_f32(vfpacc, voutput_min_less_zero_point);
251       vfpacc = __builtin_wasm_min_f32(vfpacc, voutput_max_less_zero_point);
252       vfpacc += vmagic_bias;
253       int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_zero_point;
254 
255       *output++ = (int8_t) vout;
256     } while (--c != 0);
257 
258     output = (int8_t*) ((uintptr_t) output + output_increment);
259   } while (--output_width != 0);
260 }
261