Debian Codegraph @

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

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c8-neondot.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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_igemm_minmax_ukernel_1x16c8__neondot_ld64(
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, 8 * sizeof(int8_t));
46 float* c0 = c;
47
48 const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
49 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
50 do {
51 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
52 const int32x4_t vinit0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
53 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
54 const int32x4_t vinit0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
55 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
56 const int32x4_t vinit0x89AB = vmulq_s32(vksum89AB, vinput_zero_point);
57 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
58 const int32x4_t vinit0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point);
59 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
60 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
61 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
62 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
63 int32x4_t vacc0x89 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x89AB))));
64 int32x4_t vacc0xAB = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x89AB))));
65 int32x4_t vacc0xCD = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
66 int32x4_t vacc0xEF = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
67
68 size_t p = ks;
69 do {
70 const int8_t* restrict a0 = a[0];
71 if XNN_UNPREDICTABLE(a0 != zero) {
72 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
73 } else {
74 a0 = zero_data;
75 }
76 a += 1;
77
78 size_t k = kc;
79 do {
80 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
81
82 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
83 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
84 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
85 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
86 const int8x16_t vb89c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
87 const int8x16_t vbABc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
88 const int8x16_t vbCDc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
89 const int8x16_t vbEFc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
90
91 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
92 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
93 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
94 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
95 vacc0x89 = vdotq_s32(vacc0x89, vb89c01234567, va0c01234567);
96 vacc0xAB = vdotq_s32(vacc0xAB, vbABc01234567, va0c01234567);
97 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc01234567, va0c01234567);
98 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc01234567, va0c01234567);
99
100 k -= 8 * sizeof(int8_t);
101 } while (k != 0);
102 p -= 1 * sizeof(void*);
103 } while (p != 0);
104
105 #if XNN_ARCH_ARM64
106 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
107 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
108 int32x4_t vacc0x89AB = vpaddq_s32(vacc0x89, vacc0xAB);
109 int32x4_t vacc0xCDEF = vpaddq_s32(vacc0xCD, vacc0xEF);
110 #else
111 int32x4_t vacc0x0123 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)), vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)));
112 int32x4_t vacc0x4567 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)), vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)));
113 int32x4_t vacc0x89AB = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x89), vget_high_s32(vacc0x89)), vpadd_s32(vget_low_s32(vacc0xAB), vget_high_s32(vacc0xAB)));
114 int32x4_t vacc0xCDEF = vcombine_s32(vpadd_s32(vget_low_s32(vacc0xCD), vget_high_s32(vacc0xCD)), vpadd_s32(vget_low_s32(vacc0xEF), vget_high_s32(vacc0xEF)));
115 #endif
116 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
117 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
118 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
119 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
120
121 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
122 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
123 vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale);
124 vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale);
125
126 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
127 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
128 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
129 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
130
131 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
132 #if XNN_ARCH_ARM64
133 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
134 #else
135 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
136 #endif
137 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
138 #if XNN_ARCH_ARM64
139 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
140 #else
141 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
142 #endif
143 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
144 #if XNN_ARCH_ARM64
145 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
146 #else
147 vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
148 #endif
149 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
150 #if XNN_ARCH_ARM64
151 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
152 #else
153 vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
154 #endif
155
156 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
157 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
158 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
159 vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min);
160 vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min);
161
162 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
163 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
164 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
165 vout0x89AB = vminq_f32(vout0x89AB, voutput_max);
166 vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max);
167
168 if XNN_LIKELY(nc >= 16) {
169 vst1q_f32(c0, vout0x0123);
170 vst1q_f32(c0 + 4, vout0x4567);
171 vst1q_f32(c0 + 8, vout0x89AB);
172 vst1q_f32(c0 + 12, vout0xCDEF);
173
174 a = (const int8_t**restrict) ((uintptr_t) a - ks);
175
176 c0 = (float*) ((uintptr_t) c0 + cn_stride);
177
178 nc -= 16;
179 } else {
180 if (nc & 8) {
181 vst1q_f32(c0, vout0x0123); c0 += 4;
182 vout0x0123 = vout0x89AB;
183 vst1q_f32(c0, vout0x4567); c0 += 4;
184 vout0x4567 = vout0xCDEF;
185 }
186 if (nc & 4) {
187 vst1q_f32(c0, vout0x0123); c0 += 4;
188 vout0x0123 = vout0x4567;
189 }
190 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
191 if (nc & 2) {
192 vst1_f32(c0, vout0x01); c0 += 2;
193 vout0x01 = vget_high_f32(vout0x0123);
194 }
195 if (nc & 1) {
196 vst1_lane_f32(c0, vout0x01, 0);
197 }
198 nc = 0;
199 }
200 } while (nc != 0);
201 }