Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-2x8-minmax-neon-mlal-lane.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/neon-mlal-lane.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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/common.h"
15 #include "xnnpack/gemm.h"
16
17
18 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_2x8__neon_mlal_lane(
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 float* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_f32_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 <= 2);
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 const int8_t* a0 = a;
41 float* c0 = c;
42 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
43 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44 if XNN_UNPREDICTABLE(mr != 2) {
45 a1 = a0;
46 c1 = c0;
47 }
48
49 do {
50 int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
51 int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
52 const int32x4_t vzp01 = vld1q_s32(&quantization_params[0].zero_point);
53 int32x4_t vacc0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vzp01), 0);
54 int32x4_t vacc1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vzp01), 0);
55 int32x4_t vacc0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vzp01), 0);
56 int32x4_t vacc1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vzp01), 0);
57
58 size_t k = kc;
59 while (k >= 8 * sizeof(int8_t)) {
60 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
61 const int16x8_t vxa0 = vmovl_s8(va0);
62 const int8x8_t va1 = vld1_s8(a1); a1 += 8;
63 const int16x8_t vxa1 = vmovl_s8(va1);
64
65 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
66 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
67 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
68 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
69 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
70 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
71 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
72 const int8x8_t vb01234567c7 = vld1_s8(w); w = (const int8_t*) w + 8;
73
74 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
75 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
76 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
77 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
78 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
79 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
80 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
81 const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7);
82
83
84 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
85 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
86 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
87 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
88 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
89 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
90 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
91 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
92 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
93 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
94 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
95 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
96 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
97 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
98 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
99 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
100
101 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
102 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
103 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
104 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
105 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
106 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
107 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
108 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
109 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
110 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
111 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
112 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
113 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
114 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
115 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3);
116 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3);
117
118 k -= 8 * sizeof(int8_t);
119 }
120 if XNN_UNLIKELY(k != 0) {
121 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
122 const int16x8_t vxa0 = vmovl_s8(va0);
123 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
124 const int16x8_t vxa1 = vmovl_s8(va1);
125
126 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
127
128 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
129
130 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
131 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
132 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
133 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
134
135 if (k >= 2 * sizeof(int8_t)) {
136 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
137 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
138
139 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
140 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
141 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
142 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
143
144 if (k > 2 * sizeof(int8_t)) {
145 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
146 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
147
148 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
149 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
150 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
151 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
152
153 if (k >= 4 * sizeof(int8_t)) {
154 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
155 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
156
157 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
158 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
159 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
160 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
161
162 if (k > 4 * sizeof(int8_t)) {
163 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
164 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
165
166 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
167 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
168 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
169 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
170
171 if (k >= 6 * sizeof(int8_t)) {
172 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
173 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
174
175 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
176 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
177 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
178 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
179
180 if (k > 6 * sizeof(int8_t)) {
181 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
182 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
183
184 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
185 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
186 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
187 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
188 }
189 }
190 }
191 }
192 }
193 }
194 }
195
196 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
197 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
198 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
199 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
200
201 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
202 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
203 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
204 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
205 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
206
207 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
208 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
209
210 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
211 #if XNN_ARCH_ARM64
212 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
213 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
214 #else
215 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
216 vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
217 #endif
218 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
219 #if XNN_ARCH_ARM64
220 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
221 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
222 #else
223 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
224 vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
225 #endif
226
227 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
228 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
229 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
230 vout1x0123 = vmaxq_f32(vout1x0123, voutput_min);
231 vout1x4567 = vmaxq_f32(vout1x4567, voutput_min);
232
233 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
234 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
235 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
236 vout1x0123 = vminq_f32(vout1x0123, voutput_max);
237 vout1x4567 = vminq_f32(vout1x4567, voutput_max);
238
239 if XNN_LIKELY(nc >= 8) {
240 vst1q_f32(&c0[0], vout0x0123);
241 vst1q_f32(&c0[4], vout0x4567);
242 vst1q_f32(&c1[0], vout1x0123);
243 vst1q_f32(&c1[4], vout1x4567);
244
245 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
246 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
247
248 c0 = (float*) ((uintptr_t) c0 + cn_stride);
249 c1 = (float*) ((uintptr_t) c1 + cn_stride);
250
251 nc -= 8;
252 } else {
253 if (nc & 4) {
254 vst1q_f32(c0, vout0x0123); c0 += 4;
255 vout0x0123 = vout0x4567;
256 vst1q_f32(c1, vout1x0123); c1 += 4;
257 vout1x0123 = vout1x4567;
258 }
259 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
260 float32x2_t vout1x01 = vget_low_f32(vout1x0123);
261 if (nc & 2) {
262 vst1_f32(c0, vout0x01); c0 += 2;
263 vst1_f32(c1, vout1x01); c1 += 2;
264 vout0x01 = vget_high_f32(vout0x0123);
265 vout1x01 = vget_high_f32(vout1x0123);
266 }
267 if (nc & 1) {
268 vst1_lane_f32(c0, vout0x01, 0);
269 vst1_lane_f32(c1, vout1x01, 0);
270 }
271 nc = 0;
272 }
273 } while (nc != 0);
274 }