Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8-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_1x8__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 <= 1);
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
43 do {
44 int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
45 int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
46 const int32x4_t vzp0 = vld1q_dup_s32(&quantization_params[0].zero_point);
47 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vzp0);
48 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vzp0);
49
50 size_t k = kc;
51 while (k >= 8 * sizeof(int8_t)) {
52 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
53 const int16x8_t vxa0 = vmovl_s8(va0);
54
55 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
56 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
57 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
58 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
59 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
60 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
61 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
62 const int8x8_t vb01234567c7 = vld1_s8(w); w = (const int8_t*) w + 8;
63
64 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
65 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
66 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
67 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
68 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
69 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
70 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
71 const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7);
72
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 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
77 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
78 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
79 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
80 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
81 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
82
83 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
84 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
85 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
86 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
87 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
88 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
89 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
90 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
91
92 k -= 8 * sizeof(int8_t);
93 }
94 if XNN_UNLIKELY(k != 0) {
95 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
96 const int16x8_t vxa0 = vmovl_s8(va0);
97
98 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
99
100 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
101
102 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
103 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
104
105 if (k >= 2 * sizeof(int8_t)) {
106 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
107 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
108
109 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
110 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
111
112 if (k > 2 * sizeof(int8_t)) {
113 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
114 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
115
116 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
117 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
118
119 if (k >= 4 * sizeof(int8_t)) {
120 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
121 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
122
123 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
124 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
125
126 if (k > 4 * sizeof(int8_t)) {
127 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
128 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
129
130 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
131 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
132
133 if (k >= 6 * sizeof(int8_t)) {
134 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
135 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
136
137 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
138 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
139
140 if (k > 6 * sizeof(int8_t)) {
141 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
142 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
143
144 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
145 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
146 }
147 }
148 }
149 }
150 }
151 }
152 }
153
154 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
155 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
156
157 const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale);
158 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale0);
159 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale0);
160
161 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
162 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
163
164 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
165 #if XNN_ARCH_ARM64
166 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
167 #else
168 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
169 #endif
170 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
171 #if XNN_ARCH_ARM64
172 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
173 #else
174 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
175 #endif
176
177 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
178 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
179 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
180
181 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
182 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
183 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
184
185 if XNN_LIKELY(nc >= 8) {
186 vst1q_f32(&c0[0], vout0x0123);
187 vst1q_f32(&c0[4], vout0x4567);
188
189 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
190
191 c0 = (float*) ((uintptr_t) c0 + cn_stride);
192
193 nc -= 8;
194 } else {
195 if (nc & 4) {
196 vst1q_f32(c0, vout0x0123); c0 += 4;
197 vout0x0123 = vout0x4567;
198 }
199 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
200 if (nc & 2) {
201 vst1_f32(c0, vout0x01); c0 += 2;
202 vout0x01 = vget_high_f32(vout0x0123);
203 }
204 if (nc & 1) {
205 vst1_lane_f32(c0, vout0x01, 0);
206 }
207 nc = 0;
208 }
209 } while (nc != 0);
210 }