Debian Codegraph @

src/qd8-f16-qc8w-gemm/gen/qd8-f16-qc8w-gemm-5x16c8-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_qc8w_gemm_minmax_ukernel_5x16c8__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 union xnn_f16_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 <= 5);
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 int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
56 uint16_t* c3 = (uint16_t*) ((uintptr_t) c2 + cm_stride);
57 if XNN_UNPREDICTABLE(mr < 4) {
58 a3 = a2;
59 c3 = c2;
60 }
61 const int8_t* a4 = (const int8_t*) ((uintptr_t) a3 + a_stride);
62 uint16_t* c4 = (uint16_t*) ((uintptr_t) c3 + cm_stride);
63 if XNN_UNPREDICTABLE(mr <= 4) {
64 a4 = a3;
65 c4 = c3;
66 }
67
68 // Loop over groups of 16 columns.
69 do {
70 // Initialize accumulators with bias. 16 bias values are loaded from the
71 // weight matrix, at the start of the group of 16 columns.
72 const int32x4_t vinput_zero_point01 = vld1q_s32(&quantization_params[0].zero_point);
73 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
74 const int32x4_t vksumzp0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point01), 0);
75 const int32x4_t vksumzp1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point01), 0);
76 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
77 const int32x4_t vksumzp0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point01), 0);
78 const int32x4_t vksumzp1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point01), 0);
79 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
80 const int32x4_t vksumzp0x89AB = vmulq_lane_s32(vksum89AB, vget_low_s32(vinput_zero_point01), 0);
81 const int32x4_t vksumzp1x89AB = vmulq_lane_s32(vksum89AB, vget_high_s32(vinput_zero_point01), 0);
82 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
83 const int32x4_t vksumzp0xCDEF = vmulq_lane_s32(vksumCDEF, vget_low_s32(vinput_zero_point01), 0);
84 const int32x4_t vksumzp1xCDEF = vmulq_lane_s32(vksumCDEF, vget_high_s32(vinput_zero_point01), 0);
85 const int32x4_t vinput_zero_point23 = vld1q_s32(&quantization_params[2].zero_point);
86 const int32x4_t vksumzp2x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point23), 0);
87 const int32x4_t vksumzp3x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point23), 0);
88 const int32x4_t vksumzp2x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point23), 0);
89 const int32x4_t vksumzp3x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point23), 0);
90 const int32x4_t vksumzp2x89AB = vmulq_lane_s32(vksum89AB, vget_low_s32(vinput_zero_point23), 0);
91 const int32x4_t vksumzp3x89AB = vmulq_lane_s32(vksum89AB, vget_high_s32(vinput_zero_point23), 0);
92 const int32x4_t vksumzp2xCDEF = vmulq_lane_s32(vksumCDEF, vget_low_s32(vinput_zero_point23), 0);
93 const int32x4_t vksumzp3xCDEF = vmulq_lane_s32(vksumCDEF, vget_high_s32(vinput_zero_point23), 0);
94 const int32x4_t vinput_zero_point45 = vld1q_dup_s32(&quantization_params[4].zero_point);
95 const int32x4_t vksumzp4x0123 = vmulq_s32(vksum0123, vinput_zero_point45);
96 const int32x4_t vksumzp4x4567 = vmulq_s32(vksum4567, vinput_zero_point45);
97 const int32x4_t vksumzp4x89AB = vmulq_s32(vksum89AB, vinput_zero_point45);
98 const int32x4_t vksumzp4xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point45);
99
100 int32x4_t vacc01x01 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0x0123), vreinterpretq_u64_s32(vksumzp1x0123)));
101 int32x4_t vacc01x23 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0x0123), vreinterpretq_u64_s32(vksumzp1x0123)));
102 int32x4_t vacc01x45 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0x4567), vreinterpretq_u64_s32(vksumzp1x4567)));
103 int32x4_t vacc01x67 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0x4567), vreinterpretq_u64_s32(vksumzp1x4567)));
104 int32x4_t vacc01x89 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0x89AB), vreinterpretq_u64_s32(vksumzp1x89AB)));
105 int32x4_t vacc01xAB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0x89AB), vreinterpretq_u64_s32(vksumzp1x89AB)));
106 int32x4_t vacc01xCD = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp0xCDEF), vreinterpretq_u64_s32(vksumzp1xCDEF)));
107 int32x4_t vacc01xEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp0xCDEF), vreinterpretq_u64_s32(vksumzp1xCDEF)));
108 int32x4_t vacc23x01 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2x0123), vreinterpretq_u64_s32(vksumzp3x0123)));
109 int32x4_t vacc23x23 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2x0123), vreinterpretq_u64_s32(vksumzp3x0123)));
110 int32x4_t vacc23x45 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2x4567), vreinterpretq_u64_s32(vksumzp3x4567)));
111 int32x4_t vacc23x67 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2x4567), vreinterpretq_u64_s32(vksumzp3x4567)));
112 int32x4_t vacc23x89 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2x89AB), vreinterpretq_u64_s32(vksumzp3x89AB)));
113 int32x4_t vacc23xAB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2x89AB), vreinterpretq_u64_s32(vksumzp3x89AB)));
114 int32x4_t vacc23xCD = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp2xCDEF), vreinterpretq_u64_s32(vksumzp3xCDEF)));
115 int32x4_t vacc23xEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp2xCDEF), vreinterpretq_u64_s32(vksumzp3xCDEF)));
116 int32x4_t vacc45x01 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp4x0123), vreinterpretq_u64_s32(vksumzp4x0123)));
117 int32x4_t vacc45x23 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp4x0123), vreinterpretq_u64_s32(vksumzp4x0123)));
118 int32x4_t vacc45x45 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp4x4567), vreinterpretq_u64_s32(vksumzp4x4567)));
119 int32x4_t vacc45x67 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp4x4567), vreinterpretq_u64_s32(vksumzp4x4567)));
120 int32x4_t vacc45x89 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp4x89AB), vreinterpretq_u64_s32(vksumzp4x89AB)));
121 int32x4_t vacc45xAB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp4x89AB), vreinterpretq_u64_s32(vksumzp4x89AB)));
122 int32x4_t vacc45xCD = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vksumzp4xCDEF), vreinterpretq_u64_s32(vksumzp4xCDEF)));
123 int32x4_t vacc45xEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vksumzp4xCDEF), vreinterpretq_u64_s32(vksumzp4xCDEF)));
124
125 // Inner accumulation loop along the 16 columns.
126 size_t k = kc;
127 // 2x partial unrolled loop to load 8 bytes at a time.
128
129 uint64x2x2_t va01x0123456789ABCDEF;
130 va01x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
131 va01x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
132 uint64x2x2_t va23x0123456789ABCDEF;
133 va23x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
134 va23x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
135 uint64x2x2_t va45x0123456789ABCDEF;
136 va45x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
137 va45x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
138
139 while (k >= 16 * sizeof(int8_t)) {
140 // Load a 5x16 block of activations.
141 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a0, va01x0123456789ABCDEF, 0); a0 += 16;
142 va23x0123456789ABCDEF = vld2q_lane_u64((const void*) a2, va23x0123456789ABCDEF, 0); a2 += 16;
143 va45x0123456789ABCDEF = vld2q_lane_u64((const void*) a4, va45x0123456789ABCDEF, 0); a4 += 16;
144 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a1, va01x0123456789ABCDEF, 1); a1 += 16;
145 va23x0123456789ABCDEF = vld2q_lane_u64((const void*) a3, va23x0123456789ABCDEF, 1); a3 += 16;
146
147 const int8x16_t va01x01234567 = vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]);
148 const int8x16_t va01x89ABCDEF = vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]);
149 const int8x16_t va23x01234567 = vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[0]);
150 const int8x16_t va23x89ABCDEF = vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[1]);
151 const int8x16_t va45x01234567 = vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[0]);
152 const int8x16_t va45x89ABCDEF = vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[1]);
153
154 // Load a 16x16 block of weights.
155 const int8x16_t vb01x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
156 const int8x16_t vb23x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
157 const int8x16_t vb45x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
158 const int8x16_t vb67x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
159 const int8x16_t vb89x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
160 const int8x16_t vbABx01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
161 const int8x16_t vbCDx01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
162 const int8x16_t vbEFx01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
163 const int8x16_t vb01x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
164 const int8x16_t vb23x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
165 const int8x16_t vb45x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
166 const int8x16_t vb67x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
167 const int8x16_t vb89x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
168 const int8x16_t vbABx89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
169 const int8x16_t vbCDx89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
170 const int8x16_t vbEFx89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
171
172 // Multiply-accumulate: 5x8 * 8x16 --> 5x16.
173 vacc01x01 = vmmlaq_s32(vacc01x01, va01x01234567, vb01x01234567);
174 vacc01x23 = vmmlaq_s32(vacc01x23, va01x01234567, vb23x01234567);
175 vacc01x45 = vmmlaq_s32(vacc01x45, va01x01234567, vb45x01234567);
176 vacc01x67 = vmmlaq_s32(vacc01x67, va01x01234567, vb67x01234567);
177 vacc01x89 = vmmlaq_s32(vacc01x89, va01x01234567, vb89x01234567);
178 vacc01xAB = vmmlaq_s32(vacc01xAB, va01x01234567, vbABx01234567);
179 vacc01xCD = vmmlaq_s32(vacc01xCD, va01x01234567, vbCDx01234567);
180 vacc01xEF = vmmlaq_s32(vacc01xEF, va01x01234567, vbEFx01234567);
181 vacc23x01 = vmmlaq_s32(vacc23x01, va23x01234567, vb01x01234567);
182 vacc23x23 = vmmlaq_s32(vacc23x23, va23x01234567, vb23x01234567);
183 vacc23x45 = vmmlaq_s32(vacc23x45, va23x01234567, vb45x01234567);
184 vacc23x67 = vmmlaq_s32(vacc23x67, va23x01234567, vb67x01234567);
185 vacc23x89 = vmmlaq_s32(vacc23x89, va23x01234567, vb89x01234567);
186 vacc23xAB = vmmlaq_s32(vacc23xAB, va23x01234567, vbABx01234567);
187 vacc23xCD = vmmlaq_s32(vacc23xCD, va23x01234567, vbCDx01234567);
188 vacc23xEF = vmmlaq_s32(vacc23xEF, va23x01234567, vbEFx01234567);
189 vacc45x01 = vmmlaq_s32(vacc45x01, va45x01234567, vb01x01234567);
190 vacc45x23 = vmmlaq_s32(vacc45x23, va45x01234567, vb23x01234567);
191 vacc45x45 = vmmlaq_s32(vacc45x45, va45x01234567, vb45x01234567);
192 vacc45x67 = vmmlaq_s32(vacc45x67, va45x01234567, vb67x01234567);
193 vacc45x89 = vmmlaq_s32(vacc45x89, va45x01234567, vb89x01234567);
194 vacc45xAB = vmmlaq_s32(vacc45xAB, va45x01234567, vbABx01234567);
195 vacc45xCD = vmmlaq_s32(vacc45xCD, va45x01234567, vbCDx01234567);
196 vacc45xEF = vmmlaq_s32(vacc45xEF, va45x01234567, vbEFx01234567);
197 vacc01x01 = vmmlaq_s32(vacc01x01, va01x89ABCDEF, vb01x89ABCDEF);
198 vacc01x23 = vmmlaq_s32(vacc01x23, va01x89ABCDEF, vb23x89ABCDEF);
199 vacc01x45 = vmmlaq_s32(vacc01x45, va01x89ABCDEF, vb45x89ABCDEF);
200 vacc01x67 = vmmlaq_s32(vacc01x67, va01x89ABCDEF, vb67x89ABCDEF);
201 vacc01x89 = vmmlaq_s32(vacc01x89, va01x89ABCDEF, vb89x89ABCDEF);
202 vacc01xAB = vmmlaq_s32(vacc01xAB, va01x89ABCDEF, vbABx89ABCDEF);
203 vacc01xCD = vmmlaq_s32(vacc01xCD, va01x89ABCDEF, vbCDx89ABCDEF);
204 vacc01xEF = vmmlaq_s32(vacc01xEF, va01x89ABCDEF, vbEFx89ABCDEF);
205 vacc23x01 = vmmlaq_s32(vacc23x01, va23x89ABCDEF, vb01x89ABCDEF);
206 vacc23x23 = vmmlaq_s32(vacc23x23, va23x89ABCDEF, vb23x89ABCDEF);
207 vacc23x45 = vmmlaq_s32(vacc23x45, va23x89ABCDEF, vb45x89ABCDEF);
208 vacc23x67 = vmmlaq_s32(vacc23x67, va23x89ABCDEF, vb67x89ABCDEF);
209 vacc23x89 = vmmlaq_s32(vacc23x89, va23x89ABCDEF, vb89x89ABCDEF);
210 vacc23xAB = vmmlaq_s32(vacc23xAB, va23x89ABCDEF, vbABx89ABCDEF);
211 vacc23xCD = vmmlaq_s32(vacc23xCD, va23x89ABCDEF, vbCDx89ABCDEF);
212 vacc23xEF = vmmlaq_s32(vacc23xEF, va23x89ABCDEF, vbEFx89ABCDEF);
213 vacc45x01 = vmmlaq_s32(vacc45x01, va45x89ABCDEF, vb01x89ABCDEF);
214 vacc45x23 = vmmlaq_s32(vacc45x23, va45x89ABCDEF, vb23x89ABCDEF);
215 vacc45x45 = vmmlaq_s32(vacc45x45, va45x89ABCDEF, vb45x89ABCDEF);
216 vacc45x67 = vmmlaq_s32(vacc45x67, va45x89ABCDEF, vb67x89ABCDEF);
217 vacc45x89 = vmmlaq_s32(vacc45x89, va45x89ABCDEF, vb89x89ABCDEF);
218 vacc45xAB = vmmlaq_s32(vacc45xAB, va45x89ABCDEF, vbABx89ABCDEF);
219 vacc45xCD = vmmlaq_s32(vacc45xCD, va45x89ABCDEF, vbCDx89ABCDEF);
220 vacc45xEF = vmmlaq_s32(vacc45xEF, va45x89ABCDEF, vbEFx89ABCDEF);
221
222 k -= 16 * sizeof(int8_t);
223 }
224 // Handle up to 8 final positions of `k`
225 if XNN_UNLIKELY(k != 0) {
226 // Load a 5x8 block of activations.
227 uint64x2_t va01x01234567 = vld1q_dup_u64((const void*) a0); a0 += 8;
228 uint64x2_t va23x01234567 = vld1q_dup_u64((const void*) a2); a2 += 8;
229 uint64x2_t va45x01234567 = vld1q_dup_u64((const void*) a4); a4 += 8;
230 va01x01234567 = vld1q_lane_u64((const void*) a1, va01x01234567, 1); a1 += 8;
231 va23x01234567 = vld1q_lane_u64((const void*) a3, va23x01234567, 1); a3 += 8;
232
233 // Load a 16x16 block of weights.
234 const int8x16_t vb01x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
235 const int8x16_t vb23x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
236 const int8x16_t vb45x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
237 const int8x16_t vb67x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
238 const int8x16_t vb89x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
239 const int8x16_t vbABx01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
240 const int8x16_t vbCDx01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
241 const int8x16_t vbEFx01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
242
243 // Multiply-accumulate: 5x4 * 4x16 --> 5x16.
244 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x01234567), vb01x01234567);
245 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x01234567), vb23x01234567);
246 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x01234567), vb45x01234567);
247 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x01234567), vb67x01234567);
248 vacc01x89 = vmmlaq_s32(vacc01x89, vreinterpretq_s8_u64(va01x01234567), vb89x01234567);
249 vacc01xAB = vmmlaq_s32(vacc01xAB, vreinterpretq_s8_u64(va01x01234567), vbABx01234567);
250 vacc01xCD = vmmlaq_s32(vacc01xCD, vreinterpretq_s8_u64(va01x01234567), vbCDx01234567);
251 vacc01xEF = vmmlaq_s32(vacc01xEF, vreinterpretq_s8_u64(va01x01234567), vbEFx01234567);
252 vacc23x01 = vmmlaq_s32(vacc23x01, vreinterpretq_s8_u64(va23x01234567), vb01x01234567);
253 vacc23x23 = vmmlaq_s32(vacc23x23, vreinterpretq_s8_u64(va23x01234567), vb23x01234567);
254 vacc23x45 = vmmlaq_s32(vacc23x45, vreinterpretq_s8_u64(va23x01234567), vb45x01234567);
255 vacc23x67 = vmmlaq_s32(vacc23x67, vreinterpretq_s8_u64(va23x01234567), vb67x01234567);
256 vacc23x89 = vmmlaq_s32(vacc23x89, vreinterpretq_s8_u64(va23x01234567), vb89x01234567);
257 vacc23xAB = vmmlaq_s32(vacc23xAB, vreinterpretq_s8_u64(va23x01234567), vbABx01234567);
258 vacc23xCD = vmmlaq_s32(vacc23xCD, vreinterpretq_s8_u64(va23x01234567), vbCDx01234567);
259 vacc23xEF = vmmlaq_s32(vacc23xEF, vreinterpretq_s8_u64(va23x01234567), vbEFx01234567);
260 vacc45x01 = vmmlaq_s32(vacc45x01, vreinterpretq_s8_u64(va45x01234567), vb01x01234567);
261 vacc45x23 = vmmlaq_s32(vacc45x23, vreinterpretq_s8_u64(va45x01234567), vb23x01234567);
262 vacc45x45 = vmmlaq_s32(vacc45x45, vreinterpretq_s8_u64(va45x01234567), vb45x01234567);
263 vacc45x67 = vmmlaq_s32(vacc45x67, vreinterpretq_s8_u64(va45x01234567), vb67x01234567);
264 vacc45x89 = vmmlaq_s32(vacc45x89, vreinterpretq_s8_u64(va45x01234567), vb89x01234567);
265 vacc45xAB = vmmlaq_s32(vacc45xAB, vreinterpretq_s8_u64(va45x01234567), vbABx01234567);
266 vacc45xCD = vmmlaq_s32(vacc45xCD, vreinterpretq_s8_u64(va45x01234567), vbCDx01234567);
267 vacc45xEF = vmmlaq_s32(vacc45xEF, vreinterpretq_s8_u64(va45x01234567), vbEFx01234567);
268 }
269
270 int32x4_t vacc0x0123 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x01), vreinterpretq_u64_s32(vacc01x23)));
271 int32x4_t vacc1x0123 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x01), vreinterpretq_u64_s32(vacc01x23)));
272 int32x4_t vacc0x4567 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x45), vreinterpretq_u64_s32(vacc01x67)));
273 int32x4_t vacc1x4567 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x45), vreinterpretq_u64_s32(vacc01x67)));
274 int32x4_t vacc0x89AB = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01x89), vreinterpretq_u64_s32(vacc01xAB)));
275 int32x4_t vacc1x89AB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01x89), vreinterpretq_u64_s32(vacc01xAB)));
276 int32x4_t vacc0xCDEF = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc01xCD), vreinterpretq_u64_s32(vacc01xEF)));
277 int32x4_t vacc1xCDEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc01xCD), vreinterpretq_u64_s32(vacc01xEF)));
278 int32x4_t vacc2x0123 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x01), vreinterpretq_u64_s32(vacc23x23)));
279 int32x4_t vacc3x0123 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23x01), vreinterpretq_u64_s32(vacc23x23)));
280 int32x4_t vacc2x4567 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x45), vreinterpretq_u64_s32(vacc23x67)));
281 int32x4_t vacc3x4567 = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23x45), vreinterpretq_u64_s32(vacc23x67)));
282 int32x4_t vacc2x89AB = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23x89), vreinterpretq_u64_s32(vacc23xAB)));
283 int32x4_t vacc3x89AB = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23x89), vreinterpretq_u64_s32(vacc23xAB)));
284 int32x4_t vacc2xCDEF = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc23xCD), vreinterpretq_u64_s32(vacc23xEF)));
285 int32x4_t vacc3xCDEF = vreinterpretq_s32_u64(vtrn2q_u64(vreinterpretq_u64_s32(vacc23xCD), vreinterpretq_u64_s32(vacc23xEF)));
286 int32x4_t vacc4x0123 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc45x01), vreinterpretq_u64_s32(vacc45x23)));
287 int32x4_t vacc4x4567 = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc45x45), vreinterpretq_u64_s32(vacc45x67)));
288 int32x4_t vacc4x89AB = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc45x89), vreinterpretq_u64_s32(vacc45xAB)));
289 int32x4_t vacc4xCDEF = vreinterpretq_s32_u64(vtrn1q_u64(vreinterpretq_u64_s32(vacc45xCD), vreinterpretq_u64_s32(vacc45xEF)));
290 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
291 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
292 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
293 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
294 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
295 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
296 float32x4_t vout1x89AB = vcvtq_f32_s32(vacc1x89AB);
297 float32x4_t vout1xCDEF = vcvtq_f32_s32(vacc1xCDEF);
298 float32x4_t vout2x0123 = vcvtq_f32_s32(vacc2x0123);
299 float32x4_t vout2x4567 = vcvtq_f32_s32(vacc2x4567);
300 float32x4_t vout2x89AB = vcvtq_f32_s32(vacc2x89AB);
301 float32x4_t vout2xCDEF = vcvtq_f32_s32(vacc2xCDEF);
302 float32x4_t vout3x0123 = vcvtq_f32_s32(vacc3x0123);
303 float32x4_t vout3x4567 = vcvtq_f32_s32(vacc3x4567);
304 float32x4_t vout3x89AB = vcvtq_f32_s32(vacc3x89AB);
305 float32x4_t vout3xCDEF = vcvtq_f32_s32(vacc3xCDEF);
306 float32x4_t vout4x0123 = vcvtq_f32_s32(vacc4x0123);
307 float32x4_t vout4x4567 = vcvtq_f32_s32(vacc4x4567);
308 float32x4_t vout4x89AB = vcvtq_f32_s32(vacc4x89AB);
309 float32x4_t vout4xCDEF = vcvtq_f32_s32(vacc4xCDEF);
310
311 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
312 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
313 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
314 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
315 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
316 vout0x89AB = vmulq_lane_f32(vout0x89AB, vget_low_f32(vinput_scale01), 1);
317 vout1x89AB = vmulq_lane_f32(vout1x89AB, vget_high_f32(vinput_scale01), 1);
318 vout0xCDEF = vmulq_lane_f32(vout0xCDEF, vget_low_f32(vinput_scale01), 1);
319 vout1xCDEF = vmulq_lane_f32(vout1xCDEF, vget_high_f32(vinput_scale01), 1);
320 const float32x4_t vinput_scale23 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[2].zero_point));
321 vout2x0123 = vmulq_lane_f32(vout2x0123, vget_low_f32(vinput_scale23), 1);
322 vout3x0123 = vmulq_lane_f32(vout3x0123, vget_high_f32(vinput_scale23), 1);
323 vout2x4567 = vmulq_lane_f32(vout2x4567, vget_low_f32(vinput_scale23), 1);
324 vout3x4567 = vmulq_lane_f32(vout3x4567, vget_high_f32(vinput_scale23), 1);
325 vout2x89AB = vmulq_lane_f32(vout2x89AB, vget_low_f32(vinput_scale23), 1);
326 vout3x89AB = vmulq_lane_f32(vout3x89AB, vget_high_f32(vinput_scale23), 1);
327 vout2xCDEF = vmulq_lane_f32(vout2xCDEF, vget_low_f32(vinput_scale23), 1);
328 vout3xCDEF = vmulq_lane_f32(vout3xCDEF, vget_high_f32(vinput_scale23), 1);
329 const float32x4_t vinput_scale4 = vld1q_dup_f32(&quantization_params[4].inv_scale);
330 vout4x0123 = vmulq_f32(vout4x0123, vinput_scale4);
331 vout4x4567 = vmulq_f32(vout4x4567, vinput_scale4);
332 vout4x89AB = vmulq_f32(vout4x89AB, vinput_scale4);
333 vout4xCDEF = vmulq_f32(vout4xCDEF, vinput_scale4);
334
335 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
336 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
337 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
338 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
339
340 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
341 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
342 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
343 vout2x0123 = vfmaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
344 vout3x0123 = vfmaq_f32(vbias0123, vout3x0123, vfilter_output_scale0123);
345 vout4x0123 = vfmaq_f32(vbias0123, vout4x0123, vfilter_output_scale0123);
346 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
347 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
348 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
349 vout2x4567 = vfmaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
350 vout3x4567 = vfmaq_f32(vbias4567, vout3x4567, vfilter_output_scale4567);
351 vout4x4567 = vfmaq_f32(vbias4567, vout4x4567, vfilter_output_scale4567);
352 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
353 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
354 vout1x89AB = vfmaq_f32(vbias89AB, vout1x89AB, vfilter_output_scale89AB);
355 vout2x89AB = vfmaq_f32(vbias89AB, vout2x89AB, vfilter_output_scale89AB);
356 vout3x89AB = vfmaq_f32(vbias89AB, vout3x89AB, vfilter_output_scale89AB);
357 vout4x89AB = vfmaq_f32(vbias89AB, vout4x89AB, vfilter_output_scale89AB);
358 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
359 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
360 vout1xCDEF = vfmaq_f32(vbiasCDEF, vout1xCDEF, vfilter_output_scaleCDEF);
361 vout2xCDEF = vfmaq_f32(vbiasCDEF, vout2xCDEF, vfilter_output_scaleCDEF);
362 vout3xCDEF = vfmaq_f32(vbiasCDEF, vout3xCDEF, vfilter_output_scaleCDEF);
363 vout4xCDEF = vfmaq_f32(vbiasCDEF, vout4xCDEF, vfilter_output_scaleCDEF);
364
365 float16x8_t vfp16out0x01234567 = vcombine_f16(vcvt_f16_f32(vout0x0123), vcvt_f16_f32(vout0x4567));
366 float16x8_t vfp16out0x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout0x89AB), vcvt_f16_f32(vout0xCDEF));
367 float16x8_t vfp16out1x01234567 = vcombine_f16(vcvt_f16_f32(vout1x0123), vcvt_f16_f32(vout1x4567));
368 float16x8_t vfp16out1x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout1x89AB), vcvt_f16_f32(vout1xCDEF));
369 float16x8_t vfp16out2x01234567 = vcombine_f16(vcvt_f16_f32(vout2x0123), vcvt_f16_f32(vout2x4567));
370 float16x8_t vfp16out2x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout2x89AB), vcvt_f16_f32(vout2xCDEF));
371 float16x8_t vfp16out3x01234567 = vcombine_f16(vcvt_f16_f32(vout3x0123), vcvt_f16_f32(vout3x4567));
372 float16x8_t vfp16out3x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout3x89AB), vcvt_f16_f32(vout3xCDEF));
373 float16x8_t vfp16out4x01234567 = vcombine_f16(vcvt_f16_f32(vout4x0123), vcvt_f16_f32(vout4x4567));
374 float16x8_t vfp16out4x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout4x89AB), vcvt_f16_f32(vout4xCDEF));
375
376 const float16x8_t voutput_min = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
377 vfp16out0x01234567 = vmaxq_f16(vfp16out0x01234567, voutput_min);
378 vfp16out0x89ABCDEF = vmaxq_f16(vfp16out0x89ABCDEF, voutput_min);
379 vfp16out1x01234567 = vmaxq_f16(vfp16out1x01234567, voutput_min);
380 vfp16out1x89ABCDEF = vmaxq_f16(vfp16out1x89ABCDEF, voutput_min);
381 vfp16out2x01234567 = vmaxq_f16(vfp16out2x01234567, voutput_min);
382 vfp16out2x89ABCDEF = vmaxq_f16(vfp16out2x89ABCDEF, voutput_min);
383 vfp16out3x01234567 = vmaxq_f16(vfp16out3x01234567, voutput_min);
384 vfp16out3x89ABCDEF = vmaxq_f16(vfp16out3x89ABCDEF, voutput_min);
385 vfp16out4x01234567 = vmaxq_f16(vfp16out4x01234567, voutput_min);
386 vfp16out4x89ABCDEF = vmaxq_f16(vfp16out4x89ABCDEF, voutput_min);
387 const float16x8_t voutput_max = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
388 vfp16out0x01234567 = vminq_f16(vfp16out0x01234567, voutput_max);
389 vfp16out0x89ABCDEF = vminq_f16(vfp16out0x89ABCDEF, voutput_max);
390 vfp16out1x01234567 = vminq_f16(vfp16out1x01234567, voutput_max);
391 vfp16out1x89ABCDEF = vminq_f16(vfp16out1x89ABCDEF, voutput_max);
392 vfp16out2x01234567 = vminq_f16(vfp16out2x01234567, voutput_max);
393 vfp16out2x89ABCDEF = vminq_f16(vfp16out2x89ABCDEF, voutput_max);
394 vfp16out3x01234567 = vminq_f16(vfp16out3x01234567, voutput_max);
395 vfp16out3x89ABCDEF = vminq_f16(vfp16out3x89ABCDEF, voutput_max);
396 vfp16out4x01234567 = vminq_f16(vfp16out4x01234567, voutput_max);
397 vfp16out4x89ABCDEF = vminq_f16(vfp16out4x89ABCDEF, voutput_max);
398 if XNN_LIKELY(nc >= 16) {
399 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567));
400 vst1q_u16(c0 + 8, vreinterpretq_u16_f16(vfp16out0x89ABCDEF));
401 vst1q_u16(c1, vreinterpretq_u16_f16(vfp16out1x01234567));
402 vst1q_u16(c1 + 8, vreinterpretq_u16_f16(vfp16out1x89ABCDEF));
403 vst1q_u16(c2, vreinterpretq_u16_f16(vfp16out2x01234567));
404 vst1q_u16(c2 + 8, vreinterpretq_u16_f16(vfp16out2x89ABCDEF));
405 vst1q_u16(c3, vreinterpretq_u16_f16(vfp16out3x01234567));
406 vst1q_u16(c3 + 8, vreinterpretq_u16_f16(vfp16out3x89ABCDEF));
407 vst1q_u16(c4, vreinterpretq_u16_f16(vfp16out4x01234567));
408 vst1q_u16(c4 + 8, vreinterpretq_u16_f16(vfp16out4x89ABCDEF));
409
410 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
411 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
412 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
413 a3 = (const int8_t*) ((uintptr_t) a3 - kc);
414 a4 = (const int8_t*) ((uintptr_t) a4 - kc);
415
416 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
417 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
418 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
419 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
420 c4 = (uint16_t*) ((uintptr_t) c4 + cn_stride);
421
422 nc -= 16;
423 } else {
424 if (nc & 8) {
425 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); c0 += 8;
426 vfp16out0x01234567 = vfp16out0x89ABCDEF;
427 vst1q_u16(c1, vreinterpretq_u16_f16(vfp16out1x01234567)); c1 += 8;
428 vfp16out1x01234567 = vfp16out1x89ABCDEF;
429 vst1q_u16(c2, vreinterpretq_u16_f16(vfp16out2x01234567)); c2 += 8;
430 vfp16out2x01234567 = vfp16out2x89ABCDEF;
431 vst1q_u16(c3, vreinterpretq_u16_f16(vfp16out3x01234567)); c3 += 8;
432 vfp16out3x01234567 = vfp16out3x89ABCDEF;
433 vst1q_u16(c4, vreinterpretq_u16_f16(vfp16out4x01234567)); c4 += 8;
434 vfp16out4x01234567 = vfp16out4x89ABCDEF;
435 }
436 float16x4_t vfp16out0x0123 = vget_low_f16(vfp16out0x01234567);
437 float16x4_t vfp16out1x0123 = vget_low_f16(vfp16out1x01234567);
438 float16x4_t vfp16out2x0123 = vget_low_f16(vfp16out2x01234567);
439 float16x4_t vfp16out3x0123 = vget_low_f16(vfp16out3x01234567);
440 float16x4_t vfp16out4x0123 = vget_low_f16(vfp16out4x01234567);
441 if (nc & 4) {
442 vst1_u16(c0, vreinterpret_u16_f16(vfp16out0x0123)); c0 += 4;
443 vst1_u16(c1, vreinterpret_u16_f16(vfp16out1x0123)); c1 += 4;
444 vst1_u16(c2, vreinterpret_u16_f16(vfp16out2x0123)); c2 += 4;
445 vst1_u16(c3, vreinterpret_u16_f16(vfp16out3x0123)); c3 += 4;
446 vst1_u16(c4, vreinterpret_u16_f16(vfp16out4x0123)); c4 += 4;
447 vfp16out0x0123 = vget_high_f16(vfp16out0x01234567);
448 vfp16out1x0123 = vget_high_f16(vfp16out1x01234567);
449 vfp16out2x0123 = vget_high_f16(vfp16out2x01234567);
450 vfp16out3x0123 = vget_high_f16(vfp16out3x01234567);
451 vfp16out4x0123 = vget_high_f16(vfp16out4x01234567);
452 }
453 if (nc & 2) {
454 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vfp16out0x0123), 0); c0 += 2;
455 vst1_lane_u32((void*) c1, vreinterpret_u32_f16(vfp16out1x0123), 0); c1 += 2;
456 vst1_lane_u32((void*) c2, vreinterpret_u32_f16(vfp16out2x0123), 0); c2 += 2;
457 vst1_lane_u32((void*) c3, vreinterpret_u32_f16(vfp16out3x0123), 0); c3 += 2;
458 vst1_lane_u32((void*) c4, vreinterpret_u32_f16(vfp16out4x0123), 0); c4 += 2;
459 vfp16out0x0123 = vext_f16(vfp16out0x0123, vfp16out0x0123, 2);
460 vfp16out1x0123 = vext_f16(vfp16out1x0123, vfp16out1x0123, 2);
461 vfp16out2x0123 = vext_f16(vfp16out2x0123, vfp16out2x0123, 2);
462 vfp16out3x0123 = vext_f16(vfp16out3x0123, vfp16out3x0123, 2);
463 vfp16out4x0123 = vext_f16(vfp16out4x0123, vfp16out4x0123, 2);
464 }
465 if (nc & 1) {
466 vst1_lane_u16(c0, vreinterpret_u16_f16(vfp16out0x0123), 0);
467 vst1_lane_u16(c1, vreinterpret_u16_f16(vfp16out1x0123), 0);
468 vst1_lane_u16(c2, vreinterpret_u16_f16(vfp16out2x0123), 0);
469 vst1_lane_u16(c3, vreinterpret_u16_f16(vfp16out3x0123), 0);
470 vst1_lane_u16(c4, vreinterpret_u16_f16(vfp16out4x0123), 0);
471 }
472 nc = 0;
473 }
474 } while (nc != 0);
475 }