Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8c2s4-minmax-neon-mlal.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/c2-neon-mull-shuffle.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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/gemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x8c2s4__neon_mlal(
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 kc = round_up_po2(kc, 8 * sizeof(int8_t));
44 do {
45 const int32x4_t vizp0 = vld1q_dup_s32(&quantization_params[0].zero_point);
46 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
47 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vizp0);
48 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
49 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vizp0);
50
51 size_t k = kc;
52 while (k >= 16 * sizeof(int8_t)) {
53 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
54 int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
55
56 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
57 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
58 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
59 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
60 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
61 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
62 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
63 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
64
65 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0);
66 const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
67 vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0x1);
68 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
69 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0);
70 const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
71 vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0x1);
72 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
73 va0x0 = vext_s8(va0x0, va0x0, 2);
74 va0x1 = vext_s8(va0x1, va0x1, 2);
75 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0);
76 const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
77 vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0x1);
78 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
79 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0);
80 const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
81 vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0x1);
82 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
83 va0x0 = vext_s8(va0x0, va0x0, 2);
84 va0x1 = vext_s8(va0x1, va0x1, 2);
85 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0);
86 const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const int8_t*) w + 8;
87 vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0x1);
88 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
89 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0);
90 const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const int8_t*) w + 8;
91 vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0x1);
92 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
93 va0x0 = vext_s8(va0x0, va0x0, 2);
94 va0x1 = vext_s8(va0x1, va0x1, 2);
95 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0);
96 const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const int8_t*) w + 8;
97 vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0x1);
98 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
99 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0);
100 const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const int8_t*) w + 8;
101 vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0x1);
102 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
103
104 k -= 16 * sizeof(int8_t);
105 }
106 if (k != 0) {
107 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
108
109 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
110 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
111 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
112 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
113 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
114 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
115 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
116 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
117
118 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0);
119 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
120 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0);
121 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
122 va0x0 = vext_s8(va0x0, va0x0, 2);
123 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0);
124 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
125 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0);
126 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
127 va0x0 = vext_s8(va0x0, va0x0, 2);
128 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0);
129 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
130 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0);
131 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
132 va0x0 = vext_s8(va0x0, va0x0, 2);
133 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0);
134 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
135 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0);
136 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
137
138 }
139
140 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
141 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
142
143 const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale);
144 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale0);
145 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale0);
146
147 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
148 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
149
150 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
151 #if XNN_ARCH_ARM64
152 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
153 #else
154 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
155 #endif
156 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
157 #if XNN_ARCH_ARM64
158 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
159 #else
160 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
161 #endif
162
163 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
164 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
165 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
166
167 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
168 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
169 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
170
171 if XNN_LIKELY(nc >= 8) {
172 vst1q_f32(c0, vout0x0123);
173 vst1q_f32(c0 + 0, vout0x0123);
174 vst1q_f32(c0 + 4, vout0x4567);
175
176 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
177
178 c0 = (float*) ((uintptr_t) c0 + cn_stride);
179
180 nc -= 8;
181 } else {
182 if (nc & 4) {
183 vst1q_f32(c0, vout0x0123); c0 += 4;
184 vout0x0123 = vout0x4567;
185 }
186 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
187 if (nc & 2) {
188 vst1_f32(c0, vout0x01); c0 += 2;
189 vout0x01 = vget_high_f32(vout0x0123);
190 }
191 if (nc & 1) {
192 vst1_lane_f32(c0, vout0x01, 0);
193 }
194 nc = 0;
195 }
196 } while (nc != 0);
197 }