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_1x1_acc3(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_1x1_acc3(
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 
73 
74   float* o0 = output;
75 
76   size_t padded_input_height = input_height + (padding_top_less_1 + 1) + 2 /* padding bottom */;
77   size_t output_height = (padded_input_height - 5 /* kernel size */ + 2 /* subsampling */) / 2;
78   do {
79     if XNN_UNPREDICTABLE(padded_input_height < 6) {
80       i3 = zero;
81     }
82     if XNN_UNPREDICTABLE(padded_input_height < 7) {
83       i4 = zero;
84     }
85 
86     float vi0x0 = 0.0f;
87     float vi1x0 = 0.0f;
88     float vi2x0 = 0.0f;
89     float vi3x0 = 0.0f;
90     float vi4x0 = 0.0f;
91 
92     float vi0x1 = 0.0f;
93     float vi1x1 = 0.0f;
94     float vi2x1 = 0.0f;
95     float vi3x1 = 0.0f;
96     float vi4x1 = 0.0f;
97 
98     float vi0x2 = *i0++;
99     float vi1x2 = *i1++;
100     float vi2x2 = *i2++;
101     float vi3x2 = *i3++;
102     float vi4x2 = *i4++;
103 
104     size_t w = input_width;
105     for (; w > 2 * sizeof(float); w -= 2 * sizeof(float)) {
106       const float vi0x3 = i0[0];
107       const float vi1x3 = i1[0];
108       const float vi2x3 = i2[0];
109       const float vi3x3 = i3[0];
110       const float vi4x3 = i4[0];
111 
112       const float vi0x4 = i0[1];
113       i0 += 2;
114       const float vi1x4 = i1[1];
115       i1 += 2;
116       const float vi2x4 = i2[1];
117       i2 += 2;
118       const float vi3x4 = i3[1];
119       i3 += 2;
120       const float vi4x4 = i4[1];
121       i4 += 2;
122 
123       float vo0p0 = vbias + vi0x0 * vk00;
124       float vo0p1 = vi1x0 * vk10;
125       float vo0p2 = vi2x0 * vk20;
126       vo0p0 += vi3x0 * vk30;
127       vo0p1 += vi4x0 * vk40;
128 
129       vi0x0 = vi0x2;
130       vi1x0 = vi1x2;
131       vi2x0 = vi2x2;
132       vi3x0 = vi3x2;
133       vi4x0 = vi4x2;
134 
135       vo0p2 += vi0x1 * vk01;
136       vo0p0 += vi1x1 * vk11;
137       vo0p1 += vi2x1 * vk21;
138       vo0p2 += vi3x1 * vk31;
139       vo0p0 += vi4x1 * vk41;
140 
141       vi0x1 = vi0x3;
142       vi1x1 = vi1x3;
143       vi2x1 = vi2x3;
144       vi3x1 = vi3x3;
145       vi4x1 = vi4x3;
146 
147       vo0p1 += vi0x2 * vk02;
148       vo0p2 += vi1x2 * vk12;
149       vo0p0 += vi2x2 * vk22;
150       vo0p1 += vi3x2 * vk32;
151       vo0p2 += vi4x2 * vk42;
152 
153       vi0x2 = vi0x4;
154       vi1x2 = vi1x4;
155       vi2x2 = vi2x4;
156       vi3x2 = vi3x4;
157       vi4x2 = vi4x4;
158 
159       vo0p0 += vi0x3 * vk03;
160       vo0p1 += vi1x3 * vk13;
161       vo0p2 += vi2x3 * vk23;
162       vo0p0 += vi3x3 * vk33;
163       vo0p1 += vi4x3 * vk43;
164 
165       vo0p2 += vi0x4 * vk04;
166       vo0p0 += vi1x4 * vk14;
167       vo0p1 += vi2x4 * vk24;
168       vo0p2 += vi3x4 * vk34;
169       vo0p0 += vi4x4 * vk44;
170 
171       vo0p0 += vo0p1;
172       vo0p0 += vo0p2;
173 
174       float vo0 = math_max_f32(vo0p0, vmin);
175 
176       vo0 = math_min_f32(vo0, vmax);
177 
178       *o0++ = vo0;
179     }
180     if XNN_LIKELY(w == 2 * sizeof(float)) {
181       const float vi0x3 = *i0++;
182       const float vi1x3 = *i1++;
183       const float vi2x3 = *i2++;
184       const float vi3x3 = *i3++;
185       const float vi4x3 = *i4++;
186 
187       float vo0p0 = vbias + vi0x0 * vk00;
188       float vo0p1 = vi1x0 * vk10;
189       float vo0p2 = vi2x0 * vk20;
190       vo0p0 += vi3x0 * vk30;
191       vo0p1 += vi4x0 * vk40;
192 
193       vo0p2 += vi0x1 * vk01;
194       vo0p0 += vi1x1 * vk11;
195       vo0p1 += vi2x1 * vk21;
196       vo0p2 += vi3x1 * vk31;
197       vo0p0 += vi4x1 * vk41;
198 
199       vo0p1 += vi0x2 * vk02;
200       vo0p2 += vi1x2 * vk12;
201       vo0p0 += vi2x2 * vk22;
202       vo0p1 += vi3x2 * vk32;
203       vo0p2 += vi4x2 * vk42;
204 
205       vo0p0 += vi0x3 * vk03;
206       vo0p1 += vi1x3 * vk13;
207       vo0p2 += vi2x3 * vk23;
208       vo0p0 += vi3x3 * vk33;
209       vo0p1 += vi4x3 * vk43;
210 
211       vo0p0 += vo0p1;
212       vo0p0 += vo0p2;
213 
214       float vo0 = math_max_f32(vo0p0, vmin);
215 
216       vo0 = math_min_f32(vo0, vmax);
217 
218       *o0++ = vo0;
219     } else {
220       float vo0p0 = vbias + vi0x0 * vk00;
221       float vo0p1 = vi1x0 * vk10;
222       float vo0p2 = vi2x0 * vk20;
223       vo0p0 += vi3x0 * vk30;
224       vo0p1 += vi4x0 * vk40;
225 
226       vo0p2 += vi0x1 * vk01;
227       vo0p0 += vi1x1 * vk11;
228       vo0p1 += vi2x1 * vk21;
229       vo0p2 += vi3x1 * vk31;
230       vo0p0 += vi4x1 * vk41;
231 
232       vo0p1 += vi0x2 * vk02;
233       vo0p2 += vi1x2 * vk12;
234       vo0p0 += vi2x2 * vk22;
235       vo0p1 += vi3x2 * vk32;
236       vo0p2 += vi4x2 * vk42;
237 
238       vo0p0 += vo0p1;
239       vo0p0 += vo0p2;
240 
241       float vo0 = math_max_f32(vo0p0, vmin);
242 
243       vo0 = math_min_f32(vo0, vmax);
244 
245       *o0++ = vo0;
246     }
247 
248     i0 = (const float*) ((uintptr_t) i2 - input_width);
249     i1 = (const float*) ((uintptr_t) i2);
250     i2 = (const float*) ((uintptr_t) i3);
251     i3 = (const float*) ((uintptr_t) i4);
252     i4 = (const float*) ((uintptr_t) i3 + input_width);
253 
254 
255     output_height -= 1;
256     padded_input_height -= 2;
257   } while (output_height != 0);
258 }
259