Debian Codegraph @

src/qd8-f16-qc4w-gemm/gen/qd8-f16-qc4w-gemm-3x16c8-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_qc4w_gemm_minmax_ukernel_3x16c8__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_qc4w_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 <= 3);
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 const int8_t* a0 = a;
42 uint16_t* c0 = (uint16_t*) c;
43 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
44 uint16_t* c1 = (uint16_t*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr < 2) {
46 a1 = a0;
47 c1 = c0;
48 }
49 const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
50 uint16_t* c2 = (uint16_t*) ((uintptr_t) c1 + cm_stride);
51 if XNN_UNPREDICTABLE(mr <= 2) {
52 a2 = a1;
53 c2 = c1;
54 }
55 const int8x16_t vmask = vmovq_n_s8(INT8_C(0xF0));
56
57 // Loop over groups of 16 columns.
58 do {
59 // Initialize accumulators with bias. 16 bias values are loaded from the
60 // weight matrix, at the start of the group of 16 columns.
61 const int32x4_t vinput_zero_point01 = vld1q_s32(&quantization_params[0].zero_point);
62 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
63 const int32x4_t vksumzp0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point01), 0);
64 const int32x4_t vksumzp1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point01), 0);
65 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
66 const int32x4_t vksumzp0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point01), 0);
67 const int32x4_t vksumzp1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point01), 0);
68 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
69 const int32x4_t vksumzp0x89AB = vmulq_lane_s32(vksum89AB, vget_low_s32(vinput_zero_point01), 0);
70 const int32x4_t vksumzp1x89AB = vmulq_lane_s32(vksum89AB, vget_high_s32(vinput_zero_point01), 0);
71 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
72 const int32x4_t vksumzp0xCDEF = vmulq_lane_s32(vksumCDEF, vget_low_s32(vinput_zero_point01), 0);
73 const int32x4_t vksumzp1xCDEF = vmulq_lane_s32(vksumCDEF, vget_high_s32(vinput_zero_point01), 0);
74 const int32x4_t vinput_zero_point23 = vld1q_dup_s32(&quantization_params[2].zero_point);
75 const int32x4_t vksumzp2x0123 = vmulq_s32(vksum0123, vinput_zero_point23);
76 const int32x4_t vksumzp2x4567 = vmulq_s32(vksum4567, vinput_zero_point23);
77 const int32x4_t vksumzp2x89AB = vmulq_s32(vksum89AB, vinput_zero_point23);
78 const int32x4_t vksumzp2xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point23);
79
80 int32x4_t vacc01x01 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0x0123), vreinterpretq_u64_s32(vksumzp1x0123)));
81 int32x4_t vacc01x23 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0x0123), vreinterpretq_u64_s32(vksumzp1x0123)));
82 int32x4_t vacc01x45 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0x4567), vreinterpretq_u64_s32(vksumzp1x4567)));
83 int32x4_t vacc01x67 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0x4567), vreinterpretq_u64_s32(vksumzp1x4567)));
84 int32x4_t vacc01x89 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0x89AB), vreinterpretq_u64_s32(vksumzp1x89AB)));
85 int32x4_t vacc01xAB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0x89AB), vreinterpretq_u64_s32(vksumzp1x89AB)));
86 int32x4_t vacc01xCD = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0xCDEF), vreinterpretq_u64_s32(vksumzp1xCDEF)));
87 int32x4_t vacc01xEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0xCDEF), vreinterpretq_u64_s32(vksumzp1xCDEF)));
88 int32x4_t vacc23x01 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2x0123), vreinterpretq_u64_s32(vksumzp2x0123)));
89 int32x4_t vacc23x23 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2x0123), vreinterpretq_u64_s32(vksumzp2x0123)));
90 int32x4_t vacc23x45 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2x4567), vreinterpretq_u64_s32(vksumzp2x4567)));
91 int32x4_t vacc23x67 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2x4567), vreinterpretq_u64_s32(vksumzp2x4567)));
92 int32x4_t vacc23x89 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2x89AB), vreinterpretq_u64_s32(vksumzp2x89AB)));
93 int32x4_t vacc23xAB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2x89AB), vreinterpretq_u64_s32(vksumzp2x89AB)));
94 int32x4_t vacc23xCD = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2xCDEF), vreinterpretq_u64_s32(vksumzp2xCDEF)));
95 int32x4_t vacc23xEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2xCDEF), vreinterpretq_u64_s32(vksumzp2xCDEF)));
96
97 // Inner accumulation loop along the 16 columns.
98 size_t k = kc;
99 // 2x partial unrolled loop to load 8 bytes at a time.
100
101 uint64x2x2_t va01x0123456789ABCDEF;
102 va01x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
103 va01x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
104 uint64x2x2_t va23x0123456789ABCDEF;
105 va23x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
106 va23x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
107
108 while (k >= 16 * sizeof(int8_t)) {
109 // Load a 3x16 block of activations.
110 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a0, va01x0123456789ABCDEF, 0); a0 += 16;
111 va23x0123456789ABCDEF = vld2q_lane_u64((const void*) a2, va23x0123456789ABCDEF, 0); a2 += 16;
112 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a1, va01x0123456789ABCDEF, 1); a1 += 16;
113
114 const int8x16_t va01x01234567 = vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]);
115 const int8x16_t va01x89ABCDEF = vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]);
116 const int8x16_t va23x01234567 = vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[0]);
117 const int8x16_t va23x89ABCDEF = vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[1]);
118
119 // Load a 16x16 block of weights.
120 const int8x16_t vb01x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
121 const int8x16_t vb23x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
122 const int8x16_t vb45x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
123 const int8x16_t vb67x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
124 const int8x16_t vb89x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
125 const int8x16_t vbABx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
126 const int8x16_t vbCDx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
127 const int8x16_t vbEFx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
128 const int8x16_t vb01x01234567 = vshlq_n_s8(vb01x0123456789ABCDEF, 4);
129 const int8x16_t vb23x01234567 = vshlq_n_s8(vb23x0123456789ABCDEF, 4);
130 const int8x16_t vb45x01234567 = vshlq_n_s8(vb45x0123456789ABCDEF, 4);
131 const int8x16_t vb67x01234567 = vshlq_n_s8(vb67x0123456789ABCDEF, 4);
132 const int8x16_t vb89x01234567 = vshlq_n_s8(vb89x0123456789ABCDEF, 4);
133 const int8x16_t vbABx01234567 = vshlq_n_s8(vbABx0123456789ABCDEF, 4);
134 const int8x16_t vbCDx01234567 = vshlq_n_s8(vbCDx0123456789ABCDEF, 4);
135 const int8x16_t vbEFx01234567 = vshlq_n_s8(vbEFx0123456789ABCDEF, 4);
136 const int8x16_t vb01x89ABCDEF = vandq_s8(vb01x0123456789ABCDEF, vmask);
137 const int8x16_t vb23x89ABCDEF = vandq_s8(vb23x0123456789ABCDEF, vmask);
138 const int8x16_t vb45x89ABCDEF = vandq_s8(vb45x0123456789ABCDEF, vmask);
139 const int8x16_t vb67x89ABCDEF = vandq_s8(vb67x0123456789ABCDEF, vmask);
140 const int8x16_t vb89x89ABCDEF = vandq_s8(vb89x0123456789ABCDEF, vmask);
141 const int8x16_t vbABx89ABCDEF = vandq_s8(vbABx0123456789ABCDEF, vmask);
142 const int8x16_t vbCDx89ABCDEF = vandq_s8(vbCDx0123456789ABCDEF, vmask);
143 const int8x16_t vbEFx89ABCDEF = vandq_s8(vbEFx0123456789ABCDEF, vmask);
144
145 // Multiply-accumulate: 3x8 * 8x16 --> 3x16.
146 vacc01x01 = vmmlaq_s32(vacc01x01, va01x01234567, vb01x01234567);
147 vacc01x23 = vmmlaq_s32(vacc01x23, va01x01234567, vb23x01234567);
148 vacc01x45 = vmmlaq_s32(vacc01x45, va01x01234567, vb45x01234567);
149 vacc01x67 = vmmlaq_s32(vacc01x67, va01x01234567, vb67x01234567);
150 vacc01x89 = vmmlaq_s32(vacc01x89, va01x01234567, vb89x01234567);
151 vacc01xAB = vmmlaq_s32(vacc01xAB, va01x01234567, vbABx01234567);
152 vacc01xCD = vmmlaq_s32(vacc01xCD, va01x01234567, vbCDx01234567);
153 vacc01xEF = vmmlaq_s32(vacc01xEF, va01x01234567, vbEFx01234567);
154 vacc23x01 = vmmlaq_s32(vacc23x01, va23x01234567, vb01x01234567);
155 vacc23x23 = vmmlaq_s32(vacc23x23, va23x01234567, vb23x01234567);
156 vacc23x45 = vmmlaq_s32(vacc23x45, va23x01234567, vb45x01234567);
157 vacc23x67 = vmmlaq_s32(vacc23x67, va23x01234567, vb67x01234567);
158 vacc23x89 = vmmlaq_s32(vacc23x89, va23x01234567, vb89x01234567);
159 vacc23xAB = vmmlaq_s32(vacc23xAB, va23x01234567, vbABx01234567);
160 vacc23xCD = vmmlaq_s32(vacc23xCD, va23x01234567, vbCDx01234567);
161 vacc23xEF = vmmlaq_s32(vacc23xEF, va23x01234567, vbEFx01234567);
162 vacc01x01 = vmmlaq_s32(vacc01x01, va01x89ABCDEF, vb01x89ABCDEF);
163 vacc01x23 = vmmlaq_s32(vacc01x23, va01x89ABCDEF, vb23x89ABCDEF);
164 vacc01x45 = vmmlaq_s32(vacc01x45, va01x89ABCDEF, vb45x89ABCDEF);
165 vacc01x67 = vmmlaq_s32(vacc01x67, va01x89ABCDEF, vb67x89ABCDEF);
166 vacc01x89 = vmmlaq_s32(vacc01x89, va01x89ABCDEF, vb89x89ABCDEF);
167 vacc01xAB = vmmlaq_s32(vacc01xAB, va01x89ABCDEF, vbABx89ABCDEF);
168 vacc01xCD = vmmlaq_s32(vacc01xCD, va01x89ABCDEF, vbCDx89ABCDEF);
169 vacc01xEF = vmmlaq_s32(vacc01xEF, va01x89ABCDEF, vbEFx89ABCDEF);
170 vacc23x01 = vmmlaq_s32(vacc23x01, va23x89ABCDEF, vb01x89ABCDEF);
171 vacc23x23 = vmmlaq_s32(vacc23x23, va23x89ABCDEF, vb23x89ABCDEF);
172 vacc23x45 = vmmlaq_s32(vacc23x45, va23x89ABCDEF, vb45x89ABCDEF);
173 vacc23x67 = vmmlaq_s32(vacc23x67, va23x89ABCDEF, vb67x89ABCDEF);
174 vacc23x89 = vmmlaq_s32(vacc23x89, va23x89ABCDEF, vb89x89ABCDEF);
175 vacc23xAB = vmmlaq_s32(vacc23xAB, va23x89ABCDEF, vbABx89ABCDEF);
176 vacc23xCD = vmmlaq_s32(vacc23xCD, va23x89ABCDEF, vbCDx89ABCDEF);
177 vacc23xEF = vmmlaq_s32(vacc23xEF, va23x89ABCDEF, vbEFx89ABCDEF);
178
179 k -= 16 * sizeof(int8_t);
180 }
181 // Handle up to 8 final positions of `k`
182 if XNN_UNLIKELY(k != 0) {
183 // Load a 3x8 block of activations.
184 uint64x2_t va01x01234567 = vld1q_dup_u64((const void*) a0); a0 += 8;
185 uint64x2_t va23x01234567 = vld1q_dup_u64((const void*) a2); a2 += 8;
186 va01x01234567 = vld1q_lane_u64((const void*) a1, va01x01234567, 1); a1 += 8;
187
188 // Load a 16x16 block of weights.
189 const int8x16_t vb01x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
190 const int8x16_t vb23x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
191 const int8x16_t vb45x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
192 const int8x16_t vb67x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
193 const int8x16_t vb89x0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
194 const int8x16_t vbABx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
195 const int8x16_t vbCDx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
196 const int8x16_t vbEFx0123456789ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
197 const int8x16_t vb01x01234567 = vshlq_n_s8(vb01x0123456789ABCDEF, 4);
198 const int8x16_t vb23x01234567 = vshlq_n_s8(vb23x0123456789ABCDEF, 4);
199 const int8x16_t vb45x01234567 = vshlq_n_s8(vb45x0123456789ABCDEF, 4);
200 const int8x16_t vb67x01234567 = vshlq_n_s8(vb67x0123456789ABCDEF, 4);
201 const int8x16_t vb89x01234567 = vshlq_n_s8(vb89x0123456789ABCDEF, 4);
202 const int8x16_t vbABx01234567 = vshlq_n_s8(vbABx0123456789ABCDEF, 4);
203 const int8x16_t vbCDx01234567 = vshlq_n_s8(vbCDx0123456789ABCDEF, 4);
204 const int8x16_t vbEFx01234567 = vshlq_n_s8(vbEFx0123456789ABCDEF, 4);
205
206 // Multiply-accumulate: 3x4 * 4x16 --> 3x16.
207 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x01234567), vb01x01234567);
208 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x01234567), vb23x01234567);
209 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x01234567), vb45x01234567);
210 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x01234567), vb67x01234567);
211 vacc01x89 = vmmlaq_s32(vacc01x89, vreinterpretq_s8_u64(va01x01234567), vb89x01234567);
212 vacc01xAB = vmmlaq_s32(vacc01xAB, vreinterpretq_s8_u64(va01x01234567), vbABx01234567);
213 vacc01xCD = vmmlaq_s32(vacc01xCD, vreinterpretq_s8_u64(va01x01234567), vbCDx01234567);
214 vacc01xEF = vmmlaq_s32(vacc01xEF, vreinterpretq_s8_u64(va01x01234567), vbEFx01234567);
215 vacc23x01 = vmmlaq_s32(vacc23x01, vreinterpretq_s8_u64(va23x01234567), vb01x01234567);
216 vacc23x23 = vmmlaq_s32(vacc23x23, vreinterpretq_s8_u64(va23x01234567), vb23x01234567);
217 vacc23x45 = vmmlaq_s32(vacc23x45, vreinterpretq_s8_u64(va23x01234567), vb45x01234567);
218 vacc23x67 = vmmlaq_s32(vacc23x67, vreinterpretq_s8_u64(va23x01234567), vb67x01234567);
219 vacc23x89 = vmmlaq_s32(vacc23x89, vreinterpretq_s8_u64(va23x01234567), vb89x01234567);
220 vacc23xAB = vmmlaq_s32(vacc23xAB, vreinterpretq_s8_u64(va23x01234567), vbABx01234567);
221 vacc23xCD = vmmlaq_s32(vacc23xCD, vreinterpretq_s8_u64(va23x01234567), vbCDx01234567);
222 vacc23xEF = vmmlaq_s32(vacc23xEF, vreinterpretq_s8_u64(va23x01234567), vbEFx01234567);
223 }
224
225 int32x4_t vacc0x0123 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x01), vreinterpretq_u64_s32(vacc01x23)));
226 int32x4_t vacc1x0123 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x01), vreinterpretq_u64_s32(vacc01x23)));
227 int32x4_t vacc0x4567 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x45), vreinterpretq_u64_s32(vacc01x67)));
228 int32x4_t vacc1x4567 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x45), vreinterpretq_u64_s32(vacc01x67)));
229 int32x4_t vacc0x89AB = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x89), vreinterpretq_u64_s32(vacc01xAB)));
230 int32x4_t vacc1x89AB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x89), vreinterpretq_u64_s32(vacc01xAB)));
231 int32x4_t vacc0xCDEF = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01xCD), vreinterpretq_u64_s32(vacc01xEF)));
232 int32x4_t vacc1xCDEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01xCD), vreinterpretq_u64_s32(vacc01xEF)));
233 int32x4_t vacc2x0123 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x01), vreinterpretq_u64_s32(vacc23x23)));
234 int32x4_t vacc2x4567 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x45), vreinterpretq_u64_s32(vacc23x67)));
235 int32x4_t vacc2x89AB = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x89), vreinterpretq_u64_s32(vacc23xAB)));
236 int32x4_t vacc2xCDEF = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23xCD), vreinterpretq_u64_s32(vacc23xEF)));
237 float32x4_t vout0x0123 = vcvtq_n_f32_s32(vacc0x0123, 4);
238 float32x4_t vout0x4567 = vcvtq_n_f32_s32(vacc0x4567, 4);
239 float32x4_t vout0x89AB = vcvtq_n_f32_s32(vacc0x89AB, 4);
240 float32x4_t vout0xCDEF = vcvtq_n_f32_s32(vacc0xCDEF, 4);
241 float32x4_t vout1x0123 = vcvtq_n_f32_s32(vacc1x0123, 4);
242 float32x4_t vout1x4567 = vcvtq_n_f32_s32(vacc1x4567, 4);
243 float32x4_t vout1x89AB = vcvtq_n_f32_s32(vacc1x89AB, 4);
244 float32x4_t vout1xCDEF = vcvtq_n_f32_s32(vacc1xCDEF, 4);
245 float32x4_t vout2x0123 = vcvtq_n_f32_s32(vacc2x0123, 4);
246 float32x4_t vout2x4567 = vcvtq_n_f32_s32(vacc2x4567, 4);
247 float32x4_t vout2x89AB = vcvtq_n_f32_s32(vacc2x89AB, 4);
248 float32x4_t vout2xCDEF = vcvtq_n_f32_s32(vacc2xCDEF, 4);
249
250 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
251 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
252 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
253 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
254 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
255 vout0x89AB = vmulq_lane_f32(vout0x89AB, vget_low_f32(vinput_scale01), 1);
256 vout1x89AB = vmulq_lane_f32(vout1x89AB, vget_high_f32(vinput_scale01), 1);
257 vout0xCDEF = vmulq_lane_f32(vout0xCDEF, vget_low_f32(vinput_scale01), 1);
258 vout1xCDEF = vmulq_lane_f32(vout1xCDEF, vget_high_f32(vinput_scale01), 1);
259 const float32x4_t vinput_scale2 = vld1q_dup_f32(&quantization_params[2].inv_scale);
260 vout2x0123 = vmulq_f32(vout2x0123, vinput_scale2);
261 vout2x4567 = vmulq_f32(vout2x4567, vinput_scale2);
262 vout2x89AB = vmulq_f32(vout2x89AB, vinput_scale2);
263 vout2xCDEF = vmulq_f32(vout2xCDEF, vinput_scale2);
264
265 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
266 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
267 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
268 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
269
270 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
271 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
272 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
273 vout2x0123 = vfmaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
274 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
275 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
276 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
277 vout2x4567 = vfmaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
278 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
279 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
280 vout1x89AB = vfmaq_f32(vbias89AB, vout1x89AB, vfilter_output_scale89AB);
281 vout2x89AB = vfmaq_f32(vbias89AB, vout2x89AB, vfilter_output_scale89AB);
282 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
283 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
284 vout1xCDEF = vfmaq_f32(vbiasCDEF, vout1xCDEF, vfilter_output_scaleCDEF);
285 vout2xCDEF = vfmaq_f32(vbiasCDEF, vout2xCDEF, vfilter_output_scaleCDEF);
286
287 float16x8_t vfp16out0x01234567 = vcombine_f16(vcvt_f16_f32(vout0x0123), vcvt_f16_f32(vout0x4567));
288 float16x8_t vfp16out0x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout0x89AB), vcvt_f16_f32(vout0xCDEF));
289 float16x8_t vfp16out1x01234567 = vcombine_f16(vcvt_f16_f32(vout1x0123), vcvt_f16_f32(vout1x4567));
290 float16x8_t vfp16out1x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout1x89AB), vcvt_f16_f32(vout1xCDEF));
291 float16x8_t vfp16out2x01234567 = vcombine_f16(vcvt_f16_f32(vout2x0123), vcvt_f16_f32(vout2x4567));
292 float16x8_t vfp16out2x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout2x89AB), vcvt_f16_f32(vout2xCDEF));
293
294 const float16x8_t voutput_min = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
295 vfp16out0x01234567 = vmaxq_f16(vfp16out0x01234567, voutput_min);
296 vfp16out0x89ABCDEF = vmaxq_f16(vfp16out0x89ABCDEF, voutput_min);
297 vfp16out1x01234567 = vmaxq_f16(vfp16out1x01234567, voutput_min);
298 vfp16out1x89ABCDEF = vmaxq_f16(vfp16out1x89ABCDEF, voutput_min);
299 vfp16out2x01234567 = vmaxq_f16(vfp16out2x01234567, voutput_min);
300 vfp16out2x89ABCDEF = vmaxq_f16(vfp16out2x89ABCDEF, voutput_min);
301 const float16x8_t voutput_max = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
302 vfp16out0x01234567 = vminq_f16(vfp16out0x01234567, voutput_max);
303 vfp16out0x89ABCDEF = vminq_f16(vfp16out0x89ABCDEF, voutput_max);
304 vfp16out1x01234567 = vminq_f16(vfp16out1x01234567, voutput_max);
305 vfp16out1x89ABCDEF = vminq_f16(vfp16out1x89ABCDEF, voutput_max);
306 vfp16out2x01234567 = vminq_f16(vfp16out2x01234567, voutput_max);
307 vfp16out2x89ABCDEF = vminq_f16(vfp16out2x89ABCDEF, voutput_max);
308 if XNN_LIKELY(nc >= 16) {
309 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567));
310 vst1q_u16(c0 + 8, vreinterpretq_u16_f16(vfp16out0x89ABCDEF));
311 vst1q_u16(c1, vreinterpretq_u16_f16(vfp16out1x01234567));
312 vst1q_u16(c1 + 8, vreinterpretq_u16_f16(vfp16out1x89ABCDEF));
313 vst1q_u16(c2, vreinterpretq_u16_f16(vfp16out2x01234567));
314 vst1q_u16(c2 + 8, vreinterpretq_u16_f16(vfp16out2x89ABCDEF));
315
316 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
317 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
318 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
319
320 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
321 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
322 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
323
324 nc -= 16;
325 } else {
326 if (nc & 8) {
327 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); c0 += 8;
328 vfp16out0x01234567 = vfp16out0x89ABCDEF;
329 vst1q_u16(c1, vreinterpretq_u16_f16(vfp16out1x01234567)); c1 += 8;
330 vfp16out1x01234567 = vfp16out1x89ABCDEF;
331 vst1q_u16(c2, vreinterpretq_u16_f16(vfp16out2x01234567)); c2 += 8;
332 vfp16out2x01234567 = vfp16out2x89ABCDEF;
333 }
334 float16x4_t vfp16out0x0123 = vget_low_f16(vfp16out0x01234567);
335 float16x4_t vfp16out1x0123 = vget_low_f16(vfp16out1x01234567);
336 float16x4_t vfp16out2x0123 = vget_low_f16(vfp16out2x01234567);
337 if (nc & 4) {
338 vst1_u16(c0, vreinterpret_u16_f16(vfp16out0x0123)); c0 += 4;
339 vst1_u16(c1, vreinterpret_u16_f16(vfp16out1x0123)); c1 += 4;
340 vst1_u16(c2, vreinterpret_u16_f16(vfp16out2x0123)); c2 += 4;
341 vfp16out0x0123 = vget_high_f16(vfp16out0x01234567);
342 vfp16out1x0123 = vget_high_f16(vfp16out1x01234567);
343 vfp16out2x0123 = vget_high_f16(vfp16out2x01234567);
344 }
345 if (nc & 2) {
346 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vfp16out0x0123), 0); c0 += 2;
347 vst1_lane_u32((void*) c1, vreinterpret_u32_f16(vfp16out1x0123), 0); c1 += 2;
348 vst1_lane_u32((void*) c2, vreinterpret_u32_f16(vfp16out2x0123), 0); c2 += 2;
349 vfp16out0x0123 = vext_f16(vfp16out0x0123, vfp16out0x0123, 2);
350 vfp16out1x0123 = vext_f16(vfp16out1x0123, vfp16out1x0123, 2);
351 vfp16out2x0123 = vext_f16(vfp16out2x0123, vfp16out2x0123, 2);
352 }
353 if (nc & 1) {
354 vst1_lane_u16(c0, vreinterpret_u16_f16(vfp16out0x0123), 0);
355 vst1_lane_u16(c1, vreinterpret_u16_f16(vfp16out1x0123), 0);
356 vst1_lane_u16(c2, vreinterpret_u16_f16(vfp16out2x0123), 0);
357 }
358 nc = 0;
359 }
360 } while (nc != 0);
361 }