xref: /aosp_15_r20/external/XNNPACK/src/qs8-dwconv/gen/up8x9-minmax-rndnu-neon-mul8-ld64.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-dwconv/unipass-neon-mul8.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/dwconv.h>
15 
16 
xnn_qs8_dwconv_minmax_rndnu_ukernel_up8x9__neon_mul8_ld64(size_t channels,size_t output_width,const int8_t ** input,const void * weights,int8_t * output,size_t input_stride,size_t output_increment,size_t input_offset,const int8_t * zero,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_dwconv_minmax_rndnu_ukernel_up8x9__neon_mul8_ld64(
18     size_t channels,
19     size_t output_width,
20     const int8_t** input,
21     const void* weights,
22     int8_t* output,
23     size_t input_stride,
24     size_t output_increment,
25     size_t input_offset,
26     const int8_t* zero,
27     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
33   const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
34   const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
35   const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
36   const int8x8_t voutput_min = vld1_dup_s8(&params->rndnu_neon.output_min);
37   const int8x8_t voutput_max = vld1_dup_s8(&params->rndnu_neon.output_max);
38   do {
39     const int8_t* i0 = input[0];
40     assert(i0 != NULL);
41     if XNN_UNPREDICTABLE(i0 != zero) {
42       i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
43     }
44     const int8_t* i1 = input[1];
45     assert(i1 != NULL);
46     if XNN_UNPREDICTABLE(i1 != zero) {
47       i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
48     }
49     const int8_t* i2 = input[2];
50     assert(i2 != NULL);
51     if XNN_UNPREDICTABLE(i2 != zero) {
52       i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
53     }
54     const int8_t* i3 = input[3];
55     assert(i3 != NULL);
56     if XNN_UNPREDICTABLE(i3 != zero) {
57       i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
58     }
59     const int8_t* i4 = input[4];
60     assert(i4 != NULL);
61     if XNN_UNPREDICTABLE(i4 != zero) {
62       i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
63     }
64     const int8_t* i5 = input[5];
65     assert(i5 != NULL);
66     if XNN_UNPREDICTABLE(i5 != zero) {
67       i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
68     }
69     const int8_t* i6 = input[6];
70     assert(i6 != NULL);
71     if XNN_UNPREDICTABLE(i6 != zero) {
72       i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
73     }
74     const int8_t* i7 = input[7];
75     assert(i7 != NULL);
76     if XNN_UNPREDICTABLE(i7 != zero) {
77       i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
78     }
79     const int8_t* i8 = input[8];
80     assert(i8 != NULL);
81     if XNN_UNPREDICTABLE(i8 != zero) {
82       i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
83     }
84     input = (const int8_t**) ((uintptr_t) input + input_stride);
85 
86     size_t c = channels;
87     const void* w = weights;
88     for (; c >= 8; c -= 8) {
89       int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
90       int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
91 
92       const int8x8_t vi0x01234567 = vld1_s8(i0); i0 += 8;
93       const int8x8_t vk0x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
94 
95       int16x8_t vprod01234567 = vmull_s8(vi0x01234567, vk0x01234567);
96 
97       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
98       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
99       const int8x8_t vi1x01234567 = vld1_s8(i1); i1 += 8;
100       const int8x8_t vk1x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
101 
102       vprod01234567 = vmull_s8(vi1x01234567, vk1x01234567);
103 
104       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
105       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
106       const int8x8_t vi2x01234567 = vld1_s8(i2); i2 += 8;
107       const int8x8_t vk2x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
108 
109       vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
110 
111       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
112       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
113       const int8x8_t vi3x01234567 = vld1_s8(i3); i3 += 8;
114       const int8x8_t vk3x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
115 
116       vprod01234567 = vmull_s8(vi3x01234567, vk3x01234567);
117 
118       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
119       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
120       const int8x8_t vi4x01234567 = vld1_s8(i4); i4 += 8;
121       const int8x8_t vk4x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
122 
123       vprod01234567 = vmull_s8(vi4x01234567, vk4x01234567);
124 
125       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
126       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
127       const int8x8_t vi5x01234567 = vld1_s8(i5); i5 += 8;
128       const int8x8_t vk5x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
129 
130       vprod01234567 = vmull_s8(vi5x01234567, vk5x01234567);
131 
132       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
133       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
134       const int8x8_t vi6x01234567 = vld1_s8(i6); i6 += 8;
135       const int8x8_t vk6x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
136 
137       vprod01234567 = vmull_s8(vi6x01234567, vk6x01234567);
138 
139       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
140       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
141       const int8x8_t vi7x01234567 = vld1_s8(i7); i7 += 8;
142       const int8x8_t vk7x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
143 
144       vprod01234567 = vmull_s8(vi7x01234567, vk7x01234567);
145 
146       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
147       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
148       const int8x8_t vi8x01234567 = vld1_s8(i8); i8 += 8;
149       const int8x8_t vk8x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
150 
151       vprod01234567 = vmull_s8(vi8x01234567, vk8x01234567);
152 
153       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
154       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
155 
156       vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
157       vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
158 
159       vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
160       vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
161 
162       vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
163       vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
164 
165 #if XNN_ARCH_ARM64
166       int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
167 
168       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
169 
170       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
171 #else  // !XNN_ARCH_ARM64
172       int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
173 
174       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
175 
176       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
177 #endif  // !XNN_ARCH_ARM64
178 
179       vout01234567 = vmax_s8(vout01234567, voutput_min);
180 
181       vout01234567 = vmin_s8(vout01234567, voutput_max);
182 
183       vst1_s8(output, vout01234567); output += 8;
184     }
185     if XNN_UNLIKELY(c != 0) {
186       {
187         int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
188         int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
189 
190         const int8x8_t vi0x01234567 = vld1_s8(i0);
191         const int8x8_t vk0x01234567 = vld1_s8(w);
192 
193         int16x8_t vprod01234567 = vmull_s8(vi0x01234567, vk0x01234567);
194 
195         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
196         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
197         const int8x8_t vi1x01234567 = vld1_s8(i1);
198         const int8x8_t vk1x01234567 = vld1_s8((const void*) ((const int8_t*) w + 8));
199 
200         vprod01234567 = vmull_s8(vi1x01234567, vk1x01234567);
201 
202         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
203         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
204         const int8x8_t vi2x01234567 = vld1_s8(i2);
205         const int8x8_t vk2x01234567 = vld1_s8((const void*) ((const int8_t*) w + 16));
206 
207         vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
208 
209         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
210         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
211         const int8x8_t vi3x01234567 = vld1_s8(i3);
212         const int8x8_t vk3x01234567 = vld1_s8((const void*) ((const int8_t*) w + 24));
213 
214         vprod01234567 = vmull_s8(vi3x01234567, vk3x01234567);
215 
216         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
217         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
218         const int8x8_t vi4x01234567 = vld1_s8(i4);
219         const int8x8_t vk4x01234567 = vld1_s8((const void*) ((const int8_t*) w + 32));
220 
221         vprod01234567 = vmull_s8(vi4x01234567, vk4x01234567);
222 
223         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
224         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
225         const int8x8_t vi5x01234567 = vld1_s8(i5);
226         const int8x8_t vk5x01234567 = vld1_s8((const void*) ((const int8_t*) w + 40));
227 
228         vprod01234567 = vmull_s8(vi5x01234567, vk5x01234567);
229 
230         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
231         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
232         const int8x8_t vi6x01234567 = vld1_s8(i6);
233         const int8x8_t vk6x01234567 = vld1_s8((const void*) ((const int8_t*) w + 48));
234 
235         vprod01234567 = vmull_s8(vi6x01234567, vk6x01234567);
236 
237         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
238         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
239         const int8x8_t vi7x01234567 = vld1_s8(i7);
240         const int8x8_t vk7x01234567 = vld1_s8((const void*) ((const int8_t*) w + 56));
241 
242         vprod01234567 = vmull_s8(vi7x01234567, vk7x01234567);
243 
244         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
245         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
246         const int8x8_t vi8x01234567 = vld1_s8(i8);
247         const int8x8_t vk8x01234567 = vld1_s8((const void*) ((const int8_t*) w + 64));
248 
249         vprod01234567 = vmull_s8(vi8x01234567, vk8x01234567);
250 
251         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
252         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
253 
254         vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
255         vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
256 
257         vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
258         vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
259 
260         vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
261         vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
262 
263 #if XNN_ARCH_ARM64
264         int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
265 #else
266         int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
267 #endif
268         vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
269 
270         int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
271         vout01234567 = vmax_s8(vout01234567, voutput_min);
272         vout01234567 = vmin_s8(vout01234567, voutput_max);
273 
274         if (c & 4) {
275           vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
276           vout01234567 = vext_s8(vout01234567, vout01234567, 4);
277         }
278         if (c & 2) {
279           vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
280           vout01234567 = vext_s8(vout01234567, vout01234567, 2);
281         }
282         if (c & 1) {
283           vst1_lane_s8(output, vout01234567, 0); output += 1;
284         }
285       }
286     }
287 
288     output = (int8_t*) ((uintptr_t) output + output_increment);
289   } while (--output_width != 0);
290 }
291