xref: /aosp_15_r20/external/XNNPACK/src/f32-dwconv2d-chw/gen/3x3p1-minmax-scalar-2x1.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv2d-chw/3x3p1-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_3x3p1__scalar_2x1(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_3x3p1__scalar_2x1(
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 
31   const float vmin = params->scalar.min;
32   const float vmax = params->scalar.max;
33 
34   const float vbias = weights[0];
35   const float vk00 = weights[1];
36   const float vk01 = weights[2];
37   const float vk02 = weights[3];
38   const float vk10 = weights[4];
39   const float vk11 = weights[5];
40   const float vk12 = weights[6];
41   const float vk20 = weights[7];
42   const float vk21 = weights[8];
43   const float vk22 = weights[9];
44 
45   const float* i0 = zero;
46   const float* i1 = input;
47   const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
48   const float* i3 = (const float*) ((uintptr_t) i2 + input_width);
49 
50   float* o0 = output;
51   float* o1 = (float*) ((uintptr_t) o0 + input_width);
52 
53   size_t output_height = input_height;
54   do {
55     if XNN_UNPREDICTABLE(output_height < 2) {
56       i2 = zero;
57       o1 = o0;
58     }
59     if XNN_UNPREDICTABLE(output_height < 3) {
60       i3 = zero;
61     }
62 
63     float vi0x0 = 0.0f;
64     float vi1x0 = 0.0f;
65     float vi2x0 = 0.0f;
66     float vi3x0 = 0.0f;
67 
68     float vi0x1 = *i0++;
69     float vi1x1 = *i1++;
70     float vi2x1 = *i2++;
71     float vi3x1 = *i3++;
72 
73     size_t w = input_width;
74     for (; w > 1 * sizeof(float); w -= 1 * sizeof(float)) {
75       const float vi0x2 = *i0++;
76       const float vi1x2 = *i1++;
77       const float vi2x2 = *i2++;
78       const float vi3x2 = *i3++;
79 
80       float vo0p0 = vbias + vi0x0 * vk00;
81       float vo1p0 = vbias + vi1x0 * vk00;
82       vo0p0 += vi1x0 * vk10;
83       vo1p0 += vi2x0 * vk10;
84       vo0p0 += vi2x0 * vk20;
85       vo1p0 += vi3x0 * vk20;
86 
87       vi0x0 = vi0x1;
88       vi1x0 = vi1x1;
89       vi2x0 = vi2x1;
90       vi3x0 = vi3x1;
91 
92       vo0p0 += vi0x1 * vk01;
93       vo1p0 += vi1x1 * vk01;
94       vo0p0 += vi1x1 * vk11;
95       vo1p0 += vi2x1 * vk11;
96       vo0p0 += vi2x1 * vk21;
97       vo1p0 += vi3x1 * vk21;
98 
99       vi0x1 = vi0x2;
100       vi1x1 = vi1x2;
101       vi2x1 = vi2x2;
102       vi3x1 = vi3x2;
103 
104       vo0p0 += vi0x2 * vk02;
105       vo1p0 += vi1x2 * vk02;
106       vo0p0 += vi1x2 * vk12;
107       vo1p0 += vi2x2 * vk12;
108       vo0p0 += vi2x2 * vk22;
109       vo1p0 += vi3x2 * vk22;
110 
111 
112       float vo0 = math_max_f32(vo0p0, vmin);
113       float vo1 = math_max_f32(vo1p0, vmin);
114 
115       vo0 = math_min_f32(vo0, vmax);
116       vo1 = math_min_f32(vo1, vmax);
117 
118       *o1++ = vo1;
119       *o0++ = vo0;
120     }
121     // Always process the last pixel separately to account for right edge.
122     assert(w == 1 * sizeof(float));
123     {
124       float vo0p0 = vbias + vi0x0 * vk00;
125       float vo1p0 = vbias + vi1x0 * vk00;
126       vo0p0 += vi1x0 * vk10;
127       vo1p0 += vi2x0 * vk10;
128       vo0p0 += vi2x0 * vk20;
129       vo1p0 += vi3x0 * vk20;
130 
131       vo0p0 += vi0x1 * vk01;
132       vo1p0 += vi1x1 * vk01;
133       vo0p0 += vi1x1 * vk11;
134       vo1p0 += vi2x1 * vk11;
135       vo0p0 += vi2x1 * vk21;
136       vo1p0 += vi3x1 * vk21;
137 
138 
139       float vo0 = math_max_f32(vo0p0, vmin);
140       float vo1 = math_max_f32(vo1p0, vmin);
141 
142       vo0 = math_min_f32(vo0, vmax);
143       vo1 = math_min_f32(vo1, vmax);
144 
145       *o1++ = vo1;
146       *o0++ = vo0;
147     }
148 
149     i0 = (const float*) ((uintptr_t) i2 - input_width);
150     i1 = (const float*) ((uintptr_t) i3 - input_width);
151     i2 = (const float*) ((uintptr_t) i1 + input_width);
152     i3 = (const float*) ((uintptr_t) i2 + input_width);
153 
154     o0 = o1;
155     o1 = (float*) ((uintptr_t) o0 + input_width);
156 
157     output_height = doz(output_height, 2);
158   } while (output_height != 0);
159 }
160