Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x8-minmax-neon-mlal-lane-prfm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/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
11 #include <assert.h>
12
13 #include <arm_neon.h>
14
15 #include "xnnpack/common.h"
16 #include "xnnpack/igemm.h"
17 #include "xnnpack/prefetch.h"
18
19
20 void xnn_qd8_f32_qc8w_igemm_minmax_ukernel_1x8__neon_mlal_lane_prfm(
21 size_t mr,
22 size_t nc,
23 size_t kc,
24 size_t ks,
25 const int8_t** restrict a,
26 const void* restrict w,
27 float* restrict c,
28 size_t cm_stride,
29 size_t cn_stride,
30 size_t a_offset,
31 const int8_t* zero,
32 const int8_t* zero_data,
33 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
34 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
35 {
36 assert(mr != 0);
37 assert(mr <= 1);
38 assert(nc != 0);
39 assert(kc != 0);
40 assert(ks != 0);
41 assert(ks % (1 * sizeof(void*)) == 0);
42 assert(a_offset % sizeof(int8_t) == 0);
43 assert(a != NULL);
44 assert(w != NULL);
45 assert(c != NULL);
46
47 float* c0 = c;
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 vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
53 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
54 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
55
56 size_t p = ks;
57 do {
58 const int8_t* restrict a0 = a[0];
59 if XNN_UNPREDICTABLE(a0 != zero) {
60 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
61 } else {
62 a0 = zero_data;
63 }
64 a += 1;
65
66 size_t k = kc;
67 while (k >= 8 * sizeof(int8_t)) {
68 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
69 const int16x8_t vxa0 = vmovl_s8(va0);
70
71 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
72 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
73
74 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
75 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
76 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
77 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
78
79 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
80 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
81 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
82 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
83
84 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
85 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
86 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
87 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
88
89 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
90 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
91
92 xnn_prefetch_to_l1((const int8_t*) w + 448);
93
94 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
95 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
96
97 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
98 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
99 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
100 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
101
102 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
103 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
104 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
105 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
106
107 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
108 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
109 const int8x8_t vb01234567c7 = vld1_s8(w); w = (const int8_t*) w + 8;
110 const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7);
111
112 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
113 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
114
115 k -= 8 * sizeof(int8_t);
116 }
117 if XNN_UNLIKELY(k != 0) {
118 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
119 const int16x8_t vxa0 = vmovl_s8(va0);
120
121 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
122 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
123
124 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
125 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
126
127 if (k >= 2 * sizeof(int8_t)) {
128 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
129 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
130
131 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
132 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
133
134 if (k > 2 * sizeof(int8_t)) {
135 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
136 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
137
138 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
139 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
140
141 if (k >= 4 * sizeof(int8_t)) {
142 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
143 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
144
145 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
146 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
147
148 if (k > 4 * sizeof(int8_t)) {
149 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
150 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
151
152 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
153 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
154
155 if (k >= 6 * sizeof(int8_t)) {
156 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
157 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
158
159 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
160 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
161
162 if (k > 6 * sizeof(int8_t)) {
163 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
164 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
165
166 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
167 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
168 }
169 }
170 }
171 }
172 }
173 }
174 }
175 p -= 1 * sizeof(void*);
176 } while (p != 0);
177
178 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
179 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
180
181 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
182 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
183 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
184
185 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
186 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
187
188 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
189 #if XNN_ARCH_ARM64
190 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
191 #else
192 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
193 #endif
194 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
195 #if XNN_ARCH_ARM64
196 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
197 #else
198 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
199 #endif
200
201 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
202 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
203 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
204
205 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
206 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
207 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
208
209 if XNN_LIKELY(nc >= 8) {
210 vst1q_f32(&c0[0], vout0x0123);
211 vst1q_f32(&c0[4], vout0x4567);
212
213 a = (const int8_t**restrict) ((uintptr_t) a - ks);
214
215 c0 = (float*) ((uintptr_t) c0 + cn_stride);
216
217 nc -= 8;
218 } else {
219 if (nc & 4) {
220 vst1q_f32(c0, vout0x0123); c0 += 4;
221 vout0x0123 = vout0x4567;
222 }
223 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
224 if (nc & 2) {
225 vst1_f32(c0, vout0x01); c0 += 2;
226 vout0x01 = vget_high_f32(vout0x0123);
227 }
228 if (nc & 1) {
229 vst1_lane_f32(c0, vout0x01, 0);
230 }
231 nc = 0;
232 }
233 } while (nc != 0);
234 }