1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv2d-chw/5x5s2p2-scalar.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 <xnnpack/dwconv.h>
13 #include <xnnpack/math.h>
14 
15 
xnn_f32_dwconv2d_chw_ukernel_5x5s2p2__scalar_2x1_acc2(size_t input_height,size_t input_width,const float * input,const float * weights,const float * zero,float * output,uint32_t padding_top,const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_dwconv2d_chw_ukernel_5x5s2p2__scalar_2x1_acc2(
17     size_t input_height,
18     size_t input_width,
19     const float* input,
20     const float* weights,
21     const float* zero,
22     float* output,
23     uint32_t padding_top,
24     const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26   assert(input_height != 0);
27   assert(input_width != 0);
28   assert(input_width % sizeof(float) == 0);
29   assert(padding_top >= 1);
30   assert(padding_top <= 2);
31 
32   const float vmax = params->scalar.max;
33   const float vmin = params->scalar.min;
34 
35   const float vbias = weights[0];
36   const float vk00 = weights[1];
37   const float vk01 = weights[2];
38   const float vk02 = weights[3];
39   const float vk03 = weights[4];
40   const float vk04 = weights[5];
41   const float vk10 = weights[6];
42   const float vk11 = weights[7];
43   const float vk12 = weights[8];
44   const float vk13 = weights[9];
45   const float vk14 = weights[10];
46   const float vk20 = weights[11];
47   const float vk21 = weights[12];
48   const float vk22 = weights[13];
49   const float vk23 = weights[14];
50   const float vk24 = weights[15];
51   const float vk30 = weights[16];
52   const float vk31 = weights[17];
53   const float vk32 = weights[18];
54   const float vk33 = weights[19];
55   const float vk34 = weights[20];
56   const float vk40 = weights[21];
57   const float vk41 = weights[22];
58   const float vk42 = weights[23];
59   const float vk43 = weights[24];
60   const float vk44 = weights[25];
61 
62   const uint32_t padding_top_less_1 = padding_top - 1;
63 
64   const float* i0 = zero;
65   const float* i1 = (const float*) ((uintptr_t) input - ((-padding_top_less_1) & input_width));
66   const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
67   if XNN_UNPREDICTABLE(padding_top_less_1 != 0) {
68     i1 = zero;
69   }
70   const float* i3 = (const float*) ((uintptr_t) i2 + input_width);
71   const float* i4 = (const float*) ((uintptr_t) i3 + input_width);
72   const float* i5 = (const float*) ((uintptr_t) i4 + input_width);
73   const float* i6 = (const float*) ((uintptr_t) i5 + input_width);
74 
75   const size_t output_width = round_down_po2((input_width + (2 /* padding */ - 3 /* kernel size */ + 2 /* subsampling */) * sizeof(float)) / 2, sizeof(float));
76 
77   float* o0 = output;
78   float* o1 = (float*) ((uintptr_t) o0 + output_width);
79 
80   size_t padded_input_height = input_height + (padding_top_less_1 + 1) + 2 /* padding bottom */;
81   size_t output_height = (padded_input_height - 5 /* kernel size */ + 2 /* subsampling */) / 2;
82   do {
83     if XNN_UNPREDICTABLE(padded_input_height < 6) {
84       i3 = zero;
85     }
86     if XNN_UNPREDICTABLE(padded_input_height < 7) {
87       i4 = zero;
88       o1 = o0;
89     }
90     if XNN_UNPREDICTABLE(padded_input_height < 8) {
91       i5 = zero;
92     }
93     if XNN_UNPREDICTABLE(padded_input_height < 9) {
94       i6 = zero;
95     }
96 
97     float vi0x0 = 0.0f;
98     float vi1x0 = 0.0f;
99     float vi2x0 = 0.0f;
100     float vi3x0 = 0.0f;
101     float vi4x0 = 0.0f;
102     float vi5x0 = 0.0f;
103     float vi6x0 = 0.0f;
104 
105     float vi0x1 = 0.0f;
106     float vi1x1 = 0.0f;
107     float vi2x1 = 0.0f;
108     float vi3x1 = 0.0f;
109     float vi4x1 = 0.0f;
110     float vi5x1 = 0.0f;
111     float vi6x1 = 0.0f;
112 
113     float vi0x2 = *i0++;
114     float vi1x2 = *i1++;
115     float vi2x2 = *i2++;
116     float vi3x2 = *i3++;
117     float vi4x2 = *i4++;
118     float vi5x2 = *i5++;
119     float vi6x2 = *i6++;
120 
121     size_t w = input_width;
122     for (; w > 2 * sizeof(float); w -= 2 * sizeof(float)) {
123       const float vi0x3 = i0[0];
124       const float vi1x3 = i1[0];
125       const float vi2x3 = i2[0];
126       const float vi3x3 = i3[0];
127       const float vi4x3 = i4[0];
128       const float vi5x3 = i5[0];
129       const float vi6x3 = i6[0];
130 
131       const float vi0x4 = i0[1];
132       i0 += 2;
133       const float vi1x4 = i1[1];
134       i1 += 2;
135       const float vi2x4 = i2[1];
136       i2 += 2;
137       const float vi3x4 = i3[1];
138       i3 += 2;
139       const float vi4x4 = i4[1];
140       i4 += 2;
141       const float vi5x4 = i5[1];
142       i5 += 2;
143       const float vi6x4 = i6[1];
144       i6 += 2;
145 
146       float vo0p0 = vbias + vi0x0 * vk00;
147       float vo1p0 = vbias + vi2x0 * vk00;
148       float vo0p1 = vi1x0 * vk10;
149       float vo1p1 = vi3x0 * vk10;
150       vo0p0 += vi2x0 * vk20;
151       vo1p0 += vi4x0 * vk20;
152       vo0p1 += vi3x0 * vk30;
153       vo1p1 += vi5x0 * vk30;
154       vo0p0 += vi4x0 * vk40;
155       vo1p0 += vi6x0 * vk40;
156 
157       vi0x0 = vi0x2;
158       vi1x0 = vi1x2;
159       vi2x0 = vi2x2;
160       vi3x0 = vi3x2;
161       vi4x0 = vi4x2;
162       vi5x0 = vi5x2;
163       vi6x0 = vi6x2;
164 
165       vo0p1 += vi0x1 * vk01;
166       vo1p1 += vi2x1 * vk01;
167       vo0p0 += vi1x1 * vk11;
168       vo1p0 += vi3x1 * vk11;
169       vo0p1 += vi2x1 * vk21;
170       vo1p1 += vi4x1 * vk21;
171       vo0p0 += vi3x1 * vk31;
172       vo1p0 += vi5x1 * vk31;
173       vo0p1 += vi4x1 * vk41;
174       vo1p1 += vi6x1 * vk41;
175 
176       vi0x1 = vi0x3;
177       vi1x1 = vi1x3;
178       vi2x1 = vi2x3;
179       vi3x1 = vi3x3;
180       vi4x1 = vi4x3;
181       vi5x1 = vi5x3;
182       vi6x1 = vi6x3;
183 
184       vo0p0 += vi0x2 * vk02;
185       vo1p0 += vi2x2 * vk02;
186       vo0p1 += vi1x2 * vk12;
187       vo1p1 += vi3x2 * vk12;
188       vo0p0 += vi2x2 * vk22;
189       vo1p0 += vi4x2 * vk22;
190       vo0p1 += vi3x2 * vk32;
191       vo1p1 += vi5x2 * vk32;
192       vo0p0 += vi4x2 * vk42;
193       vo1p0 += vi6x2 * vk42;
194 
195       vi0x2 = vi0x4;
196       vi1x2 = vi1x4;
197       vi2x2 = vi2x4;
198       vi3x2 = vi3x4;
199       vi4x2 = vi4x4;
200       vi5x2 = vi5x4;
201       vi6x2 = vi6x4;
202 
203       vo0p1 += vi0x3 * vk03;
204       vo1p1 += vi2x3 * vk03;
205       vo0p0 += vi1x3 * vk13;
206       vo1p0 += vi3x3 * vk13;
207       vo0p1 += vi2x3 * vk23;
208       vo1p1 += vi4x3 * vk23;
209       vo0p0 += vi3x3 * vk33;
210       vo1p0 += vi5x3 * vk33;
211       vo0p1 += vi4x3 * vk43;
212       vo1p1 += vi6x3 * vk43;
213 
214       vo0p0 += vi0x4 * vk04;
215       vo1p0 += vi2x4 * vk04;
216       vo0p1 += vi1x4 * vk14;
217       vo1p1 += vi3x4 * vk14;
218       vo0p0 += vi2x4 * vk24;
219       vo1p0 += vi4x4 * vk24;
220       vo0p1 += vi3x4 * vk34;
221       vo1p1 += vi5x4 * vk34;
222       vo0p0 += vi4x4 * vk44;
223       vo1p0 += vi6x4 * vk44;
224 
225       vo0p0 += vo0p1;
226       vo1p0 += vo1p1;
227 
228       float vo0 = math_max_f32(vo0p0, vmin);
229       float vo1 = math_max_f32(vo1p0, vmin);
230 
231       vo0 = math_min_f32(vo0, vmax);
232       vo1 = math_min_f32(vo1, vmax);
233 
234       *o1++ = vo1;
235       *o0++ = vo0;
236     }
237     if XNN_LIKELY(w == 2 * sizeof(float)) {
238       const float vi0x3 = *i0++;
239       const float vi1x3 = *i1++;
240       const float vi2x3 = *i2++;
241       const float vi3x3 = *i3++;
242       const float vi4x3 = *i4++;
243       const float vi5x3 = *i5++;
244       const float vi6x3 = *i6++;
245 
246       float vo0p0 = vbias + vi0x0 * vk00;
247       float vo1p0 = vbias + vi2x0 * vk00;
248       float vo0p1 = vi1x0 * vk10;
249       float vo1p1 = vi3x0 * vk10;
250       vo0p0 += vi2x0 * vk20;
251       vo1p0 += vi4x0 * vk20;
252       vo0p1 += vi3x0 * vk30;
253       vo1p1 += vi5x0 * vk30;
254       vo0p0 += vi4x0 * vk40;
255       vo1p0 += vi6x0 * vk40;
256 
257       vo0p1 += vi0x1 * vk01;
258       vo1p1 += vi2x1 * vk01;
259       vo0p0 += vi1x1 * vk11;
260       vo1p0 += vi3x1 * vk11;
261       vo0p1 += vi2x1 * vk21;
262       vo1p1 += vi4x1 * vk21;
263       vo0p0 += vi3x1 * vk31;
264       vo1p0 += vi5x1 * vk31;
265       vo0p1 += vi4x1 * vk41;
266       vo1p1 += vi6x1 * vk41;
267 
268       vo0p0 += vi0x2 * vk02;
269       vo1p0 += vi2x2 * vk02;
270       vo0p1 += vi1x2 * vk12;
271       vo1p1 += vi3x2 * vk12;
272       vo0p0 += vi2x2 * vk22;
273       vo1p0 += vi4x2 * vk22;
274       vo0p1 += vi3x2 * vk32;
275       vo1p1 += vi5x2 * vk32;
276       vo0p0 += vi4x2 * vk42;
277       vo1p0 += vi6x2 * vk42;
278 
279       vo0p1 += vi0x3 * vk03;
280       vo1p1 += vi2x3 * vk03;
281       vo0p0 += vi1x3 * vk13;
282       vo1p0 += vi3x3 * vk13;
283       vo0p1 += vi2x3 * vk23;
284       vo1p1 += vi4x3 * vk23;
285       vo0p0 += vi3x3 * vk33;
286       vo1p0 += vi5x3 * vk33;
287       vo0p1 += vi4x3 * vk43;
288       vo1p1 += vi6x3 * vk43;
289 
290       vo0p0 += vo0p1;
291       vo1p0 += vo1p1;
292 
293       float vo0 = math_max_f32(vo0p0, vmin);
294       float vo1 = math_max_f32(vo1p0, vmin);
295 
296       vo0 = math_min_f32(vo0, vmax);
297       vo1 = math_min_f32(vo1, vmax);
298 
299       *o1++ = vo1;
300       *o0++ = vo0;
301     } else {
302       float vo0p0 = vbias + vi0x0 * vk00;
303       float vo1p0 = vbias + vi2x0 * vk00;
304       float vo0p1 = vi1x0 * vk10;
305       float vo1p1 = vi3x0 * vk10;
306       vo0p0 += vi2x0 * vk20;
307       vo1p0 += vi4x0 * vk20;
308       vo0p1 += vi3x0 * vk30;
309       vo1p1 += vi5x0 * vk30;
310       vo0p0 += vi4x0 * vk40;
311       vo1p0 += vi6x0 * vk40;
312 
313       vo0p1 += vi0x1 * vk01;
314       vo1p1 += vi2x1 * vk01;
315       vo0p0 += vi1x1 * vk11;
316       vo1p0 += vi3x1 * vk11;
317       vo0p1 += vi2x1 * vk21;
318       vo1p1 += vi4x1 * vk21;
319       vo0p0 += vi3x1 * vk31;
320       vo1p0 += vi5x1 * vk31;
321       vo0p1 += vi4x1 * vk41;
322       vo1p1 += vi6x1 * vk41;
323 
324       vo0p0 += vi0x2 * vk02;
325       vo1p0 += vi2x2 * vk02;
326       vo0p1 += vi1x2 * vk12;
327       vo1p1 += vi3x2 * vk12;
328       vo0p0 += vi2x2 * vk22;
329       vo1p0 += vi4x2 * vk22;
330       vo0p1 += vi3x2 * vk32;
331       vo1p1 += vi5x2 * vk32;
332       vo0p0 += vi4x2 * vk42;
333       vo1p0 += vi6x2 * vk42;
334 
335       vo0p0 += vo0p1;
336       vo1p0 += vo1p1;
337 
338       float vo0 = math_max_f32(vo0p0, vmin);
339       float vo1 = math_max_f32(vo1p0, vmin);
340 
341       vo0 = math_min_f32(vo0, vmax);
342       vo1 = math_min_f32(vo1, vmax);
343 
344       *o1++ = vo1;
345       *o0++ = vo0;
346     }
347 
348     i0 = (const float*) ((uintptr_t) i3);
349     i1 = (const float*) ((uintptr_t) i4);
350     i2 = (const float*) ((uintptr_t) i5);
351     i3 = (const float*) ((uintptr_t) i6);
352     i4 = (const float*) ((uintptr_t) i3 + input_width);
353     i5 = (const float*) ((uintptr_t) i4 + input_width);
354     i6 = (const float*) ((uintptr_t) i5 + input_width);
355 
356     o0 = o1;
357     o1 = (float*) ((uintptr_t) o0 + output_width);
358 
359     output_height = doz(output_height, 2);
360     padded_input_height = doz(padded_input_height, 4);
361   } while (output_height != 0);
362 }
363