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_acc4(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_acc4(
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 float vo0p1 = vi1x0 * vk10;
73 float vo0p2 = vi2x0 * vk20;
74
75 vi0x0 = vi0x1;
76 vi1x0 = vi1x1;
77 vi2x0 = vi2x1;
78
79 float vo0p3 = vi0x1 * vk01;
80 vo0p0 += vi1x1 * vk11;
81 vo0p1 += vi2x1 * vk21;
82
83 vi0x1 = vi0x2;
84 vi1x1 = vi1x2;
85 vi2x1 = vi2x2;
86
87 vo0p2 += vi0x2 * vk02;
88 vo0p3 += vi1x2 * vk12;
89 vo0p0 += vi2x2 * vk22;
90
91 vo0p0 += vo0p1;
92 vo0p2 += vo0p3;
93 vo0p0 += vo0p2;
94
95 float vo0 = math_max_f32(vo0p0, vmin);
96
97 vo0 = math_min_f32(vo0, vmax);
98
99 *o0++ = vo0;
100 }
101 // Always process the last pixel separately to account for right edge.
102 assert(w == 1 * sizeof(float));
103 {
104 float vo0p0 = vbias + vi0x0 * vk00;
105 float vo0p1 = vi1x0 * vk10;
106 float vo0p2 = vi2x0 * vk20;
107
108 float vo0p3 = vi0x1 * vk01;
109 vo0p0 += vi1x1 * vk11;
110 vo0p1 += vi2x1 * vk21;
111
112 vo0p0 += vo0p1;
113 vo0p2 += vo0p3;
114 vo0p0 += vo0p2;
115
116 float vo0 = math_max_f32(vo0p0, vmin);
117
118 vo0 = math_min_f32(vo0, vmax);
119
120 *o0++ = vo0;
121 }
122
123 i0 = (const float*) ((uintptr_t) i1 - input_width);
124
125
126 } while (--output_height != 0);
127 }
128