Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x16c4-minmax-neondot.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c4-neondot.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/igemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f32_qc8w_igemm_minmax_ukernel_1x16c4__neondot(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const int8_t** restrict a,
24 const void* restrict w,
25 float* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const int8_t* zero,
30 const int8_t* zero_data,
31 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
32 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
33 {
34 assert(mr != 0);
35 assert(mr <= 1);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(ks != 0);
39 assert(ks % (1 * sizeof(void*)) == 0);
40 assert(a_offset % sizeof(int8_t) == 0);
41 assert(a != NULL);
42 assert(w != NULL);
43 assert(c != NULL);
44
45 kc = round_up_po2(kc, 4 * sizeof(int8_t));
46 float* c0 = c;
47
48 do {
49 const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
50 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
51 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
52 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
53 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
54 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
55 int32x4_t vacc0x89AB = vmulq_s32(vksum89AB, vinput_zero_point);
56 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
57 int32x4_t vacc0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point);
58
59 size_t p = ks;
60 do {
61 const int8_t* restrict a0 = a[0];
62 if XNN_UNPREDICTABLE(a0 != zero) {
63 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
64 } else {
65 a0 = zero_data;
66 }
67 a += 1;
68
69 // Inner accumulation loop along the 16 columns.
70 size_t k = kc;
71 // 2x partial unrolled loop to load 8 bytes at a time.
72 while (k >= 8 * sizeof(int8_t)) {
73 // Load a 1x8 block of activations.
74 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
75
76 // Load a 8x16 block of weights.
77 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
78 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
79 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
80 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
81 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
82 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
83 const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
84 const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
85
86 // Multiply-accumulate: 1x8 * 8x16 --> 1x16.
87 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
88 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
89 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
90 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
91 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
92 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
93 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1);
94 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
95
96 k -= 8 * sizeof(int8_t);
97 }
98 // Handle up to 4 final positions of `k`
99 if XNN_UNLIKELY(k != 0) {
100 // Load a 1x4 block of activations.
101 const int8x8_t va0x01234567 = vld1_s8(a0);
102
103 // Load a 4x16 block of weights.
104 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
105 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
106 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
107 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
108
109 // Multiply-accumulate: 1x4 * 4x16 --> 1x16.
110 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
111 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
112 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
113 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
114 }
115 p -= 1 * sizeof(void*);
116 } while (p != 0);
117
118 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
119 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
120 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
121 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
122 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
123 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
124 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
125 vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale);
126 vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale);
127
128 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
129 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
130 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
131 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
132
133 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
134 #if XNN_ARCH_ARM64
135 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
136 #else
137 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
138 #endif
139 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
140 #if XNN_ARCH_ARM64
141 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
142 #else
143 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
144 #endif
145 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
146 #if XNN_ARCH_ARM64
147 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
148 #else
149 vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
150 #endif
151 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
152 #if XNN_ARCH_ARM64
153 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
154 #else
155 vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
156 #endif
157
158 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
159 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
160 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
161 vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min);
162 vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min);
163
164 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
165 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
166 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
167 vout0x89AB = vminq_f32(vout0x89AB, voutput_max);
168 vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max);
169
170 if XNN_LIKELY(nc >= 16) {
171 vst1q_f32(c0, vout0x0123);
172 vst1q_f32(c0 + 4, vout0x4567);
173 vst1q_f32(c0 + 8, vout0x89AB);
174 vst1q_f32(c0 + 12, vout0xCDEF);
175
176 a = (const int8_t**restrict) ((uintptr_t) a - ks);
177
178 c0 = (float*) ((uintptr_t) c0 + cn_stride);
179
180 nc -= 16;
181 } else {
182 if (nc & 8) {
183 vst1q_f32(c0, vout0x0123); c0 += 4;
184 vout0x0123 = vout0x89AB;
185 vst1q_f32(c0, vout0x4567); c0 += 4;
186 vout0x4567 = vout0xCDEF;
187 }
188 if (nc & 4) {
189 vst1q_f32(c0, vout0x0123); c0 += 4;
190 vout0x0123 = vout0x4567;
191 }
192 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
193 if (nc & 2) {
194 vst1_f32(c0, vout0x01); c0 += 2;
195 vout0x01 = vget_high_f32(vout0x0123);
196 }
197 if (nc & 1) {
198 vst1_lane_f32(c0, vout0x01, 0);
199 }
200 nc = 0;
201 }
202 } while (nc != 0);
203 }