1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gavgpool/unipass-neon.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 <arm_neon.h>
13
14 #include <xnnpack/gavgpool.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16
17
xnn_qu8_gavgpool_minmax_fp32_ukernel_7x__neonv8_c32(size_t rows,size_t channels,const uint8_t * input,size_t input_stride,const uint8_t * zero,uint8_t * output,const union xnn_qu8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_gavgpool_minmax_fp32_ukernel_7x__neonv8_c32(
19 size_t rows,
20 size_t channels,
21 const uint8_t* input,
22 size_t input_stride,
23 const uint8_t* zero,
24 uint8_t* output,
25 const union xnn_qu8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
26 {
27 assert(rows != 0);
28 assert(rows <= 7);
29 assert(channels != 0);
30
31 const uint8_t* i0 = input;
32 const uint8_t* i1 = (const uint8_t*) ((uintptr_t) i0 + input_stride);
33 if XNN_UNPREDICTABLE(rows < 2) {
34 i1 = zero;
35 }
36 const uint8_t* i2 = (const uint8_t*) ((uintptr_t) i1 + input_stride);
37 if XNN_UNPREDICTABLE(rows <= 2) {
38 i2 = zero;
39 }
40 const uint8_t* i3 = (const uint8_t*) ((uintptr_t) i2 + input_stride);
41 if XNN_UNPREDICTABLE(rows < 4) {
42 i3 = zero;
43 }
44 const uint8_t* i4 = (const uint8_t*) ((uintptr_t) i3 + input_stride);
45 if XNN_UNPREDICTABLE(rows <= 4) {
46 i4 = zero;
47 }
48 const uint8_t* i5 = (const uint8_t*) ((uintptr_t) i4 + input_stride);
49 if XNN_UNPREDICTABLE(rows < 6) {
50 i5 = zero;
51 }
52 const uint8_t* i6 = (const uint8_t*) ((uintptr_t) i5 + input_stride);
53 if XNN_UNPREDICTABLE(rows <= 6) {
54 i6 = zero;
55 }
56
57 const int32x4_t vinit_bias = vld1q_dup_s32(¶ms->fp32_neonv8.init_bias);
58 const float32x4_t vscale = vld1q_dup_f32(¶ms->fp32_neonv8.scale);
59 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point);
60 const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->fp32_neonv8.output_min);
61 const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->fp32_neonv8.output_max);
62 for (; channels >= 32; channels -= 32) {
63 const uint8x8_t vi0x01234567 = vld1_u8(i0); i0 += 8;
64 const uint8x8_t vi0x89ABCDEF = vld1_u8(i0); i0 += 8;
65 const uint8x8_t vi0xGHIJKLMN = vld1_u8(i0); i0 += 8;
66 const uint8x8_t vi0xOPQRSTUV = vld1_u8(i0); i0 += 8;
67 const uint8x8_t vi1x01234567 = vld1_u8(i1); i1 += 8;
68 const uint8x8_t vi1x89ABCDEF = vld1_u8(i1); i1 += 8;
69 const uint8x8_t vi1xGHIJKLMN = vld1_u8(i1); i1 += 8;
70 const uint8x8_t vi1xOPQRSTUV = vld1_u8(i1); i1 += 8;
71
72 const uint8x8_t vi2x01234567 = vld1_u8(i2); i2 += 8;
73 uint16x8_t vsum01234567 = vaddl_u8(vi0x01234567, vi1x01234567);
74 const uint8x8_t vi2x89ABCDEF = vld1_u8(i2); i2 += 8;
75 uint16x8_t vsum89ABCDEF = vaddl_u8(vi0x89ABCDEF, vi1x89ABCDEF);
76 const uint8x8_t vi2xGHIJKLMN = vld1_u8(i2); i2 += 8;
77 uint16x8_t vsumGHIJKLMN = vaddl_u8(vi0xGHIJKLMN, vi1xGHIJKLMN);
78 const uint8x8_t vi2xOPQRSTUV = vld1_u8(i2); i2 += 8;
79 uint16x8_t vsumOPQRSTUV = vaddl_u8(vi0xOPQRSTUV, vi1xOPQRSTUV);
80
81 const uint8x8_t vi3x01234567 = vld1_u8(i3); i3 += 8;
82 vsum01234567 = vaddw_u8(vsum01234567, vi2x01234567);
83 const uint8x8_t vi3x89ABCDEF = vld1_u8(i3); i3 += 8;
84 vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi2x89ABCDEF);
85 const uint8x8_t vi3xGHIJKLMN = vld1_u8(i3); i3 += 8;
86 vsumGHIJKLMN = vaddw_u8(vsumGHIJKLMN, vi2xGHIJKLMN);
87 const uint8x8_t vi3xOPQRSTUV = vld1_u8(i3); i3 += 8;
88 vsumOPQRSTUV = vaddw_u8(vsumOPQRSTUV, vi2xOPQRSTUV);
89 const uint8x8_t vi4x01234567 = vld1_u8(i4); i4 += 8;
90 vsum01234567 = vaddw_u8(vsum01234567, vi3x01234567);
91 const uint8x8_t vi4x89ABCDEF = vld1_u8(i4); i4 += 8;
92 vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi3x89ABCDEF);
93 const uint8x8_t vi4xGHIJKLMN = vld1_u8(i4); i4 += 8;
94 vsumGHIJKLMN = vaddw_u8(vsumGHIJKLMN, vi3xGHIJKLMN);
95 const uint8x8_t vi4xOPQRSTUV = vld1_u8(i4); i4 += 8;
96 vsumOPQRSTUV = vaddw_u8(vsumOPQRSTUV, vi3xOPQRSTUV);
97 const uint8x8_t vi5x01234567 = vld1_u8(i5); i5 += 8;
98 vsum01234567 = vaddw_u8(vsum01234567, vi4x01234567);
99 const uint8x8_t vi5x89ABCDEF = vld1_u8(i5); i5 += 8;
100 vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi4x89ABCDEF);
101 const uint8x8_t vi5xGHIJKLMN = vld1_u8(i5); i5 += 8;
102 vsumGHIJKLMN = vaddw_u8(vsumGHIJKLMN, vi4xGHIJKLMN);
103 const uint8x8_t vi5xOPQRSTUV = vld1_u8(i5); i5 += 8;
104 vsumOPQRSTUV = vaddw_u8(vsumOPQRSTUV, vi4xOPQRSTUV);
105 const uint8x8_t vi6x01234567 = vld1_u8(i6); i6 += 8;
106 vsum01234567 = vaddw_u8(vsum01234567, vi5x01234567);
107 const uint8x8_t vi6x89ABCDEF = vld1_u8(i6); i6 += 8;
108 vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi5x89ABCDEF);
109 const uint8x8_t vi6xGHIJKLMN = vld1_u8(i6); i6 += 8;
110 vsumGHIJKLMN = vaddw_u8(vsumGHIJKLMN, vi5xGHIJKLMN);
111 const uint8x8_t vi6xOPQRSTUV = vld1_u8(i6); i6 += 8;
112 vsumOPQRSTUV = vaddw_u8(vsumOPQRSTUV, vi5xOPQRSTUV);
113 vsum01234567 = vaddw_u8(vsum01234567, vi6x01234567);
114 vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi6x89ABCDEF);
115 vsumGHIJKLMN = vaddw_u8(vsumGHIJKLMN, vi6xGHIJKLMN);
116 vsumOPQRSTUV = vaddw_u8(vsumOPQRSTUV, vi6xOPQRSTUV);
117
118 int32x4_t vacc0123 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsum01234567)));
119 int32x4_t vacc4567 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsum01234567)));
120 int32x4_t vacc89AB = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsum89ABCDEF)));
121 int32x4_t vaccCDEF = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsum89ABCDEF)));
122 int32x4_t vaccGHIJ = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsumGHIJKLMN)));
123 int32x4_t vaccKLMN = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsumGHIJKLMN)));
124 int32x4_t vaccOPQR = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsumOPQRSTUV)));
125 int32x4_t vaccSTUV = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsumOPQRSTUV)));
126
127 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
128 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
129 float32x4_t vfpacc89AB = vcvtq_f32_s32(vacc89AB);
130 float32x4_t vfpaccCDEF = vcvtq_f32_s32(vaccCDEF);
131 float32x4_t vfpaccGHIJ = vcvtq_f32_s32(vaccGHIJ);
132 float32x4_t vfpaccKLMN = vcvtq_f32_s32(vaccKLMN);
133 float32x4_t vfpaccOPQR = vcvtq_f32_s32(vaccOPQR);
134 float32x4_t vfpaccSTUV = vcvtq_f32_s32(vaccSTUV);
135
136 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
137 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
138 vfpacc89AB = vmulq_f32(vfpacc89AB, vscale);
139 vfpaccCDEF = vmulq_f32(vfpaccCDEF, vscale);
140 vfpaccGHIJ = vmulq_f32(vfpaccGHIJ, vscale);
141 vfpaccKLMN = vmulq_f32(vfpaccKLMN, vscale);
142 vfpaccOPQR = vmulq_f32(vfpaccOPQR, vscale);
143 vfpaccSTUV = vmulq_f32(vfpaccSTUV, vscale);
144
145 vacc0123 = vcvtnq_s32_f32(vfpacc0123);
146 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
147 vacc89AB = vcvtnq_s32_f32(vfpacc89AB);
148 vaccCDEF = vcvtnq_s32_f32(vfpaccCDEF);
149 vaccGHIJ = vcvtnq_s32_f32(vfpaccGHIJ);
150 vaccKLMN = vcvtnq_s32_f32(vfpaccKLMN);
151 vaccOPQR = vcvtnq_s32_f32(vfpaccOPQR);
152 vaccSTUV = vcvtnq_s32_f32(vfpaccSTUV);
153
154 #if XNN_ARCH_ARM64
155 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
156 int16x8_t vacc89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc89AB), vaccCDEF);
157 int16x8_t vaccGHIJKLMN = vqmovn_high_s32(vqmovn_s32(vaccGHIJ), vaccKLMN);
158 int16x8_t vaccOPQRSTUV = vqmovn_high_s32(vqmovn_s32(vaccOPQR), vaccSTUV);
159 #else // !XNN_ARCH_ARM64
160 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
161 int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
162 int16x8_t vaccGHIJKLMN = vcombine_s16(vqmovn_s32(vaccGHIJ), vqmovn_s32(vaccKLMN));
163 int16x8_t vaccOPQRSTUV = vcombine_s16(vqmovn_s32(vaccOPQR), vqmovn_s32(vaccSTUV));
164 #endif // !XNN_ARCH_ARM64
165
166 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
167 vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
168 vaccGHIJKLMN = vqaddq_s16(vaccGHIJKLMN, voutput_zero_point);
169 vaccOPQRSTUV = vqaddq_s16(vaccOPQRSTUV, voutput_zero_point);
170
171 #if XNN_ARCH_ARM64
172 uint8x16_t vout0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc01234567), vacc89ABCDEF);
173 uint8x16_t voutGHIJKLMNOPQRSTUV = vqmovun_high_s16(vqmovun_s16(vaccGHIJKLMN), vaccOPQRSTUV);
174 #else // !XNN_ARCH_ARM64
175 uint8x16_t vout0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc01234567), vqmovun_s16(vacc89ABCDEF));
176 uint8x16_t voutGHIJKLMNOPQRSTUV = vcombine_u8(vqmovun_s16(vaccGHIJKLMN), vqmovun_s16(vaccOPQRSTUV));
177 #endif // !XNN_ARCH_ARM64
178
179 vout0123456789ABCDEF = vmaxq_u8(vout0123456789ABCDEF, voutput_min);
180 voutGHIJKLMNOPQRSTUV = vmaxq_u8(voutGHIJKLMNOPQRSTUV, voutput_min);
181
182 vout0123456789ABCDEF = vminq_u8(vout0123456789ABCDEF, voutput_max);
183 voutGHIJKLMNOPQRSTUV = vminq_u8(voutGHIJKLMNOPQRSTUV, voutput_max);
184
185 vst1q_u8(output, vout0123456789ABCDEF); output += 16;
186 vst1q_u8(output, voutGHIJKLMNOPQRSTUV); output += 16;
187 }
188 if XNN_UNLIKELY(channels != 0) {
189 do {
190 const uint8x8_t vi0x01234567 = vld1_u8(i0); i0 += 8;
191 const uint8x8_t vi1x01234567 = vld1_u8(i1); i1 += 8;
192 const uint8x8_t vi2x01234567 = vld1_u8(i2); i2 += 8;
193 uint16x8_t vsum01234567 = vaddl_u8(vi0x01234567, vi1x01234567);
194
195 const uint8x8_t vi3x01234567 = vld1_u8(i3); i3 += 8;
196 vsum01234567 = vaddw_u8(vsum01234567, vi2x01234567);
197 const uint8x8_t vi4x01234567 = vld1_u8(i4); i4 += 8;
198 vsum01234567 = vaddw_u8(vsum01234567, vi3x01234567);
199 const uint8x8_t vi5x01234567 = vld1_u8(i5); i5 += 8;
200 vsum01234567 = vaddw_u8(vsum01234567, vi4x01234567);
201 const uint8x8_t vi6x01234567 = vld1_u8(i6); i6 += 8;
202 vsum01234567 = vaddw_u8(vsum01234567, vi5x01234567);
203 vsum01234567 = vaddw_u8(vsum01234567, vi6x01234567);
204
205 int32x4_t vacc0123 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsum01234567)));
206 int32x4_t vacc4567 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsum01234567)));
207
208 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
209 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
210
211 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
212 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
213
214 vacc0123 = vcvtnq_s32_f32(vfpacc0123);
215 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
216
217 #if XNN_ARCH_ARM64
218 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
219 #else
220 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
221 #endif
222 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
223
224 uint8x8_t vout01234567 = vqmovun_s16(vacc01234567);
225 vout01234567 = vmax_u8(vout01234567, vget_low_u8(voutput_min));
226 vout01234567 = vmin_u8(vout01234567, vget_low_u8(voutput_max));
227
228 if XNN_LIKELY(channels >= 8) {
229 vst1_u8(output, vout01234567); output += 8;
230 channels -= 8;
231 } else {
232 if (channels & 4) {
233 vst1_lane_u32((void*) output, vreinterpret_u32_u8(vout01234567), 0); output += 4;
234 vout01234567 = vext_u8(vout01234567, vout01234567, 4);
235 }
236 if (channels & 2) {
237 vst1_lane_u16((void*) output, vreinterpret_u16_u8(vout01234567), 0); output += 2;
238 vout01234567 = vext_u8(vout01234567, vout01234567, 2);
239 }
240 if (channels & 1) {
241 vst1_lane_u8(output, vout01234567, 0); output += 1;
242 }
243 channels = 0;
244 }
245 } while (channels != 0);
246 }
247 }
248