xref: /aosp_15_r20/external/XNNPACK/src/f32-dwconv2d-chw/gen/3x3p1-minmax-scalar-1x1.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_1x1(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_1x1(
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 
49   float* o0 = output;
50 
51   size_t output_height = input_height;
52   do {
53     if XNN_UNPREDICTABLE(output_height < 2) {
54       i2 = zero;
55     }
56 
57     float vi0x0 = 0.0f;
58     float vi1x0 = 0.0f;
59     float vi2x0 = 0.0f;
60 
61     float vi0x1 = *i0++;
62     float vi1x1 = *i1++;
63     float vi2x1 = *i2++;
64 
65     size_t w = input_width;
66     for (; w > 1 * sizeof(float); w -= 1 * sizeof(float)) {
67       const float vi0x2 = *i0++;
68       const float vi1x2 = *i1++;
69       const float vi2x2 = *i2++;
70 
71       float vo0p0 = vbias + vi0x0 * vk00;
72       vo0p0 += vi1x0 * vk10;
73       vo0p0 += vi2x0 * vk20;
74 
75       vi0x0 = vi0x1;
76       vi1x0 = vi1x1;
77       vi2x0 = vi2x1;
78 
79       vo0p0 += vi0x1 * vk01;
80       vo0p0 += vi1x1 * vk11;
81       vo0p0 += vi2x1 * vk21;
82 
83       vi0x1 = vi0x2;
84       vi1x1 = vi1x2;
85       vi2x1 = vi2x2;
86 
87       vo0p0 += vi0x2 * vk02;
88       vo0p0 += vi1x2 * vk12;
89       vo0p0 += vi2x2 * vk22;
90 
91 
92       float vo0 = math_max_f32(vo0p0, vmin);
93 
94       vo0 = math_min_f32(vo0, vmax);
95 
96       *o0++ = vo0;
97     }
98     // Always process the last pixel separately to account for right edge.
99     assert(w == 1 * sizeof(float));
100     {
101       float vo0p0 = vbias + vi0x0 * vk00;
102       vo0p0 += vi1x0 * vk10;
103       vo0p0 += vi2x0 * vk20;
104 
105       vo0p0 += vi0x1 * vk01;
106       vo0p0 += vi1x1 * vk11;
107       vo0p0 += vi2x1 * vk21;
108 
109 
110       float vo0 = math_max_f32(vo0p0, vmin);
111 
112       vo0 = math_min_f32(vo0, vmax);
113 
114       *o0++ = vo0;
115     }
116 
117     i0 = (const float*) ((uintptr_t) i1 - input_width);
118 
119 
120   } while (--output_height != 0);
121 }
122