Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-1x16c8-minmax-fp32-aarch64-neondot-ld128.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c8-neondot.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/intrinsics-polyfill.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x16c8__aarch64_neondot_ld128(
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 <= 1);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (1 * 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
47 do {
48 const int32x4_t vinit0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
49 const int32x4_t vinit0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
50 const int32x4_t vinit0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
51 const int32x4_t vinit0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
52 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
53 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
54 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
55 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
56 int32x4_t vacc0x89 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x89AB))));
57 int32x4_t vacc0xAB = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x89AB))));
58 int32x4_t vacc0xCD = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
59 int32x4_t vacc0xEF = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
60
61 size_t p = ks;
62 do {
63 const int8_t* restrict a0 = a[0];
64 if XNN_UNPREDICTABLE(a0 != zero) {
65 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
66 }
67 a += 1;
68
69 size_t k = kc;
70 for (; k >= 16 * sizeof(int8_t); k -= 16 * sizeof(int8_t)) {
71 const uint64x2x2_t va0c0123456789ABCDEF = vld2q_dup_u64((const void*) a0); a0 += 16;
72
73 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
74 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
75 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
76 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
77 const int8x16_t vb89c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
78 const int8x16_t vbABc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
79 const int8x16_t vbCDc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
80 const int8x16_t vbEFc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
81
82 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
83 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
84 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
85 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
86 vacc0x89 = vdotq_s32(vacc0x89, vb89c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
87 vacc0xAB = vdotq_s32(vacc0xAB, vbABc01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
88 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
89 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
90
91 const int8x16_t vb01c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
92 const int8x16_t vb23c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
93 const int8x16_t vb45c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
94 const int8x16_t vb67c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
95 const int8x16_t vb89c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
96 const int8x16_t vbABc89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
97 const int8x16_t vbCDc89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
98 const int8x16_t vbEFc89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
99
100 vacc0x01 = vdotq_s32(vacc0x01, vb01c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
101 vacc0x23 = vdotq_s32(vacc0x23, vb23c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
102 vacc0x45 = vdotq_s32(vacc0x45, vb45c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
103 vacc0x67 = vdotq_s32(vacc0x67, vb67c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
104 vacc0x89 = vdotq_s32(vacc0x89, vb89c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
105 vacc0xAB = vdotq_s32(vacc0xAB, vbABc89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
106 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
107 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
108 }
109 if XNN_LIKELY(k != 0) {
110 assert(k == 8 * sizeof(int8_t));
111
112 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
113
114 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
115 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
116 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
117 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
118 const int8x16_t vb89c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
119 const int8x16_t vbABc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
120 const int8x16_t vbCDc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
121 const int8x16_t vbEFc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
122
123 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
124 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
125 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
126 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
127 vacc0x89 = vdotq_s32(vacc0x89, vb89c01234567, va0c01234567);
128 vacc0xAB = vdotq_s32(vacc0xAB, vbABc01234567, va0c01234567);
129 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc01234567, va0c01234567);
130 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc01234567, va0c01234567);
131 }
132 p -= 1 * sizeof(void*);
133 } while (p != 0);
134
135 #if XNN_ARCH_ARM64
136 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
137 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
138 int32x4_t vacc0x89AB = vpaddq_s32(vacc0x89, vacc0xAB);
139 int32x4_t vacc0xCDEF = vpaddq_s32(vacc0xCD, vacc0xEF);
140 #else
141 int32x4_t vacc0x0123 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)), vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)));
142 int32x4_t vacc0x4567 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)), vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)));
143 int32x4_t vacc0x89AB = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x89), vget_high_s32(vacc0x89)), vpadd_s32(vget_low_s32(vacc0xAB), vget_high_s32(vacc0xAB)));
144 int32x4_t vacc0xCDEF = vcombine_s32(vpadd_s32(vget_low_s32(vacc0xCD), vget_high_s32(vacc0xCD)), vpadd_s32(vget_low_s32(vacc0xEF), vget_high_s32(vacc0xEF)));
145 #endif
146
147 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
148 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
149 float32x4_t vfpacc0x89AB = vcvtq_f32_s32(vacc0x89AB);
150 float32x4_t vfpacc0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
151
152 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4;
153 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
154 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4;
155 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
156 const float32x4_t vscale89AB = vld1q_f32((const float*) w); w = (const float*) w + 4;
157 vfpacc0x89AB = vmulq_f32(vfpacc0x89AB, vscale89AB);
158 const float32x4_t vscaleCDEF = vld1q_f32((const float*) w); w = (const float*) w + 4;
159 vfpacc0xCDEF = vmulq_f32(vfpacc0xCDEF, vscaleCDEF);
160
161 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
162 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
163 vacc0x89AB = vcvtnq_s32_f32(vfpacc0x89AB);
164 vacc0xCDEF = vcvtnq_s32_f32(vfpacc0xCDEF);
165
166 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
167 #if XNN_ARCH_ARM64
168 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
169 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point);
170
171 int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
172 #else
173 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
174 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point);
175
176 int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
177 #endif
178 const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min);
179 const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max);
180
181 vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
182
183 vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
184
185 if (nc >= 16) {
186 // Main case where there the 16 columns fit in the destination.
187 vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
188
189 // Advance to the next 16 columns.
190 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
191
192 a = (const int8_t**restrict) ((uintptr_t) a - ks);
193
194 nc -= 16;
195 } else {
196 // Final case where not all of the 16 columns fit in the destination.
197 int8x8_t vout0x01234567 = vget_low_s8(vout0x0123456789ABCDEF);
198 if (nc & 8) {
199 vst1_s8(c0, vout0x01234567); c0 += 8;
200 vout0x01234567 = vget_high_s8(vout0x0123456789ABCDEF);
201 }
202 if (nc & 4) {
203 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
204 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
205 }
206 if (nc & 2) {
207 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
208 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
209 }
210 if (nc & 1) {
211 vst1_lane_s8(c0, vout0x01234567, 0);
212 }
213
214 nc = 0;
215 }
216 } while (nc != 0);
217 }