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 
16 
xnn_qs8_dwconv_minmax_ukernel_up8x9__neon_mul16(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_gemm_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_dwconv_minmax_ukernel_up8x9__neon_mul16(
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_gemm_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const int32x4_t vmultiplier = vld1q_dup_s32(&params->neon.multiplier);
33   const int32x4_t vright_shift = vld1q_dup_s32(&params->neon.right_shift);
34   const int32x4_t vzero_shift_mask = vreinterpretq_s32_u32(vceqq_s32(vright_shift, vmovq_n_s32(0)));
35   const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->neon.output_zero_point);
36   const int8x8_t voutput_min = vld1_dup_s8(&params->neon.output_min);
37   const int8x8_t voutput_max = vld1_dup_s8(&params->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*) ((uintptr_t) w + 4 * sizeof(int32_t));
90       int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
91 
92 
93       const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
94       const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i1)); i1 += 8;
100       const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i2)); i2 += 8;
106       const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i3)); i3 += 8;
112       const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i4)); i4 += 8;
118       const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i5)); i5 += 8;
124       const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i6)); i6 += 8;
130       const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i7)); i7 += 8;
136       const int16x8_t vk7x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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 = vmovl_s8(vld1_s8(i8)); i8 += 8;
142       const int16x8_t vk8x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
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       vacc0123 = vqrdmulhq_s32(vacc0123, vmultiplier);
148       vacc4567 = vqrdmulhq_s32(vacc4567, vmultiplier);
149 
150       vacc0123 = vsraq_n_s32(vacc0123, vbicq_s32(vacc0123, vzero_shift_mask), 31);
151       vacc4567 = vsraq_n_s32(vacc4567, vbicq_s32(vacc4567, vzero_shift_mask), 31);
152 
153       vacc0123 = vrshlq_s32(vacc0123, vright_shift);
154       vacc4567 = vrshlq_s32(vacc4567, vright_shift);
155 
156 #if XNN_ARCH_ARM64
157       const int16x8_t vacc01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567), voutput_zero_point);
158 
159       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
160 #else
161       const int16x8_t vacc01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567)), voutput_zero_point);
162 
163       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
164 #endif
165 
166       vout01234567 = vmax_s8(vout01234567, voutput_min);
167 
168       vout01234567 = vmin_s8(vout01234567, voutput_max);
169 
170       vst1_s8(output, vout01234567); output += 8;
171     }
172     if XNN_UNLIKELY(c != 0) {
173       {
174         int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
175         int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
176 
177         const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0));
178         const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w));
179 
180         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
181         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
182         const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1));
183         const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 8 * sizeof(int8_t))));
184 
185         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
186         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
187         const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2));
188         const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 16 * sizeof(int8_t))));
189 
190         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
191         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
192         const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3));
193         const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 24 * sizeof(int8_t))));
194 
195         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
196         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
197         const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4));
198         const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 32 * sizeof(int8_t))));
199 
200         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
201         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
202         const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5));
203         const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 40 * sizeof(int8_t))));
204 
205         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
206         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
207         const int16x8_t vi6x01234567 = vmovl_s8(vld1_s8(i6));
208         const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 48 * sizeof(int8_t))));
209 
210         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567));
211         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567));
212         const int16x8_t vi7x01234567 = vmovl_s8(vld1_s8(i7));
213         const int16x8_t vk7x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 56 * sizeof(int8_t))));
214 
215         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi7x01234567), vget_low_s16(vk7x01234567));
216         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi7x01234567), vget_high_s16(vk7x01234567));
217         const int16x8_t vi8x01234567 = vmovl_s8(vld1_s8(i8));
218         const int16x8_t vk8x01234567 = vmovl_s8(vld1_s8((const void*) ((uintptr_t) w + 64 * sizeof(int8_t))));
219 
220         vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi8x01234567), vget_low_s16(vk8x01234567));
221         vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi8x01234567), vget_high_s16(vk8x01234567));
222 
223         vacc0123 = vqrdmulhq_s32(vacc0123, vmultiplier);
224         vacc4567 = vqrdmulhq_s32(vacc4567, vmultiplier);
225 
226         vacc0123 = vsraq_n_s32(vacc0123, vbicq_s32(vacc0123, vzero_shift_mask), 31);
227         vacc4567 = vsraq_n_s32(vacc4567, vbicq_s32(vacc4567, vzero_shift_mask), 31);
228 
229         vacc0123 = vrshlq_s32(vacc0123, vright_shift);
230         vacc4567 = vrshlq_s32(vacc4567, vright_shift);
231 
232 #if XNN_ARCH_ARM64
233         const int16x8_t vacc01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567), voutput_zero_point);
234 
235         int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
236 #else
237         const int16x8_t vacc01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567)), voutput_zero_point);
238 
239         int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
240 #endif
241 
242         vout01234567 = vmax_s8(vout01234567, voutput_min);
243         vout01234567 = vmin_s8(vout01234567, voutput_max);
244 
245         if (c & 4) {
246           vst1_lane_u32(__builtin_assume_aligned(output, 1), vreinterpret_u32_s8(vout01234567), 0); output += 4;
247           vout01234567 = vext_s8(vout01234567, vout01234567, 4);
248         }
249         if (c & 2) {
250           vst1_lane_u16(__builtin_assume_aligned(output, 1), vreinterpret_u16_s8(vout01234567), 0); output += 2;
251           vout01234567 = vext_s8(vout01234567, vout01234567, 2);
252         }
253         if (c & 1) {
254           vst1_lane_s8(output, vout01234567, 0); output += 1;
255         }
256       }
257     }
258 
259     output = (int8_t*) ((uintptr_t) output + output_increment);
260   } while (--output_width != 0);
261 }
262