1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gavgpool/multipass-scalar.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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/gavgpool.h>
13 #include <xnnpack/math.h>
14
15
xnn_qs8_gavgpool_minmax_fp32_ukernel_7p7x__scalar_fmagic_c2(size_t rows,size_t channels,const int8_t * input,size_t input_stride,const int8_t * zero,int32_t * buffer,int8_t * output,const union xnn_qs8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qs8_gavgpool_minmax_fp32_ukernel_7p7x__scalar_fmagic_c2(
17 size_t rows,
18 size_t channels,
19 const int8_t* input,
20 size_t input_stride,
21 const int8_t* zero,
22 int32_t* buffer,
23 int8_t* output,
24 const union xnn_qs8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26 assert(rows > 7);
27 assert(channels != 0);
28
29 const int8_t* i0 = input;
30 const int8_t* i1 = (const int8_t*) ((uintptr_t) i0 + input_stride);
31 const int8_t* i2 = (const int8_t*) ((uintptr_t) i1 + input_stride);
32 const int8_t* i3 = (const int8_t*) ((uintptr_t) i2 + input_stride);
33 const int8_t* i4 = (const int8_t*) ((uintptr_t) i3 + input_stride);
34 const int8_t* i5 = (const int8_t*) ((uintptr_t) i4 + input_stride);
35 const int8_t* i6 = (const int8_t*) ((uintptr_t) i5 + input_stride);
36 const size_t input_increment = 7 * input_stride - round_up_po2(channels, 2) * sizeof(int8_t);
37
38 const int32_t vinit_bias = params->fp32_scalar_fmagic.init_bias;
39 int32_t* b = buffer;
40 for (ptrdiff_t c = (ptrdiff_t) channels; c > 0; c -= 2) {
41 const int32_t vi0x0 = (int32_t) i0[0];
42 const int32_t vi0x1 = (int32_t) i0[1];
43 i0 += 2;
44
45 int32_t vacc0 = vi0x0 + vinit_bias;
46 const int32_t vi1x0 = (int32_t) i1[0];
47 int32_t vacc1 = vi0x1 + vinit_bias;
48 const int32_t vi1x1 = (int32_t) i1[1];
49 i1 += 2;
50
51 vacc0 += vi1x0;
52 const int32_t vi2x0 = (int32_t) i2[0];
53 vacc1 += vi1x1;
54 const int32_t vi2x1 = (int32_t) i2[1];
55 i2 += 2;
56 vacc0 += vi2x0;
57 const int32_t vi3x0 = (int32_t) i3[0];
58 vacc1 += vi2x1;
59 const int32_t vi3x1 = (int32_t) i3[1];
60 i3 += 2;
61 vacc0 += vi3x0;
62 const int32_t vi4x0 = (int32_t) i4[0];
63 vacc1 += vi3x1;
64 const int32_t vi4x1 = (int32_t) i4[1];
65 i4 += 2;
66 vacc0 += vi4x0;
67 const int32_t vi5x0 = (int32_t) i5[0];
68 vacc1 += vi4x1;
69 const int32_t vi5x1 = (int32_t) i5[1];
70 i5 += 2;
71 vacc0 += vi5x0;
72 const int32_t vi6x0 = (int32_t) i6[0];
73 vacc1 += vi5x1;
74 const int32_t vi6x1 = (int32_t) i6[1];
75 i6 += 2;
76
77 vacc0 += vi6x0;
78 vacc1 += vi6x1;
79
80 b[0] = vacc0;
81 b[1] = vacc1;
82 b += 2;
83 }
84
85 for (rows -= 7; rows > 7; rows -= 7) {
86 i0 = (const int8_t*) ((uintptr_t) i0 + input_increment);
87 i1 = (const int8_t*) ((uintptr_t) i1 + input_increment);
88 i2 = (const int8_t*) ((uintptr_t) i2 + input_increment);
89 i3 = (const int8_t*) ((uintptr_t) i3 + input_increment);
90 i4 = (const int8_t*) ((uintptr_t) i4 + input_increment);
91 i5 = (const int8_t*) ((uintptr_t) i5 + input_increment);
92 i6 = (const int8_t*) ((uintptr_t) i6 + input_increment);
93
94 int32_t* b = buffer;
95 for (ptrdiff_t c = (ptrdiff_t) channels; c > 0; c -= 2) {
96 int32_t vacc0 = b[0];
97 const int32_t vi0x0 = (int32_t) i0[0];
98 int32_t vacc1 = b[1];
99 const int32_t vi0x1 = (int32_t) i0[1];
100 i0 += 2;
101
102 vacc0 += vi0x0;
103 const int32_t vi1x0 = (int32_t) i1[0];
104 vacc1 += vi0x1;
105 const int32_t vi1x1 = (int32_t) i1[1];
106 i1 += 2;
107 vacc0 += vi1x0;
108 const int32_t vi2x0 = (int32_t) i2[0];
109 vacc1 += vi1x1;
110 const int32_t vi2x1 = (int32_t) i2[1];
111 i2 += 2;
112 vacc0 += vi2x0;
113 const int32_t vi3x0 = (int32_t) i3[0];
114 vacc1 += vi2x1;
115 const int32_t vi3x1 = (int32_t) i3[1];
116 i3 += 2;
117 vacc0 += vi3x0;
118 const int32_t vi4x0 = (int32_t) i4[0];
119 vacc1 += vi3x1;
120 const int32_t vi4x1 = (int32_t) i4[1];
121 i4 += 2;
122 vacc0 += vi4x0;
123 const int32_t vi5x0 = (int32_t) i5[0];
124 vacc1 += vi4x1;
125 const int32_t vi5x1 = (int32_t) i5[1];
126 i5 += 2;
127 vacc0 += vi5x0;
128 const int32_t vi6x0 = (int32_t) i6[0];
129 vacc1 += vi5x1;
130 const int32_t vi6x1 = (int32_t) i6[1];
131 i6 += 2;
132
133 vacc0 += vi6x0;
134 vacc1 += vi6x1;
135
136 b[0] = vacc0;
137 b[1] = vacc1;
138 b += 2;
139 }
140 }
141
142 i0 = (const int8_t*) ((uintptr_t) i0 + input_increment);
143 i1 = (const int8_t*) ((uintptr_t) i1 + input_increment);
144 if XNN_UNPREDICTABLE(rows < 2) {
145 i1 = zero;
146 }
147 i2 = (const int8_t*) ((uintptr_t) i2 + input_increment);
148 if XNN_UNPREDICTABLE(rows <= 2) {
149 i2 = zero;
150 }
151 i3 = (const int8_t*) ((uintptr_t) i3 + input_increment);
152 if XNN_UNPREDICTABLE(rows < 4) {
153 i3 = zero;
154 }
155 i4 = (const int8_t*) ((uintptr_t) i4 + input_increment);
156 if XNN_UNPREDICTABLE(rows <= 4) {
157 i4 = zero;
158 }
159 i5 = (const int8_t*) ((uintptr_t) i5 + input_increment);
160 if XNN_UNPREDICTABLE(rows < 6) {
161 i5 = zero;
162 }
163 i6 = (const int8_t*) ((uintptr_t) i6 + input_increment);
164 if XNN_UNPREDICTABLE(rows <= 6) {
165 i6 = zero;
166 }
167
168 const float vscale = params->fp32_scalar_fmagic.scale;
169 const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point;
170 const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point;
171 const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias;
172 const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point;
173 for (; channels >= 2; channels -= 2) {
174 int32_t vacc0 = buffer[0];
175 const int32_t vi0x0 = (int32_t) i0[0];
176 int32_t vacc1 = buffer[1];
177 const int32_t vi0x1 = (int32_t) i0[1];
178 buffer += 2;
179 i0 += 2;
180
181 vacc0 += vi0x0;
182 const int32_t vi1x0 = (int32_t) i1[0];
183 vacc1 += vi0x1;
184 const int32_t vi1x1 = (int32_t) i1[1];
185 i1 += 2;
186 vacc0 += vi1x0;
187 const int32_t vi2x0 = (int32_t) i2[0];
188 vacc1 += vi1x1;
189 const int32_t vi2x1 = (int32_t) i2[1];
190 i2 += 2;
191 vacc0 += vi2x0;
192 const int32_t vi3x0 = (int32_t) i3[0];
193 vacc1 += vi2x1;
194 const int32_t vi3x1 = (int32_t) i3[1];
195 i3 += 2;
196 vacc0 += vi3x0;
197 const int32_t vi4x0 = (int32_t) i4[0];
198 vacc1 += vi3x1;
199 const int32_t vi4x1 = (int32_t) i4[1];
200 i4 += 2;
201 vacc0 += vi4x0;
202 const int32_t vi5x0 = (int32_t) i5[0];
203 vacc1 += vi4x1;
204 const int32_t vi5x1 = (int32_t) i5[1];
205 i5 += 2;
206 vacc0 += vi5x0;
207 const int32_t vi6x0 = (int32_t) i6[0];
208 vacc1 += vi5x1;
209 const int32_t vi6x1 = (int32_t) i6[1];
210 i6 += 2;
211
212 vacc0 += vi6x0;
213 vacc1 += vi6x1;
214
215 float vfpacc0 = (float) vacc0 * vscale;
216 float vfpacc1 = (float) vacc1 * vscale;
217
218 vfpacc0 = math_max_f32(vfpacc0, voutput_min_less_zero_point);
219 vfpacc1 = math_max_f32(vfpacc1, voutput_min_less_zero_point);
220
221 vfpacc0 = math_min_f32(vfpacc0, voutput_max_less_zero_point);
222 vfpacc1 = math_min_f32(vfpacc1, voutput_max_less_zero_point);
223
224 vfpacc0 += vmagic_bias;
225 vfpacc1 += vmagic_bias;
226
227 int32_t vout0 = (int32_t) float_as_uint32(vfpacc0) - vmagic_bias_less_output_zero_point;
228 int32_t vout1 = (int32_t) float_as_uint32(vfpacc1) - vmagic_bias_less_output_zero_point;
229
230 output[0] = (int8_t) vout0;
231 output[1] = (int8_t) vout1;
232 output += 2;
233 }
234 if XNN_UNLIKELY(channels != 0) {
235 int32_t vacc = *buffer;
236 const int32_t vi0 = (int32_t) *i0;
237 const int32_t vi1 = (int32_t) *i1;
238
239 vacc += vi0;
240 const int32_t vi2 = (int32_t) *i2;
241 vacc += vi1;
242 const int32_t vi3 = (int32_t) *i3;
243 vacc += vi2;
244 const int32_t vi4 = (int32_t) *i4;
245 vacc += vi3;
246 const int32_t vi5 = (int32_t) *i5;
247 vacc += vi4;
248 const int32_t vi6 = (int32_t) *i6;
249
250 vacc += vi5;
251 vacc += vi6;
252
253 float vfpacc = (float) vacc * vscale;
254 vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
255 vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
256 vfpacc += vmagic_bias;
257 int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_zero_point;
258
259 *output = (int8_t) vout;
260 }
261 }
262