Debian Codegraph @

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