Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-8x8c8-minmax-fp32-neoni8mm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/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/igemm.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_8x8c8__neoni8mm(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 size_t ks,
24 const int8_t** restrict a,
25 const void* restrict w,
26 int8_t* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 size_t a_offset,
30 const int8_t* zero,
31 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
32 {
33 assert(mr != 0);
34 assert(mr <= 8);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (8 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(int8_t) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 kc = round_up_po2(kc, 8 * sizeof(int8_t));
45 int8_t* c0 = c;
46 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
47 if XNN_UNPREDICTABLE(mr < 2) {
48 c1 = c0;
49 }
50 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
51 if XNN_UNPREDICTABLE(mr <= 2) {
52 c2 = c1;
53 }
54 int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
55 if XNN_UNPREDICTABLE(mr < 4) {
56 c3 = c2;
57 }
58 int8_t* c4 = (int8_t*) ((uintptr_t) c3 + cm_stride);
59 if XNN_UNPREDICTABLE(mr <= 4) {
60 c4 = c3;
61 }
62 int8_t* c5 = (int8_t*) ((uintptr_t) c4 + cm_stride);
63 if XNN_UNPREDICTABLE(mr < 6) {
64 c5 = c4;
65 }
66 int8_t* c6 = (int8_t*) ((uintptr_t) c5 + cm_stride);
67 if XNN_UNPREDICTABLE(mr <= 6) {
68 c6 = c5;
69 }
70 int8_t* c7 = (int8_t*) ((uintptr_t) c6 + cm_stride);
71 if XNN_UNPREDICTABLE(mr != 8) {
72 c7 = c6;
73 }
74
75 do {
76 const uint64x2x2_t vbias01x0123 = vld2q_dup_u64(w); w = (const int32_t*) w + 4;
77 const uint64x2x2_t vbias01x4567 = vld2q_dup_u64(w); w = (const int32_t*) w + 4;
78 int32x4_t vacc01x01 = vreinterpretq_s32_u64(vbias01x0123.val[0]);
79 int32x4_t vacc01x23 = vreinterpretq_s32_u64(vbias01x0123.val[1]);
80 int32x4_t vacc01x45 = vreinterpretq_s32_u64(vbias01x4567.val[0]);
81 int32x4_t vacc01x67 = vreinterpretq_s32_u64(vbias01x4567.val[1]);
82 int32x4_t vacc23x01 = vreinterpretq_s32_u64(vbias01x0123.val[0]);
83 int32x4_t vacc23x23 = vreinterpretq_s32_u64(vbias01x0123.val[1]);
84 int32x4_t vacc23x45 = vreinterpretq_s32_u64(vbias01x4567.val[0]);
85 int32x4_t vacc23x67 = vreinterpretq_s32_u64(vbias01x4567.val[1]);
86 int32x4_t vacc45x01 = vreinterpretq_s32_u64(vbias01x0123.val[0]);
87 int32x4_t vacc45x23 = vreinterpretq_s32_u64(vbias01x0123.val[1]);
88 int32x4_t vacc45x45 = vreinterpretq_s32_u64(vbias01x4567.val[0]);
89 int32x4_t vacc45x67 = vreinterpretq_s32_u64(vbias01x4567.val[1]);
90 int32x4_t vacc67x01 = vreinterpretq_s32_u64(vbias01x0123.val[0]);
91 int32x4_t vacc67x23 = vreinterpretq_s32_u64(vbias01x0123.val[1]);
92 int32x4_t vacc67x45 = vreinterpretq_s32_u64(vbias01x4567.val[0]);
93 int32x4_t vacc67x67 = vreinterpretq_s32_u64(vbias01x4567.val[1]);
94
95 size_t p = ks;
96 do {
97 const int8_t* restrict a0 = a[0];
98 if XNN_UNPREDICTABLE(a0 != zero) {
99 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
100 }
101 const int8_t* restrict a1 = a[1];
102 if XNN_UNPREDICTABLE(a1 != zero) {
103 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
104 }
105 const int8_t* restrict a2 = a[2];
106 if XNN_UNPREDICTABLE(a2 != zero) {
107 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
108 }
109 const int8_t* restrict a3 = a[3];
110 if XNN_UNPREDICTABLE(a3 != zero) {
111 a3 = (const int8_t*) ((uintptr_t) a3 + a_offset);
112 }
113 const int8_t* restrict a4 = a[4];
114 if XNN_UNPREDICTABLE(a4 != zero) {
115 a4 = (const int8_t*) ((uintptr_t) a4 + a_offset);
116 }
117 const int8_t* restrict a5 = a[5];
118 if XNN_UNPREDICTABLE(a5 != zero) {
119 a5 = (const int8_t*) ((uintptr_t) a5 + a_offset);
120 }
121 const int8_t* restrict a6 = a[6];
122 if XNN_UNPREDICTABLE(a6 != zero) {
123 a6 = (const int8_t*) ((uintptr_t) a6 + a_offset);
124 }
125 const int8_t* restrict a7 = a[7];
126 if XNN_UNPREDICTABLE(a7 != zero) {
127 a7 = (const int8_t*) ((uintptr_t) a7 + a_offset);
128 }
129 a += 8;
130
131 uint64x2x2_t va01x0123456789ABCDEF;
132 va01x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
133 va01x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
134 uint64x2x2_t va23x0123456789ABCDEF;
135 va23x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
136 va23x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
137 uint64x2x2_t va45x0123456789ABCDEF;
138 va45x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
139 va45x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
140 uint64x2x2_t va67x0123456789ABCDEF;
141 va67x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
142 va67x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
143
144 // Inner accumulation loop along the 8 columns.
145 size_t k = kc;
146 // 2x partial unrolled loop to load 8 bytes at a time.
147 while (k >= 16 * sizeof(int8_t)) {
148 // Load a 8x16 block of activations.
149 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a0, va01x0123456789ABCDEF, 0); a0 += 16;
150 va23x0123456789ABCDEF = vld2q_lane_u64((const void*) a2, va23x0123456789ABCDEF, 0); a2 += 16;
151 va45x0123456789ABCDEF = vld2q_lane_u64((const void*) a4, va45x0123456789ABCDEF, 0); a4 += 16;
152 va67x0123456789ABCDEF = vld2q_lane_u64((const void*) a6, va67x0123456789ABCDEF, 0); a6 += 16;
153 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a1, va01x0123456789ABCDEF, 1); a1 += 16;
154 va23x0123456789ABCDEF = vld2q_lane_u64((const void*) a3, va23x0123456789ABCDEF, 1); a3 += 16;
155 va45x0123456789ABCDEF = vld2q_lane_u64((const void*) a5, va45x0123456789ABCDEF, 1); a5 += 16;
156 va67x0123456789ABCDEF = vld2q_lane_u64((const void*) a7, va67x0123456789ABCDEF, 1); a7 += 16;
157
158 // Load a 16x8 block of weights.
159 const int8x16_t vb01x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
160 const int8x16_t vb23x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
161 const int8x16_t vb45x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
162 const int8x16_t vb67x01234567 = 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
168 // Multiply-accumulate: 8x16 * 16x8 --> 8x8.
169 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb01x01234567);
170 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb23x01234567);
171 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb45x01234567);
172 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb67x01234567);
173 vacc23x01 = vmmlaq_s32(vacc23x01, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[0]), vb01x01234567);
174 vacc23x23 = vmmlaq_s32(vacc23x23, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[0]), vb23x01234567);
175 vacc23x45 = vmmlaq_s32(vacc23x45, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[0]), vb45x01234567);
176 vacc23x67 = vmmlaq_s32(vacc23x67, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[0]), vb67x01234567);
177 vacc45x01 = vmmlaq_s32(vacc45x01, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[0]), vb01x01234567);
178 vacc45x23 = vmmlaq_s32(vacc45x23, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[0]), vb23x01234567);
179 vacc45x45 = vmmlaq_s32(vacc45x45, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[0]), vb45x01234567);
180 vacc45x67 = vmmlaq_s32(vacc45x67, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[0]), vb67x01234567);
181 vacc67x01 = vmmlaq_s32(vacc67x01, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[0]), vb01x01234567);
182 vacc67x23 = vmmlaq_s32(vacc67x23, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[0]), vb23x01234567);
183 vacc67x45 = vmmlaq_s32(vacc67x45, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[0]), vb45x01234567);
184 vacc67x67 = vmmlaq_s32(vacc67x67, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[0]), vb67x01234567);
185 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb01x89ABCDEF);
186 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb23x89ABCDEF);
187 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb45x89ABCDEF);
188 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb67x89ABCDEF);
189 vacc23x01 = vmmlaq_s32(vacc23x01, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[1]), vb01x89ABCDEF);
190 vacc23x23 = vmmlaq_s32(vacc23x23, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[1]), vb23x89ABCDEF);
191 vacc23x45 = vmmlaq_s32(vacc23x45, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[1]), vb45x89ABCDEF);
192 vacc23x67 = vmmlaq_s32(vacc23x67, vreinterpretq_s8_u64(va23x0123456789ABCDEF.val[1]), vb67x89ABCDEF);
193 vacc45x01 = vmmlaq_s32(vacc45x01, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[1]), vb01x89ABCDEF);
194 vacc45x23 = vmmlaq_s32(vacc45x23, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[1]), vb23x89ABCDEF);
195 vacc45x45 = vmmlaq_s32(vacc45x45, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[1]), vb45x89ABCDEF);
196 vacc45x67 = vmmlaq_s32(vacc45x67, vreinterpretq_s8_u64(va45x0123456789ABCDEF.val[1]), vb67x89ABCDEF);
197 vacc67x01 = vmmlaq_s32(vacc67x01, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[1]), vb01x89ABCDEF);
198 vacc67x23 = vmmlaq_s32(vacc67x23, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[1]), vb23x89ABCDEF);
199 vacc67x45 = vmmlaq_s32(vacc67x45, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[1]), vb45x89ABCDEF);
200 vacc67x67 = vmmlaq_s32(vacc67x67, vreinterpretq_s8_u64(va67x0123456789ABCDEF.val[1]), vb67x89ABCDEF);
201
202 k -= 16 * sizeof(int8_t);
203 }
204 // Handle up to 8 final positions of `k`
205 if XNN_UNLIKELY(k != 0) {
206 // Load a 8x8 block of activations.
207 uint64x2_t va01x01234567 = vld1q_dup_u64((const void*) a0); a0 += 8;
208 uint64x2_t va23x01234567 = vld1q_dup_u64((const void*) a2); a2 += 8;
209 uint64x2_t va45x01234567 = vld1q_dup_u64((const void*) a4); a4 += 8;
210 uint64x2_t va67x01234567 = vld1q_dup_u64((const void*) a6); a6 += 8;
211 va01x01234567 = vld1q_lane_u64((const void*) a1, va01x01234567, 1); a1 += 8;
212 va23x01234567 = vld1q_lane_u64((const void*) a3, va23x01234567, 1); a3 += 8;
213 va45x01234567 = vld1q_lane_u64((const void*) a5, va45x01234567, 1); a5 += 8;
214 va67x01234567 = vld1q_lane_u64((const void*) a7, va67x01234567, 1); a7 += 8;
215
216 // Load a 16x8 block of weights.
217 const int8x16_t vb01x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
218 const int8x16_t vb23x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
219 const int8x16_t vb45x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
220 const int8x16_t vb67x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
221
222 // Multiply-accumulate: 8x4 * 4x8 --> 8x8.
223 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x01234567), vb01x01234567);
224 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x01234567), vb23x01234567);
225 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x01234567), vb45x01234567);
226 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x01234567), vb67x01234567);
227 vacc23x01 = vmmlaq_s32(vacc23x01, vreinterpretq_s8_u64(va23x01234567), vb01x01234567);
228 vacc23x23 = vmmlaq_s32(vacc23x23, vreinterpretq_s8_u64(va23x01234567), vb23x01234567);
229 vacc23x45 = vmmlaq_s32(vacc23x45, vreinterpretq_s8_u64(va23x01234567), vb45x01234567);
230 vacc23x67 = vmmlaq_s32(vacc23x67, vreinterpretq_s8_u64(va23x01234567), vb67x01234567);
231 vacc45x01 = vmmlaq_s32(vacc45x01, vreinterpretq_s8_u64(va45x01234567), vb01x01234567);
232 vacc45x23 = vmmlaq_s32(vacc45x23, vreinterpretq_s8_u64(va45x01234567), vb23x01234567);
233 vacc45x45 = vmmlaq_s32(vacc45x45, vreinterpretq_s8_u64(va45x01234567), vb45x01234567);
234 vacc45x67 = vmmlaq_s32(vacc45x67, vreinterpretq_s8_u64(va45x01234567), vb67x01234567);
235 vacc67x01 = vmmlaq_s32(vacc67x01, vreinterpretq_s8_u64(va67x01234567), vb01x01234567);
236 vacc67x23 = vmmlaq_s32(vacc67x23, vreinterpretq_s8_u64(va67x01234567), vb23x01234567);
237 vacc67x45 = vmmlaq_s32(vacc67x45, vreinterpretq_s8_u64(va67x01234567), vb45x01234567);
238 vacc67x67 = vmmlaq_s32(vacc67x67, vreinterpretq_s8_u64(va67x01234567), vb67x01234567);
239 }
240
241 p -= 8 * sizeof(void*);
242 } while (p != 0);
243
244 int32x4_t vacc0x0123 = vcombine_s32(vget_low_s32(vacc01x01), vget_low_s32(vacc01x23));
245 int32x4_t vacc1x0123 = vcombine_s32(vget_high_s32(vacc01x01), vget_high_s32(vacc01x23));
246 int32x4_t vacc0x4567 = vcombine_s32(vget_low_s32(vacc01x45), vget_low_s32(vacc01x67));
247 int32x4_t vacc1x4567 = vcombine_s32(vget_high_s32(vacc01x45), vget_high_s32(vacc01x67));
248 int32x4_t vacc2x0123 = vcombine_s32(vget_low_s32(vacc23x01), vget_low_s32(vacc23x23));
249 int32x4_t vacc3x0123 = vcombine_s32(vget_high_s32(vacc23x01), vget_high_s32(vacc23x23));
250 int32x4_t vacc2x4567 = vcombine_s32(vget_low_s32(vacc23x45), vget_low_s32(vacc23x67));
251 int32x4_t vacc3x4567 = vcombine_s32(vget_high_s32(vacc23x45), vget_high_s32(vacc23x67));
252 int32x4_t vacc4x0123 = vcombine_s32(vget_low_s32(vacc45x01), vget_low_s32(vacc45x23));
253 int32x4_t vacc5x0123 = vcombine_s32(vget_high_s32(vacc45x01), vget_high_s32(vacc45x23));
254 int32x4_t vacc4x4567 = vcombine_s32(vget_low_s32(vacc45x45), vget_low_s32(vacc45x67));
255 int32x4_t vacc5x4567 = vcombine_s32(vget_high_s32(vacc45x45), vget_high_s32(vacc45x67));
256 int32x4_t vacc6x0123 = vcombine_s32(vget_low_s32(vacc67x01), vget_low_s32(vacc67x23));
257 int32x4_t vacc7x0123 = vcombine_s32(vget_high_s32(vacc67x01), vget_high_s32(vacc67x23));
258 int32x4_t vacc6x4567 = vcombine_s32(vget_low_s32(vacc67x45), vget_low_s32(vacc67x67));
259 int32x4_t vacc7x4567 = vcombine_s32(vget_high_s32(vacc67x45), vget_high_s32(vacc67x67));
260
261 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
262 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
263 float32x4_t vfpacc1x0123 = vcvtq_f32_s32(vacc1x0123);
264 float32x4_t vfpacc1x4567 = vcvtq_f32_s32(vacc1x4567);
265 float32x4_t vfpacc2x0123 = vcvtq_f32_s32(vacc2x0123);
266 float32x4_t vfpacc2x4567 = vcvtq_f32_s32(vacc2x4567);
267 float32x4_t vfpacc3x0123 = vcvtq_f32_s32(vacc3x0123);
268 float32x4_t vfpacc3x4567 = vcvtq_f32_s32(vacc3x4567);
269 float32x4_t vfpacc4x0123 = vcvtq_f32_s32(vacc4x0123);
270 float32x4_t vfpacc4x4567 = vcvtq_f32_s32(vacc4x4567);
271 float32x4_t vfpacc5x0123 = vcvtq_f32_s32(vacc5x0123);
272 float32x4_t vfpacc5x4567 = vcvtq_f32_s32(vacc5x4567);
273 float32x4_t vfpacc6x0123 = vcvtq_f32_s32(vacc6x0123);
274 float32x4_t vfpacc6x4567 = vcvtq_f32_s32(vacc6x4567);
275 float32x4_t vfpacc7x0123 = vcvtq_f32_s32(vacc7x0123);
276 float32x4_t vfpacc7x4567 = vcvtq_f32_s32(vacc7x4567);
277
278 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4;
279 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
280 vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123);
281 vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123);
282 vfpacc3x0123 = vmulq_f32(vfpacc3x0123, vscale0123);
283 vfpacc4x0123 = vmulq_f32(vfpacc4x0123, vscale0123);
284 vfpacc5x0123 = vmulq_f32(vfpacc5x0123, vscale0123);
285 vfpacc6x0123 = vmulq_f32(vfpacc6x0123, vscale0123);
286 vfpacc7x0123 = vmulq_f32(vfpacc7x0123, vscale0123);
287 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4;
288 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
289 vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567);
290 vfpacc2x4567 = vmulq_f32(vfpacc2x4567, vscale4567);
291 vfpacc3x4567 = vmulq_f32(vfpacc3x4567, vscale4567);
292 vfpacc4x4567 = vmulq_f32(vfpacc4x4567, vscale4567);
293 vfpacc5x4567 = vmulq_f32(vfpacc5x4567, vscale4567);
294 vfpacc6x4567 = vmulq_f32(vfpacc6x4567, vscale4567);
295 vfpacc7x4567 = vmulq_f32(vfpacc7x4567, vscale4567);
296
297 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
298 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
299 vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123);
300 vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567);
301 vacc2x0123 = vcvtnq_s32_f32(vfpacc2x0123);
302 vacc2x4567 = vcvtnq_s32_f32(vfpacc2x4567);
303 vacc3x0123 = vcvtnq_s32_f32(vfpacc3x0123);
304 vacc3x4567 = vcvtnq_s32_f32(vfpacc3x4567);
305 vacc4x0123 = vcvtnq_s32_f32(vfpacc4x0123);
306 vacc4x4567 = vcvtnq_s32_f32(vfpacc4x4567);
307 vacc5x0123 = vcvtnq_s32_f32(vfpacc5x0123);
308 vacc5x4567 = vcvtnq_s32_f32(vfpacc5x4567);
309 vacc6x0123 = vcvtnq_s32_f32(vfpacc6x0123);
310 vacc6x4567 = vcvtnq_s32_f32(vfpacc6x4567);
311 vacc7x0123 = vcvtnq_s32_f32(vfpacc7x0123);
312 vacc7x4567 = vcvtnq_s32_f32(vfpacc7x4567);
313
314 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
315 #if XNN_ARCH_ARM64
316 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
317 const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
318 const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point);
319 const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point);
320 const int16x8_t vacc4x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc4x0123), vacc4x4567), voutput_zero_point);
321 const int16x8_t vacc5x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc5x0123), vacc5x4567), voutput_zero_point);
322 const int16x8_t vacc6x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc6x0123), vacc6x4567), voutput_zero_point);
323 const int16x8_t vacc7x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc7x0123), vacc7x4567), voutput_zero_point);
324
325 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
326 int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567);
327 int8x16_t vout4x01234567_5x01234567 = vqmovn_high_s16(vqmovn_s16(vacc4x01234567), vacc5x01234567);
328 int8x16_t vout6x01234567_7x01234567 = vqmovn_high_s16(vqmovn_s16(vacc6x01234567), vacc7x01234567);
329 #else
330 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
331 const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
332 const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point);
333 const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point);
334 const int16x8_t vacc4x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc4x0123), vqmovn_s32(vacc4x4567)), voutput_zero_point);
335 const int16x8_t vacc5x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc5x0123), vqmovn_s32(vacc5x4567)), voutput_zero_point);
336 const int16x8_t vacc6x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc6x0123), vqmovn_s32(vacc6x4567)), voutput_zero_point);
337 const int16x8_t vacc7x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc7x0123), vqmovn_s32(vacc7x4567)), voutput_zero_point);
338
339 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
340 int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567));
341 int8x16_t vout4x01234567_5x01234567 = vcombine_s8(vqmovn_s16(vacc4x01234567), vqmovn_s16(vacc5x01234567));
342 int8x16_t vout6x01234567_7x01234567 = vcombine_s8(vqmovn_s16(vacc6x01234567), vqmovn_s16(vacc7x01234567));
343 #endif
344 const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min);
345 const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max);
346
347 vout6x01234567_7x01234567 = vmaxq_s8(vout6x01234567_7x01234567, voutput_min);
348 vout4x01234567_5x01234567 = vmaxq_s8(vout4x01234567_5x01234567, voutput_min);
349 vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min);
350 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
351
352 vout6x01234567_7x01234567 = vminq_s8(vout6x01234567_7x01234567, voutput_max);
353 vout4x01234567_5x01234567 = vminq_s8(vout4x01234567_5x01234567, voutput_max);
354 vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max);
355 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
356
357 if (nc >= 8) {
358 vst1_s8(c7, vget_high_s8(vout6x01234567_7x01234567));
359 vst1_s8(c6, vget_low_s8(vout6x01234567_7x01234567));
360 vst1_s8(c5, vget_high_s8(vout4x01234567_5x01234567));
361 vst1_s8(c4, vget_low_s8(vout4x01234567_5x01234567));
362 vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567));
363 vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567));
364 vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567));
365 vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567));
366
367 c7 = (int8_t*) ((uintptr_t) c7 + cn_stride);
368 c6 = (int8_t*) ((uintptr_t) c6 + cn_stride);
369 c5 = (int8_t*) ((uintptr_t) c5 + cn_stride);
370 c4 = (int8_t*) ((uintptr_t) c4 + cn_stride);
371 c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
372 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
373 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
374 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
375
376 a = (const int8_t**restrict) ((uintptr_t) a - ks);
377
378 nc -= 8;
379 } else {
380 if (nc & 4) {
381 vst1q_lane_u32((void*) c7, vreinterpretq_u32_s8(vout6x01234567_7x01234567), 2); c7 += 4;
382 vst1q_lane_u32((void*) c6, vreinterpretq_u32_s8(vout6x01234567_7x01234567), 0); c6 += 4;
383 vst1q_lane_u32((void*) c5, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 2); c5 += 4;
384 vst1q_lane_u32((void*) c4, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 0); c4 += 4;
385 vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4;
386 vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4;
387 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
388 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
389 vout6x01234567_7x01234567 = vextq_s8(vout6x01234567_7x01234567, vout6x01234567_7x01234567, 4);
390 vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 4);
391 vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4);
392 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
393 }
394 if (nc & 2) {
395 vst1q_lane_u16((void*) c7, vreinterpretq_u16_s8(vout6x01234567_7x01234567), 4); c7 += 2;
396 vst1q_lane_u16((void*) c6, vreinterpretq_u16_s8(vout6x01234567_7x01234567), 0); c6 += 2;
397 vst1q_lane_u16((void*) c5, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 4); c5 += 2;
398 vst1q_lane_u16((void*) c4, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 0); c4 += 2;
399 vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2;
400 vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2;
401 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
402 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
403 vout6x01234567_7x01234567 = vextq_s8(vout6x01234567_7x01234567, vout6x01234567_7x01234567, 2);
404 vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 2);
405 vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2);
406 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
407 }
408 if (nc & 1) {
409 vst1q_lane_s8(c7, vout6x01234567_7x01234567, 8);
410 vst1q_lane_s8(c6, vout6x01234567_7x01234567, 0);
411 vst1q_lane_s8(c5, vout4x01234567_5x01234567, 8);
412 vst1q_lane_s8(c4, vout4x01234567_5x01234567, 0);
413 vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8);
414 vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0);
415 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
416 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
417 }
418
419 nc = 0;
420 }
421 } while (nc != 0);
422 }