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_qc8_dwconv_minmax_fp32_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_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qc8_dwconv_minmax_fp32_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_qc8_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 float32x4_t vmagic_bias = vld1q_dup_f32(¶ms->fp32_neon.magic_bias);
33 const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(¶ms->fp32_neon.magic_bias_less_output_zero_point);
34 const int8x8_t voutput_min = vld1_dup_s8(¶ms->fp32_neon.output_min);
35 const int8x8_t voutput_max = vld1_dup_s8(¶ms->fp32_neon.output_max);
36 do {
37 const int8_t* i0 = input[0];
38 assert(i0 != NULL);
39 if XNN_UNPREDICTABLE(i0 != zero) {
40 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
41 }
42 const int8_t* i1 = input[1];
43 assert(i1 != NULL);
44 if XNN_UNPREDICTABLE(i1 != zero) {
45 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
46 }
47 const int8_t* i2 = input[2];
48 assert(i2 != NULL);
49 if XNN_UNPREDICTABLE(i2 != zero) {
50 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
51 }
52 const int8_t* i3 = input[3];
53 assert(i3 != NULL);
54 if XNN_UNPREDICTABLE(i3 != zero) {
55 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
56 }
57 const int8_t* i4 = input[4];
58 assert(i4 != NULL);
59 if XNN_UNPREDICTABLE(i4 != zero) {
60 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
61 }
62 const int8_t* i5 = input[5];
63 assert(i5 != NULL);
64 if XNN_UNPREDICTABLE(i5 != zero) {
65 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
66 }
67 const int8_t* i6 = input[6];
68 assert(i6 != NULL);
69 if XNN_UNPREDICTABLE(i6 != zero) {
70 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
71 }
72 const int8_t* i7 = input[7];
73 assert(i7 != NULL);
74 if XNN_UNPREDICTABLE(i7 != zero) {
75 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
76 }
77 const int8_t* i8 = input[8];
78 assert(i8 != NULL);
79 if XNN_UNPREDICTABLE(i8 != zero) {
80 i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
81 }
82 input = (const int8_t**) ((uintptr_t) input + input_stride);
83
84 size_t c = channels;
85 const void* w = weights;
86 for (; c >= 8; c -= 8) {
87 int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
88 int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
89
90
91 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
92 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
93
94 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
95 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
96
97 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
98 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
99
100 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
101 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
102
103 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
104 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
105
106 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
107 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
108
109 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
110 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
111
112 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
113 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
114
115 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
116 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
117
118 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
119 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
120
121 const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5)); i5 += 8;
122 const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
123
124 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
125 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
126
127 const int16x8_t vi6x01234567 = vmovl_s8(vld1_s8(i6)); i6 += 8;
128 const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
129
130 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567));
131 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567));
132
133 const int16x8_t vi7x01234567 = vmovl_s8(vld1_s8(i7)); i7 += 8;
134 const int16x8_t vk7x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
135
136 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi7x01234567), vget_low_s16(vk7x01234567));
137 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi7x01234567), vget_high_s16(vk7x01234567));
138
139 const int16x8_t vi8x01234567 = vmovl_s8(vld1_s8(i8)); i8 += 8;
140 const int16x8_t vk8x01234567 = vmovl_s8(vld1_s8(w)); w = (const void*) ((const int8_t*) w + 8);
141
142 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi8x01234567), vget_low_s16(vk8x01234567));
143 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi8x01234567), vget_high_s16(vk8x01234567));
144
145 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
146 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
147
148 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
149 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
150
151 vfpacc0123 = vmulq_f32(vfpacc0123, vscale0123);
152 vfpacc4567 = vmulq_f32(vfpacc4567, vscale4567);
153
154 vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
155 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
156
157 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
158 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
159
160 #if XNN_ARCH_ARM64
161 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
162
163
164 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
165 #else // !XNN_ARCH_ARM64
166 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
167
168
169 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
170 #endif // !XNN_ARCH_ARM64
171
172 vout01234567 = vmax_s8(vout01234567, voutput_min);
173
174 vout01234567 = vmin_s8(vout01234567, voutput_max);
175
176 vst1_s8(output, vout01234567); output += 8;
177 }
178 if XNN_UNLIKELY(c != 0) {
179 {
180 int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
181 int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
182
183 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0));
184 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w));
185
186 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
187 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
188 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1));
189 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 8)));
190
191 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
192 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
193 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2));
194 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 16)));
195
196 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
197 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
198 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3));
199 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 24)));
200
201 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
202 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
203 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4));
204 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 32)));
205
206 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
207 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
208 const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5));
209 const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 40)));
210
211 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
212 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
213 const int16x8_t vi6x01234567 = vmovl_s8(vld1_s8(i6));
214 const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 48)));
215
216 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567));
217 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567));
218 const int16x8_t vi7x01234567 = vmovl_s8(vld1_s8(i7));
219 const int16x8_t vk7x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 56)));
220
221 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi7x01234567), vget_low_s16(vk7x01234567));
222 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi7x01234567), vget_high_s16(vk7x01234567));
223 const int16x8_t vi8x01234567 = vmovl_s8(vld1_s8(i8));
224 const int16x8_t vk8x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 64)));
225
226 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi8x01234567), vget_low_s16(vk8x01234567));
227 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi8x01234567), vget_high_s16(vk8x01234567));
228
229 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
230 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
231
232 const float32x4_t vscale0123 = vld1q_f32((const float*) ((uintptr_t) w + 0 * sizeof(int32_t) + 72 * sizeof(int8_t)));
233 const float32x4_t vscale4567 = vld1q_f32((const float*) ((uintptr_t) w + 0 * sizeof(int32_t) + 72 * sizeof(int8_t) + 4 * sizeof(float)));
234 vfpacc0123 = vmulq_f32(vfpacc0123, vscale0123);
235 vfpacc4567 = vmulq_f32(vfpacc4567, vscale4567);
236
237 vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
238 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
239
240 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
241 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
242
243 #if XNN_ARCH_ARM64
244 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
245 #else
246 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
247 #endif
248
249 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
250 vout01234567 = vmax_s8(vout01234567, voutput_min);
251 vout01234567 = vmin_s8(vout01234567, voutput_max);
252
253 if (c & 4) {
254 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
255 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
256 }
257 if (c & 2) {
258 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
259 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
260 }
261 if (c & 1) {
262 vst1_lane_s8(output, vout01234567, 0); output += 1;
263 }
264 }
265 }
266
267 output = (int8_t*) ((uintptr_t) output + output_increment);
268 } while (--output_width != 0);
269 }
270