xref: /aosp_15_r20/external/XNNPACK/src/qs8-dwconv/gen/up8x9-minmax-rndnu-neon-mla8-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_mla8_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_mla8_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       const int8x8_t vi1x01234567 = vld1_s8(i1); i1 += 8;
98       const int8x8_t vk1x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
99 
100       vprod01234567 = vmlal_s8(vprod01234567, vi1x01234567, vk1x01234567);
101 
102       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
103       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
104       const int8x8_t vi2x01234567 = vld1_s8(i2); i2 += 8;
105       const int8x8_t vk2x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
106 
107       vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
108 
109       const int8x8_t vi3x01234567 = vld1_s8(i3); i3 += 8;
110       const int8x8_t vk3x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
111 
112       vprod01234567 = vmlal_s8(vprod01234567, vi3x01234567, vk3x01234567);
113 
114       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
115       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
116       const int8x8_t vi4x01234567 = vld1_s8(i4); i4 += 8;
117       const int8x8_t vk4x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
118 
119       vprod01234567 = vmull_s8(vi4x01234567, vk4x01234567);
120 
121       const int8x8_t vi5x01234567 = vld1_s8(i5); i5 += 8;
122       const int8x8_t vk5x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
123 
124       vprod01234567 = vmlal_s8(vprod01234567, vi5x01234567, vk5x01234567);
125 
126       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
127       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
128       const int8x8_t vi6x01234567 = vld1_s8(i6); i6 += 8;
129       const int8x8_t vk6x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
130 
131       vprod01234567 = vmull_s8(vi6x01234567, vk6x01234567);
132 
133       const int8x8_t vi7x01234567 = vld1_s8(i7); i7 += 8;
134       const int8x8_t vk7x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
135 
136       vprod01234567 = vmlal_s8(vprod01234567, vi7x01234567, vk7x01234567);
137 
138       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
139       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
140       const int8x8_t vi8x01234567 = vld1_s8(i8); i8 += 8;
141       const int8x8_t vk8x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
142 
143       vprod01234567 = vmull_s8(vi8x01234567, vk8x01234567);
144 
145       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
146       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
147 
148       vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
149       vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
150 
151       vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
152       vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
153 
154       vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
155       vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
156 
157 #if XNN_ARCH_ARM64
158       int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
159 
160       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
161 
162       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
163 #else  // !XNN_ARCH_ARM64
164       int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
165 
166       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
167 
168       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
169 #endif  // !XNN_ARCH_ARM64
170 
171       vout01234567 = vmax_s8(vout01234567, voutput_min);
172 
173       vout01234567 = vmin_s8(vout01234567, voutput_max);
174 
175       vst1_s8(output, vout01234567); output += 8;
176     }
177     if XNN_UNLIKELY(c != 0) {
178       {
179         int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
180         int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
181 
182         const int8x8_t vi0x01234567 = vld1_s8(i0);
183         const int8x8_t vk0x01234567 = vld1_s8(w);
184 
185         int16x8_t vprod01234567 = vmull_s8(vi0x01234567, vk0x01234567);
186 
187         const int8x8_t vi1x01234567 = vld1_s8(i1);
188         const int8x8_t vk1x01234567 = vld1_s8((const void*) ((const int8_t*) w + 8));
189 
190         vprod01234567 = vmlal_s8(vprod01234567, vi1x01234567, vk1x01234567);
191 
192         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
193         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
194         const int8x8_t vi2x01234567 = vld1_s8(i2);
195         const int8x8_t vk2x01234567 = vld1_s8((const void*) ((const int8_t*) w + 16));
196 
197         vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
198 
199         const int8x8_t vi3x01234567 = vld1_s8(i3);
200         const int8x8_t vk3x01234567 = vld1_s8((const void*) ((const int8_t*) w + 24));
201 
202         vprod01234567 = vmlal_s8(vprod01234567, vi3x01234567, vk3x01234567);
203 
204         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
205         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
206         const int8x8_t vi4x01234567 = vld1_s8(i4);
207         const int8x8_t vk4x01234567 = vld1_s8((const void*) ((const int8_t*) w + 32));
208 
209         vprod01234567 = vmull_s8(vi4x01234567, vk4x01234567);
210 
211         const int8x8_t vi5x01234567 = vld1_s8(i5);
212         const int8x8_t vk5x01234567 = vld1_s8((const void*) ((const int8_t*) w + 40));
213 
214         vprod01234567 = vmlal_s8(vprod01234567, vi5x01234567, vk5x01234567);
215 
216         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
217         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
218         const int8x8_t vi6x01234567 = vld1_s8(i6);
219         const int8x8_t vk6x01234567 = vld1_s8((const void*) ((const int8_t*) w + 48));
220 
221         vprod01234567 = vmull_s8(vi6x01234567, vk6x01234567);
222 
223         const int8x8_t vi7x01234567 = vld1_s8(i7);
224         const int8x8_t vk7x01234567 = vld1_s8((const void*) ((const int8_t*) w + 56));
225 
226         vprod01234567 = vmlal_s8(vprod01234567, vi7x01234567, vk7x01234567);
227 
228         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
229         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
230         const int8x8_t vi8x01234567 = vld1_s8(i8);
231         const int8x8_t vk8x01234567 = vld1_s8((const void*) ((const int8_t*) w + 64));
232 
233         vprod01234567 = vmull_s8(vi8x01234567, vk8x01234567);
234 
235         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
236         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
237 
238         vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
239         vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
240 
241         vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
242         vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
243 
244         vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
245         vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
246 
247 #if XNN_ARCH_ARM64
248         int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
249 #else
250         int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
251 #endif
252         vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
253 
254         int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
255         vout01234567 = vmax_s8(vout01234567, voutput_min);
256         vout01234567 = vmin_s8(vout01234567, voutput_max);
257 
258         if (c & 4) {
259           vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
260           vout01234567 = vext_s8(vout01234567, vout01234567, 4);
261         }
262         if (c & 2) {
263           vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
264           vout01234567 = vext_s8(vout01234567, vout01234567, 2);
265         }
266         if (c & 1) {
267           vst1_lane_s8(output, vout01234567, 0); output += 1;
268         }
269       }
270     }
271 
272     output = (int8_t*) ((uintptr_t) output + output_increment);
273   } while (--output_width != 0);
274 }
275