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