Debian Codegraph @

src/qd8-f16-qb4w-gemm/gen/qd8-f16-qb4w-gemm-4x16c8-minmax-neoni8mm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/c8-neoni8mm.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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/gemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f16_qb4w_gemm_minmax_ukernel_4x16c8__neoni8mm(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const int8_t* restrict a,
23 size_t a_stride,
24 const void* restrict w,
25 xnn_float16* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const struct xnn_f16_qb4w_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
29 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
30 {
31 assert(mr != 0);
32 assert(mr <= 4);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(kc % sizeof(int8_t) == 0);
36 assert(a != NULL);
37 assert(w != NULL);
38 assert(c != NULL);
39
40 kc = round_up_po2(kc, 8 * sizeof(int8_t));
41 size_t bl = params->scalar.blocksize;
42 assert(bl <= kc);
43 assert(bl != 0);
44 assert(bl % 32 == 0);
45 const int8_t* a0 = a;
46 uint16_t* c0 = (uint16_t*) c;
47 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
48 uint16_t* c1 = (uint16_t*) ((uintptr_t) c0 + cm_stride);
49 if XNN_UNPREDICTABLE(mr < 2) {
50 a1 = a0;
51 c1 = c0;
52 }
53 const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
54 uint16_t* c2 = (uint16_t*) ((uintptr_t) c1 + cm_stride);
55 if XNN_UNPREDICTABLE(mr <= 2) {
56 a2 = a1;
57 c2 = c1;
58 }
59 const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
60 uint16_t* c3 = (uint16_t*) ((uintptr_t) c2 + cm_stride);
61 if XNN_UNPREDICTABLE(mr != 4) {
62 a3 = a2;
63 c3 = c2;
64 }
65 const int8x16_t vmask = vmovq_n_s8(INT8_C(0xF0));
66
67 // Loop over groups of 16 columns.
68 do {
69 // Initialize accumulators with scaled vksum. 16 scaled vksum values are loaded from the
70 // weight matrix, at the start of the group of 16 columns.
71 const float32x4_t vinput_zero_point01 = vcvtq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
72 const float32x4_t vksum0123 = vld1q_f32(w); w = (const float*) w + 4;
73 float32x4_t vout0x0123 = vmulq_lane_f32(vksum0123, vget_low_f32(vinput_zero_point01), 0);
74 float32x4_t vout1x0123 = vmulq_lane_f32(vksum0123, vget_high_f32(vinput_zero_point01), 0);
75 const float32x4_t vksum4567 = vld1q_f32(w); w = (const float*) w + 4;
76 float32x4_t vout0x4567 = vmulq_lane_f32(vksum4567, vget_low_f32(vinput_zero_point01), 0);
77 float32x4_t vout1x4567 = vmulq_lane_f32(vksum4567, vget_high_f32(vinput_zero_point01), 0);
78 const float32x4_t vksum89AB = vld1q_f32(w); w = (const float*) w + 4;
79 float32x4_t vout0x89AB = vmulq_lane_f32(vksum89AB, vget_low_f32(vinput_zero_point01), 0);
80 float32x4_t vout1x89AB = vmulq_lane_f32(vksum89AB, vget_high_f32(vinput_zero_point01), 0);
81 const float32x4_t vksumCDEF = vld1q_f32(w); w = (const float*) w + 4;
82 float32x4_t vout0xCDEF = vmulq_lane_f32(vksumCDEF, vget_low_f32(vinput_zero_point01), 0);
83 float32x4_t vout1xCDEF = vmulq_lane_f32(vksumCDEF, vget_high_f32(vinput_zero_point01), 0);
84 const float32x4_t vinput_zero_point23 = vcvtq_f32_s32(vld1q_s32(&quantization_params[2].zero_point));
85 float32x4_t vout2x0123 = vmulq_lane_f32(vksum0123, vget_low_f32(vinput_zero_point23), 0);
86 float32x4_t vout3x0123 = vmulq_lane_f32(vksum0123, vget_high_f32(vinput_zero_point23), 0);
87 float32x4_t vout2x4567 = vmulq_lane_f32(vksum4567, vget_low_f32(vinput_zero_point23), 0);
88 float32x4_t vout3x4567 = vmulq_lane_f32(vksum4567, vget_high_f32(vinput_zero_point23), 0);
89 float32x4_t vout2x89AB = vmulq_lane_f32(vksum89AB, vget_low_f32(vinput_zero_point23), 0);
90 float32x4_t vout3x89AB = vmulq_lane_f32(vksum89AB, vget_high_f32(vinput_zero_point23), 0);
91 float32x4_t vout2xCDEF = vmulq_lane_f32(vksumCDEF, vget_low_f32(vinput_zero_point23), 0);
92 float32x4_t vout3xCDEF = vmulq_lane_f32(vksumCDEF, vget_high_f32(vinput_zero_point23), 0);
93
94
95 for (size_t kb=0; kb < kc; kb += bl) {
96 int32x4_t vacc01x01 = vdupq_n_s32(0);
97 int32x4_t vacc01x23 = vdupq_n_s32(0);
98 int32x4_t vacc01x45 = vdupq_n_s32(0);
99 int32x4_t vacc01x67 = vdupq_n_s32(0);
100 int32x4_t vacc01x89 = vdupq_n_s32(0);
101 int32x4_t vacc01xAB = vdupq_n_s32(0);
102 int32x4_t vacc01xCD = vdupq_n_s32(0);
103 int32x4_t vacc01xEF = vdupq_n_s32(0);
104 int32x4_t vacc23x01 = vdupq_n_s32(0);
105 int32x4_t vacc23x23 = vdupq_n_s32(0);
106 int32x4_t vacc23x45 = vdupq_n_s32(0);
107 int32x4_t vacc23x67 = vdupq_n_s32(0);
108 int32x4_t vacc23x89 = vdupq_n_s32(0);
109 int32x4_t vacc23xAB = vdupq_n_s32(0);
110 int32x4_t vacc23xCD = vdupq_n_s32(0);
111 int32x4_t vacc23xEF = vdupq_n_s32(0);
112
113 size_t k = bl;
114 // 2x partial unrolled loop to load 8 bytes at a time.
115
116 uint64x2x2_t va01x0123456789ABCDEF;
117 va01x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
118 va01x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
119 uint64x2x2_t va23x0123456789ABCDEF;
120 va23x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
121 va23x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
122
123 while (k >= 16 * sizeof(int8_t)) {
124 // Load a 4x16 block of activations.
125 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a0, va01x0123456789ABCDEF, 0); a0 += 16;
126 va23x0123456789ABCDEF = vld2q_lane_u64((const void*) a2, va23x0123456789ABCDEF, 0); a2 += 16;
127 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a1, va01x0123456789ABCDEF, 1); a1 += 16;
128 va23x0123456789ABCDEF = vld2q_lane_u64((const void*) a3, va23x0123456789ABCDEF, 1); a3 += 16;
129
130 const int8x16_t va01x01234567 = vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]);
131 const int8x16_t va01x89ABCDEF = vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]);
132 const int8x16_t va23x01234567 = vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[0]);
133 const int8x16_t va23x89ABCDEF = vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[1]);
134
135 // Load a 16x16 block of weights.
136 const int8x16_t vb01x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
137 const int8x16_t vb23x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
138 const int8x16_t vb45x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
139 const int8x16_t vb67x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
140 const int8x16_t vb89x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
141 const int8x16_t vbABx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
142 const int8x16_t vbCDx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
143 const int8x16_t vbEFx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
144 const int8x16_t vb01x01234567 = vshlq_n_s8(vb01x0123456789ABCDEF, 4);
145 const int8x16_t vb23x01234567 = vshlq_n_s8(vb23x0123456789ABCDEF, 4);
146 const int8x16_t vb45x01234567 = vshlq_n_s8(vb45x0123456789ABCDEF, 4);
147 const int8x16_t vb67x01234567 = vshlq_n_s8(vb67x0123456789ABCDEF, 4);
148 const int8x16_t vb89x01234567 = vshlq_n_s8(vb89x0123456789ABCDEF, 4);
149 const int8x16_t vbABx01234567 = vshlq_n_s8(vbABx0123456789ABCDEF, 4);
150 const int8x16_t vbCDx01234567 = vshlq_n_s8(vbCDx0123456789ABCDEF, 4);
151 const int8x16_t vbEFx01234567 = vshlq_n_s8(vbEFx0123456789ABCDEF, 4);
152 const int8x16_t vb01x89ABCDEF = vandq_s8(vb01x0123456789ABCDEF, vmask);
153 const int8x16_t vb23x89ABCDEF = vandq_s8(vb23x0123456789ABCDEF, vmask);
154 const int8x16_t vb45x89ABCDEF = vandq_s8(vb45x0123456789ABCDEF, vmask);
155 const int8x16_t vb67x89ABCDEF = vandq_s8(vb67x0123456789ABCDEF, vmask);
156 const int8x16_t vb89x89ABCDEF = vandq_s8(vb89x0123456789ABCDEF, vmask);
157 const int8x16_t vbABx89ABCDEF = vandq_s8(vbABx0123456789ABCDEF, vmask);
158 const int8x16_t vbCDx89ABCDEF = vandq_s8(vbCDx0123456789ABCDEF, vmask);
159 const int8x16_t vbEFx89ABCDEF = vandq_s8(vbEFx0123456789ABCDEF, vmask);
160
161 // Multiply-accumulate: 4x8 * 8x16 --> 4x16.
162 vacc01x01 = vmmlaq_s32(vacc01x01, va01x01234567, vb01x01234567);
163 vacc01x23 = vmmlaq_s32(vacc01x23, va01x01234567, vb23x01234567);
164 vacc01x45 = vmmlaq_s32(vacc01x45, va01x01234567, vb45x01234567);
165 vacc01x67 = vmmlaq_s32(vacc01x67, va01x01234567, vb67x01234567);
166 vacc01x89 = vmmlaq_s32(vacc01x89, va01x01234567, vb89x01234567);
167 vacc01xAB = vmmlaq_s32(vacc01xAB, va01x01234567, vbABx01234567);
168 vacc01xCD = vmmlaq_s32(vacc01xCD, va01x01234567, vbCDx01234567);
169 vacc01xEF = vmmlaq_s32(vacc01xEF, va01x01234567, vbEFx01234567);
170 vacc23x01 = vmmlaq_s32(vacc23x01, va23x01234567, vb01x01234567);
171 vacc23x23 = vmmlaq_s32(vacc23x23, va23x01234567, vb23x01234567);
172 vacc23x45 = vmmlaq_s32(vacc23x45, va23x01234567, vb45x01234567);
173 vacc23x67 = vmmlaq_s32(vacc23x67, va23x01234567, vb67x01234567);
174 vacc23x89 = vmmlaq_s32(vacc23x89, va23x01234567, vb89x01234567);
175 vacc23xAB = vmmlaq_s32(vacc23xAB, va23x01234567, vbABx01234567);
176 vacc23xCD = vmmlaq_s32(vacc23xCD, va23x01234567, vbCDx01234567);
177 vacc23xEF = vmmlaq_s32(vacc23xEF, va23x01234567, vbEFx01234567);
178 vacc01x01 = vmmlaq_s32(vacc01x01, va01x89ABCDEF, vb01x89ABCDEF);
179 vacc01x23 = vmmlaq_s32(vacc01x23, va01x89ABCDEF, vb23x89ABCDEF);
180 vacc01x45 = vmmlaq_s32(vacc01x45, va01x89ABCDEF, vb45x89ABCDEF);
181 vacc01x67 = vmmlaq_s32(vacc01x67, va01x89ABCDEF, vb67x89ABCDEF);
182 vacc01x89 = vmmlaq_s32(vacc01x89, va01x89ABCDEF, vb89x89ABCDEF);
183 vacc01xAB = vmmlaq_s32(vacc01xAB, va01x89ABCDEF, vbABx89ABCDEF);
184 vacc01xCD = vmmlaq_s32(vacc01xCD, va01x89ABCDEF, vbCDx89ABCDEF);
185 vacc01xEF = vmmlaq_s32(vacc01xEF, va01x89ABCDEF, vbEFx89ABCDEF);
186 vacc23x01 = vmmlaq_s32(vacc23x01, va23x89ABCDEF, vb01x89ABCDEF);
187 vacc23x23 = vmmlaq_s32(vacc23x23, va23x89ABCDEF, vb23x89ABCDEF);
188 vacc23x45 = vmmlaq_s32(vacc23x45, va23x89ABCDEF, vb45x89ABCDEF);
189 vacc23x67 = vmmlaq_s32(vacc23x67, va23x89ABCDEF, vb67x89ABCDEF);
190 vacc23x89 = vmmlaq_s32(vacc23x89, va23x89ABCDEF, vb89x89ABCDEF);
191 vacc23xAB = vmmlaq_s32(vacc23xAB, va23x89ABCDEF, vbABx89ABCDEF);
192 vacc23xCD = vmmlaq_s32(vacc23xCD, va23x89ABCDEF, vbCDx89ABCDEF);
193 vacc23xEF = vmmlaq_s32(vacc23xEF, va23x89ABCDEF, vbEFx89ABCDEF);
194
195 k -= 16 * sizeof(int8_t);
196 }
197 // Handle up to 8 final positions of `k`
198 if XNN_UNLIKELY(k != 0) {
199 // Load a 4x8 block of activations.
200 uint64x2_t va01x01234567 = vld1q_dup_u64((const void*) a0); a0 += 8;
201 uint64x2_t va23x01234567 = vld1q_dup_u64((const void*) a2); a2 += 8;
202 va01x01234567 = vld1q_lane_u64((const void*) a1, va01x01234567, 1); a1 += 8;
203 va23x01234567 = vld1q_lane_u64((const void*) a3, va23x01234567, 1); a3 += 8;
204
205 // Load a 16x16 block of weights.
206 const int8x16_t vb01x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
207 const int8x16_t vb23x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
208 const int8x16_t vb45x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
209 const int8x16_t vb67x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
210 const int8x16_t vb89x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
211 const int8x16_t vbABx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
212 const int8x16_t vbCDx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
213 const int8x16_t vbEFx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
214 const int8x16_t vb01x01234567 = vshlq_n_s8(vb01x0123456789ABCDEF, 4);
215 const int8x16_t vb23x01234567 = vshlq_n_s8(vb23x0123456789ABCDEF, 4);
216 const int8x16_t vb45x01234567 = vshlq_n_s8(vb45x0123456789ABCDEF, 4);
217 const int8x16_t vb67x01234567 = vshlq_n_s8(vb67x0123456789ABCDEF, 4);
218 const int8x16_t vb89x01234567 = vshlq_n_s8(vb89x0123456789ABCDEF, 4);
219 const int8x16_t vbABx01234567 = vshlq_n_s8(vbABx0123456789ABCDEF, 4);
220 const int8x16_t vbCDx01234567 = vshlq_n_s8(vbCDx0123456789ABCDEF, 4);
221 const int8x16_t vbEFx01234567 = vshlq_n_s8(vbEFx0123456789ABCDEF, 4);
222
223 // Multiply-accumulate: 4x4 * 4x16 --> 4x16.
224 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x01234567), vb01x01234567);
225 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x01234567), vb23x01234567);
226 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x01234567), vb45x01234567);
227 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x01234567), vb67x01234567);
228 vacc01x89 = vmmlaq_s32(vacc01x89, vreinterpretq_s8_u64(va01x01234567), vb89x01234567);
229 vacc01xAB = vmmlaq_s32(vacc01xAB, vreinterpretq_s8_u64(va01x01234567), vbABx01234567);
230 vacc01xCD = vmmlaq_s32(vacc01xCD, vreinterpretq_s8_u64(va01x01234567), vbCDx01234567);
231 vacc01xEF = vmmlaq_s32(vacc01xEF, vreinterpretq_s8_u64(va01x01234567), vbEFx01234567);
232 vacc23x01 = vmmlaq_s32(vacc23x01, vreinterpretq_s8_u64(va23x01234567), vb01x01234567);
233 vacc23x23 = vmmlaq_s32(vacc23x23, vreinterpretq_s8_u64(va23x01234567), vb23x01234567);
234 vacc23x45 = vmmlaq_s32(vacc23x45, vreinterpretq_s8_u64(va23x01234567), vb45x01234567);
235 vacc23x67 = vmmlaq_s32(vacc23x67, vreinterpretq_s8_u64(va23x01234567), vb67x01234567);
236 vacc23x89 = vmmlaq_s32(vacc23x89, vreinterpretq_s8_u64(va23x01234567), vb89x01234567);
237 vacc23xAB = vmmlaq_s32(vacc23xAB, vreinterpretq_s8_u64(va23x01234567), vbABx01234567);
238 vacc23xCD = vmmlaq_s32(vacc23xCD, vreinterpretq_s8_u64(va23x01234567), vbCDx01234567);
239 vacc23xEF = vmmlaq_s32(vacc23xEF, vreinterpretq_s8_u64(va23x01234567), vbEFx01234567);
240 }
241
242 int32x4_t vacc0x0123 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x01), vreinterpretq_u64_s32(vacc01x23)));
243 int32x4_t vacc1x0123 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x01), vreinterpretq_u64_s32(vacc01x23)));
244 int32x4_t vacc0x4567 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x45), vreinterpretq_u64_s32(vacc01x67)));
245 int32x4_t vacc1x4567 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x45), vreinterpretq_u64_s32(vacc01x67)));
246 int32x4_t vacc0x89AB = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x89), vreinterpretq_u64_s32(vacc01xAB)));
247 int32x4_t vacc1x89AB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x89), vreinterpretq_u64_s32(vacc01xAB)));
248 int32x4_t vacc0xCDEF = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01xCD), vreinterpretq_u64_s32(vacc01xEF)));
249 int32x4_t vacc1xCDEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01xCD), vreinterpretq_u64_s32(vacc01xEF)));
250 int32x4_t vacc2x0123 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x01), vreinterpretq_u64_s32(vacc23x23)));
251 int32x4_t vacc3x0123 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23x01), vreinterpretq_u64_s32(vacc23x23)));
252 int32x4_t vacc2x4567 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x45), vreinterpretq_u64_s32(vacc23x67)));
253 int32x4_t vacc3x4567 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23x45), vreinterpretq_u64_s32(vacc23x67)));
254 int32x4_t vacc2x89AB = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x89), vreinterpretq_u64_s32(vacc23xAB)));
255 int32x4_t vacc3x89AB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23x89), vreinterpretq_u64_s32(vacc23xAB)));
256 int32x4_t vacc2xCDEF = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23xCD), vreinterpretq_u64_s32(vacc23xEF)));
257 int32x4_t vacc3xCDEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23xCD), vreinterpretq_u64_s32(vacc23xEF)));
258 const float32x4_t vfilter_output_scale0123 = vreinterpretq_f32_u32(vshll_n_u16(vld1_u16(w), 16)); w = (const uint16_t*) w + 4;
259 const float32x4_t vfilter_output_scale4567 = vreinterpretq_f32_u32(vshll_n_u16(vld1_u16(w), 16)); w = (const uint16_t*) w + 4;
260 const float32x4_t vfilter_output_scale89AB = vreinterpretq_f32_u32(vshll_n_u16(vld1_u16(w), 16)); w = (const uint16_t*) w + 4;
261 const float32x4_t vfilter_output_scaleCDEF = vreinterpretq_f32_u32(vshll_n_u16(vld1_u16(w), 16)); w = (const uint16_t*) w + 4;
262 float32x4_t vf0x0123 = vcvtq_f32_s32(vacc0x0123);
263 vout0x0123 = vfmaq_f32(vout0x0123, vf0x0123, vfilter_output_scale0123);
264 float32x4_t vf0x4567 = vcvtq_f32_s32(vacc0x4567);
265 vout0x4567 = vfmaq_f32(vout0x4567, vf0x4567, vfilter_output_scale4567);
266 float32x4_t vf0x89AB = vcvtq_f32_s32(vacc0x89AB);
267 vout0x89AB = vfmaq_f32(vout0x89AB, vf0x89AB, vfilter_output_scale89AB);
268 float32x4_t vf0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
269 vout0xCDEF = vfmaq_f32(vout0xCDEF, vf0xCDEF, vfilter_output_scaleCDEF);
270 float32x4_t vf1x0123 = vcvtq_f32_s32(vacc1x0123);
271 vout1x0123 = vfmaq_f32(vout1x0123, vf1x0123, vfilter_output_scale0123);
272 float32x4_t vf1x4567 = vcvtq_f32_s32(vacc1x4567);
273 vout1x4567 = vfmaq_f32(vout1x4567, vf1x4567, vfilter_output_scale4567);
274 float32x4_t vf1x89AB = vcvtq_f32_s32(vacc1x89AB);
275 vout1x89AB = vfmaq_f32(vout1x89AB, vf1x89AB, vfilter_output_scale89AB);
276 float32x4_t vf1xCDEF = vcvtq_f32_s32(vacc1xCDEF);
277 vout1xCDEF = vfmaq_f32(vout1xCDEF, vf1xCDEF, vfilter_output_scaleCDEF);
278 float32x4_t vf2x0123 = vcvtq_f32_s32(vacc2x0123);
279 vout2x0123 = vfmaq_f32(vout2x0123, vf2x0123, vfilter_output_scale0123);
280 float32x4_t vf2x4567 = vcvtq_f32_s32(vacc2x4567);
281 vout2x4567 = vfmaq_f32(vout2x4567, vf2x4567, vfilter_output_scale4567);
282 float32x4_t vf2x89AB = vcvtq_f32_s32(vacc2x89AB);
283 vout2x89AB = vfmaq_f32(vout2x89AB, vf2x89AB, vfilter_output_scale89AB);
284 float32x4_t vf2xCDEF = vcvtq_f32_s32(vacc2xCDEF);
285 vout2xCDEF = vfmaq_f32(vout2xCDEF, vf2xCDEF, vfilter_output_scaleCDEF);
286 float32x4_t vf3x0123 = vcvtq_f32_s32(vacc3x0123);
287 vout3x0123 = vfmaq_f32(vout3x0123, vf3x0123, vfilter_output_scale0123);
288 float32x4_t vf3x4567 = vcvtq_f32_s32(vacc3x4567);
289 vout3x4567 = vfmaq_f32(vout3x4567, vf3x4567, vfilter_output_scale4567);
290 float32x4_t vf3x89AB = vcvtq_f32_s32(vacc3x89AB);
291 vout3x89AB = vfmaq_f32(vout3x89AB, vf3x89AB, vfilter_output_scale89AB);
292 float32x4_t vf3xCDEF = vcvtq_f32_s32(vacc3xCDEF);
293 vout3xCDEF = vfmaq_f32(vout3xCDEF, vf3xCDEF, vfilter_output_scaleCDEF);
294 }
295
296 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
297 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
298 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
299 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
300 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
301 vout0x89AB = vmulq_lane_f32(vout0x89AB, vget_low_f32(vinput_scale01), 1);
302 vout1x89AB = vmulq_lane_f32(vout1x89AB, vget_high_f32(vinput_scale01), 1);
303 vout0xCDEF = vmulq_lane_f32(vout0xCDEF, vget_low_f32(vinput_scale01), 1);
304 vout1xCDEF = vmulq_lane_f32(vout1xCDEF, vget_high_f32(vinput_scale01), 1);
305 const float32x4_t vinput_scale23 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[2].zero_point));
306 vout2x0123 = vmulq_lane_f32(vout2x0123, vget_low_f32(vinput_scale23), 1);
307 vout3x0123 = vmulq_lane_f32(vout3x0123, vget_high_f32(vinput_scale23), 1);
308 vout2x4567 = vmulq_lane_f32(vout2x4567, vget_low_f32(vinput_scale23), 1);
309 vout3x4567 = vmulq_lane_f32(vout3x4567, vget_high_f32(vinput_scale23), 1);
310 vout2x89AB = vmulq_lane_f32(vout2x89AB, vget_low_f32(vinput_scale23), 1);
311 vout3x89AB = vmulq_lane_f32(vout3x89AB, vget_high_f32(vinput_scale23), 1);
312 vout2xCDEF = vmulq_lane_f32(vout2xCDEF, vget_low_f32(vinput_scale23), 1);
313 vout3xCDEF = vmulq_lane_f32(vout3xCDEF, vget_high_f32(vinput_scale23), 1);
314
315
316 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
317 vout0x0123 = vaddq_f32(vbias0123, vout0x0123);
318 vout1x0123 = vaddq_f32(vbias0123, vout1x0123);
319 vout2x0123 = vaddq_f32(vbias0123, vout2x0123);
320 vout3x0123 = vaddq_f32(vbias0123, vout3x0123);
321 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
322 vout0x4567 = vaddq_f32(vbias4567, vout0x4567);
323 vout1x4567 = vaddq_f32(vbias4567, vout1x4567);
324 vout2x4567 = vaddq_f32(vbias4567, vout2x4567);
325 vout3x4567 = vaddq_f32(vbias4567, vout3x4567);
326 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
327 vout0x89AB = vaddq_f32(vbias89AB, vout0x89AB);
328 vout1x89AB = vaddq_f32(vbias89AB, vout1x89AB);
329 vout2x89AB = vaddq_f32(vbias89AB, vout2x89AB);
330 vout3x89AB = vaddq_f32(vbias89AB, vout3x89AB);
331 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
332 vout0xCDEF = vaddq_f32(vbiasCDEF, vout0xCDEF);
333 vout1xCDEF = vaddq_f32(vbiasCDEF, vout1xCDEF);
334 vout2xCDEF = vaddq_f32(vbiasCDEF, vout2xCDEF);
335 vout3xCDEF = vaddq_f32(vbiasCDEF, vout3xCDEF);
336
337 float16x8_t vfp16out0x01234567 = vcombine_f16(vcvt_f16_f32(vout0x0123), vcvt_f16_f32(vout0x4567));
338 float16x8_t vfp16out0x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout0x89AB), vcvt_f16_f32(vout0xCDEF));
339 float16x8_t vfp16out1x01234567 = vcombine_f16(vcvt_f16_f32(vout1x0123), vcvt_f16_f32(vout1x4567));
340 float16x8_t vfp16out1x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout1x89AB), vcvt_f16_f32(vout1xCDEF));
341 float16x8_t vfp16out2x01234567 = vcombine_f16(vcvt_f16_f32(vout2x0123), vcvt_f16_f32(vout2x4567));
342 float16x8_t vfp16out2x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout2x89AB), vcvt_f16_f32(vout2xCDEF));
343 float16x8_t vfp16out3x01234567 = vcombine_f16(vcvt_f16_f32(vout3x0123), vcvt_f16_f32(vout3x4567));
344 float16x8_t vfp16out3x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout3x89AB), vcvt_f16_f32(vout3xCDEF));
345
346 const float16x8_t voutput_min = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
347 vfp16out0x01234567 = vmaxq_f16(vfp16out0x01234567, voutput_min);
348 vfp16out0x89ABCDEF = vmaxq_f16(vfp16out0x89ABCDEF, voutput_min);
349 vfp16out1x01234567 = vmaxq_f16(vfp16out1x01234567, voutput_min);
350 vfp16out1x89ABCDEF = vmaxq_f16(vfp16out1x89ABCDEF, voutput_min);
351 vfp16out2x01234567 = vmaxq_f16(vfp16out2x01234567, voutput_min);
352 vfp16out2x89ABCDEF = vmaxq_f16(vfp16out2x89ABCDEF, voutput_min);
353 vfp16out3x01234567 = vmaxq_f16(vfp16out3x01234567, voutput_min);
354 vfp16out3x89ABCDEF = vmaxq_f16(vfp16out3x89ABCDEF, voutput_min);
355 const float16x8_t voutput_max = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
356 vfp16out0x01234567 = vminq_f16(vfp16out0x01234567, voutput_max);
357 vfp16out0x89ABCDEF = vminq_f16(vfp16out0x89ABCDEF, voutput_max);
358 vfp16out1x01234567 = vminq_f16(vfp16out1x01234567, voutput_max);
359 vfp16out1x89ABCDEF = vminq_f16(vfp16out1x89ABCDEF, voutput_max);
360 vfp16out2x01234567 = vminq_f16(vfp16out2x01234567, voutput_max);
361 vfp16out2x89ABCDEF = vminq_f16(vfp16out2x89ABCDEF, voutput_max);
362 vfp16out3x01234567 = vminq_f16(vfp16out3x01234567, voutput_max);
363 vfp16out3x89ABCDEF = vminq_f16(vfp16out3x89ABCDEF, voutput_max);
364 if XNN_LIKELY(nc >= 16) {
365 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567));
366 vst1q_u16(c0 + 8, vreinterpretq_u16_f16(vfp16out0x89ABCDEF));
367 vst1q_u16(c1, vreinterpretq_u16_f16(vfp16out1x01234567));
368 vst1q_u16(c1 + 8, vreinterpretq_u16_f16(vfp16out1x89ABCDEF));
369 vst1q_u16(c2, vreinterpretq_u16_f16(vfp16out2x01234567));
370 vst1q_u16(c2 + 8, vreinterpretq_u16_f16(vfp16out2x89ABCDEF));
371 vst1q_u16(c3, vreinterpretq_u16_f16(vfp16out3x01234567));
372 vst1q_u16(c3 + 8, vreinterpretq_u16_f16(vfp16out3x89ABCDEF));
373
374 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
375 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
376 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
377 a3 = (const int8_t*) ((uintptr_t) a3 - kc);
378
379 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
380 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
381 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
382 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
383
384 nc -= 16;
385 } else {
386 if (nc & 8) {
387 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); c0 += 8;
388 vfp16out0x01234567 = vfp16out0x89ABCDEF;
389 vst1q_u16(c1, vreinterpretq_u16_f16(vfp16out1x01234567)); c1 += 8;
390 vfp16out1x01234567 = vfp16out1x89ABCDEF;
391 vst1q_u16(c2, vreinterpretq_u16_f16(vfp16out2x01234567)); c2 += 8;
392 vfp16out2x01234567 = vfp16out2x89ABCDEF;
393 vst1q_u16(c3, vreinterpretq_u16_f16(vfp16out3x01234567)); c3 += 8;
394 vfp16out3x01234567 = vfp16out3x89ABCDEF;
395 }
396 float16x4_t vfp16out0x0123 = vget_low_f16(vfp16out0x01234567);
397 float16x4_t vfp16out1x0123 = vget_low_f16(vfp16out1x01234567);
398 float16x4_t vfp16out2x0123 = vget_low_f16(vfp16out2x01234567);
399 float16x4_t vfp16out3x0123 = vget_low_f16(vfp16out3x01234567);
400 if (nc & 4) {
401 vst1_u16(c0, vreinterpret_u16_f16(vfp16out0x0123)); c0 += 4;
402 vst1_u16(c1, vreinterpret_u16_f16(vfp16out1x0123)); c1 += 4;
403 vst1_u16(c2, vreinterpret_u16_f16(vfp16out2x0123)); c2 += 4;
404 vst1_u16(c3, vreinterpret_u16_f16(vfp16out3x0123)); c3 += 4;
405 vfp16out0x0123 = vget_high_f16(vfp16out0x01234567);
406 vfp16out1x0123 = vget_high_f16(vfp16out1x01234567);
407 vfp16out2x0123 = vget_high_f16(vfp16out2x01234567);
408 vfp16out3x0123 = vget_high_f16(vfp16out3x01234567);
409 }
410 if (nc & 2) {
411 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vfp16out0x0123), 0); c0 += 2;
412 vst1_lane_u32((void*) c1, vreinterpret_u32_f16(vfp16out1x0123), 0); c1 += 2;
413 vst1_lane_u32((void*) c2, vreinterpret_u32_f16(vfp16out2x0123), 0); c2 += 2;
414 vst1_lane_u32((void*) c3, vreinterpret_u32_f16(vfp16out3x0123), 0); c3 += 2;
415 vfp16out0x0123 = vext_f16(vfp16out0x0123, vfp16out0x0123, 2);
416 vfp16out1x0123 = vext_f16(vfp16out1x0123, vfp16out1x0123, 2);
417 vfp16out2x0123 = vext_f16(vfp16out2x0123, vfp16out2x0123, 2);
418 vfp16out3x0123 = vext_f16(vfp16out3x0123, vfp16out3x0123, 2);
419 }
420 if (nc & 1) {
421 vst1_lane_u16(c0, vreinterpret_u16_f16(vfp16out0x0123), 0);
422 vst1_lane_u16(c1, vreinterpret_u16_f16(vfp16out1x0123), 0);
423 vst1_lane_u16(c2, vreinterpret_u16_f16(vfp16out2x0123), 0);
424 vst1_lane_u16(c3, vreinterpret_u16_f16(vfp16out3x0123), 0);
425 }
426 nc = 0;
427 }
428 } while (nc != 0);
429 }