Debian Codegraph @

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