xref: /aosp_15_r20/external/XNNPACK/src/qu8-dwconv/gen/up8x9-minmax-fp32-neonv8-mul16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-dwconv/unipass-neon-mul16.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 #include <xnnpack/intrinsics-polyfill.h>
16 
17 
xnn_qu8_dwconv_minmax_fp32_ukernel_up8x9__neonv8_mul16(size_t channels,size_t output_width,const uint8_t ** input,const void * weights,uint8_t * output,size_t input_stride,size_t output_increment,size_t input_offset,const uint8_t * zero,const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_dwconv_minmax_fp32_ukernel_up8x9__neonv8_mul16(
19     size_t channels,
20     size_t output_width,
21     const uint8_t** input,
22     const void* weights,
23     uint8_t* output,
24     size_t input_stride,
25     size_t output_increment,
26     size_t input_offset,
27     const uint8_t* zero,
28     const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
29 {
30   assert(channels != 0);
31   assert(output_width != 0);
32 
33   const uint8x8_t vkernel_zero_point = vld1_dup_u8(params->fp32_neonv8.kernel_zero_point);
34   const float32x4_t vscale = vld1q_dup_f32(&params->fp32_neonv8.scale);
35   const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
36   const uint8x8_t voutput_min = vld1_dup_u8(&params->fp32_neonv8.output_min);
37   const uint8x8_t voutput_max = vld1_dup_u8(&params->fp32_neonv8.output_max);
38   do {
39     const uint8_t* i0 = input[0];
40     assert(i0 != NULL);
41     if XNN_UNPREDICTABLE(i0 != zero) {
42       i0 = (const uint8_t*) ((uintptr_t) i0 + input_offset);
43     }
44     const uint8_t* i1 = input[1];
45     assert(i1 != NULL);
46     if XNN_UNPREDICTABLE(i1 != zero) {
47       i1 = (const uint8_t*) ((uintptr_t) i1 + input_offset);
48     }
49     const uint8_t* i2 = input[2];
50     assert(i2 != NULL);
51     if XNN_UNPREDICTABLE(i2 != zero) {
52       i2 = (const uint8_t*) ((uintptr_t) i2 + input_offset);
53     }
54     const uint8_t* i3 = input[3];
55     assert(i3 != NULL);
56     if XNN_UNPREDICTABLE(i3 != zero) {
57       i3 = (const uint8_t*) ((uintptr_t) i3 + input_offset);
58     }
59     const uint8_t* i4 = input[4];
60     assert(i4 != NULL);
61     if XNN_UNPREDICTABLE(i4 != zero) {
62       i4 = (const uint8_t*) ((uintptr_t) i4 + input_offset);
63     }
64     const uint8_t* i5 = input[5];
65     assert(i5 != NULL);
66     if XNN_UNPREDICTABLE(i5 != zero) {
67       i5 = (const uint8_t*) ((uintptr_t) i5 + input_offset);
68     }
69     const uint8_t* i6 = input[6];
70     assert(i6 != NULL);
71     if XNN_UNPREDICTABLE(i6 != zero) {
72       i6 = (const uint8_t*) ((uintptr_t) i6 + input_offset);
73     }
74     const uint8_t* i7 = input[7];
75     assert(i7 != NULL);
76     if XNN_UNPREDICTABLE(i7 != zero) {
77       i7 = (const uint8_t*) ((uintptr_t) i7 + input_offset);
78     }
79     const uint8_t* i8 = input[8];
80     assert(i8 != NULL);
81     if XNN_UNPREDICTABLE(i8 != zero) {
82       i8 = (const uint8_t*) ((uintptr_t) i8 + input_offset);
83     }
84     input = (const uint8_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 
93       const int16x8_t vi0x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i0))); i0 += 8;
94       const int16x8_t vk0x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
95 
96       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
97       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
98 
99       const int16x8_t vi1x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i1))); i1 += 8;
100       const int16x8_t vk1x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
101 
102       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
103       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
104 
105       const int16x8_t vi2x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i2))); i2 += 8;
106       const int16x8_t vk2x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
107 
108       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
109       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
110 
111       const int16x8_t vi3x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i3))); i3 += 8;
112       const int16x8_t vk3x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
113 
114       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
115       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
116 
117       const int16x8_t vi4x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i4))); i4 += 8;
118       const int16x8_t vk4x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
119 
120       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
121       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
122 
123       const int16x8_t vi5x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i5))); i5 += 8;
124       const int16x8_t vk5x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
125 
126       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
127       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
128 
129       const int16x8_t vi6x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i6))); i6 += 8;
130       const int16x8_t vk6x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
131 
132       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567));
133       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567));
134 
135       const int16x8_t vi7x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i7))); i7 += 8;
136       const int16x8_t vk7x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
137 
138       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi7x01234567), vget_low_s16(vk7x01234567));
139       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi7x01234567), vget_high_s16(vk7x01234567));
140 
141       const int16x8_t vi8x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i8))); i8 += 8;
142       const int16x8_t vk8x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point)); w = (const void*) ((const uint8_t*) w + 8);
143 
144       vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi8x01234567), vget_low_s16(vk8x01234567));
145       vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi8x01234567), vget_high_s16(vk8x01234567));
146 
147       float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
148       float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
149 
150       vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
151       vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
152 
153       vacc0123 = vcvtnq_s32_f32(vfpacc0123);
154       vacc4567 = vcvtnq_s32_f32(vfpacc4567);
155 
156 #if XNN_ARCH_ARM64
157       int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
158 
159       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
160 
161       uint8x8_t vout01234567 = vqmovun_s16(vacc01234567);
162 #else  // !XNN_ARCH_ARM64
163       int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
164 
165       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
166 
167       uint8x8_t vout01234567 = vqmovun_s16(vacc01234567);
168 #endif  // !XNN_ARCH_ARM64
169 
170       vout01234567 = vmax_u8(vout01234567, voutput_min);
171 
172       vout01234567 = vmin_u8(vout01234567, voutput_max);
173 
174       vst1_u8(output, vout01234567); output += 8;
175     }
176     if XNN_UNLIKELY(c != 0) {
177       {
178         int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
179         int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
180 
181         const int16x8_t vi0x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i0)));
182         const int16x8_t vk0x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8(w), vkernel_zero_point));
183 
184         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
185         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
186         const int16x8_t vi1x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i1)));
187         const int16x8_t vk1x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 8)), vkernel_zero_point));
188 
189         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
190         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
191         const int16x8_t vi2x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i2)));
192         const int16x8_t vk2x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 16)), vkernel_zero_point));
193 
194         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
195         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
196         const int16x8_t vi3x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i3)));
197         const int16x8_t vk3x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 24)), vkernel_zero_point));
198 
199         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
200         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
201         const int16x8_t vi4x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i4)));
202         const int16x8_t vk4x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 32)), vkernel_zero_point));
203 
204         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
205         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
206         const int16x8_t vi5x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i5)));
207         const int16x8_t vk5x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 40)), vkernel_zero_point));
208 
209         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
210         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
211         const int16x8_t vi6x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i6)));
212         const int16x8_t vk6x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 48)), vkernel_zero_point));
213 
214         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567));
215         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567));
216         const int16x8_t vi7x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i7)));
217         const int16x8_t vk7x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 56)), vkernel_zero_point));
218 
219         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi7x01234567), vget_low_s16(vk7x01234567));
220         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi7x01234567), vget_high_s16(vk7x01234567));
221         const int16x8_t vi8x01234567 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(i8)));
222         const int16x8_t vk8x01234567 = vreinterpretq_s16_u16(vsubl_u8(vld1_u8((const void*) ((const uint8_t*) w + 64)), vkernel_zero_point));
223 
224         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi8x01234567), vget_low_s16(vk8x01234567));
225         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi8x01234567), vget_high_s16(vk8x01234567));
226 
227         float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
228         float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
229 
230         vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
231         vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
232 
233         vacc0123 = vcvtnq_s32_f32(vfpacc0123);
234         vacc4567 = vcvtnq_s32_f32(vfpacc4567);
235 
236 #if XNN_ARCH_ARM64
237         int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
238 #else
239         int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
240 #endif
241         vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
242 
243         uint8x8_t vout01234567 = vqmovun_s16(vacc01234567);
244         vout01234567 = vmax_u8(vout01234567, voutput_min);
245         vout01234567 = vmin_u8(vout01234567, voutput_max);
246 
247         if (c & 4) {
248           vst1_lane_u32((void*) output, vreinterpret_u32_u8(vout01234567), 0); output += 4;
249           vout01234567 = vext_u8(vout01234567, vout01234567, 4);
250         }
251         if (c & 2) {
252           vst1_lane_u16((void*) output, vreinterpret_u16_u8(vout01234567), 0); output += 2;
253           vout01234567 = vext_u8(vout01234567, vout01234567, 2);
254         }
255         if (c & 1) {
256           vst1_lane_u8(output, vout01234567, 0); output += 1;
257         }
258       }
259     }
260 
261     output = (uint8_t*) ((uintptr_t) output + output_increment);
262   } while (--output_width != 0);
263 }
264