Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x8c8-minmax-aarch64-neondot-ld128.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_1x8c8__aarch64_neondot_ld128(
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 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
56 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
57 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
58 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
59
60 size_t p = ks;
61 do {
62 const int8_t* restrict a0 = a[0];
63 if XNN_UNPREDICTABLE(a0 != zero) {
64 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
65 } else {
66 a0 = zero_data;
67 }
68 a += 1;
69
70 size_t k = kc;
71 for (; k >= 16 * sizeof(int8_t); k -= 16 * sizeof(int8_t)) {
72 const uint64x2x2_t va0c0123456789ABCDEF = vld2q_dup_u64((const void*) a0); a0 += 16;
73
74 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
75 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
76 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
77 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
78
79 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
80 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
81 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
82 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
83
84 const int8x16_t vb01c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
85 const int8x16_t vb23c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
86 const int8x16_t vb45c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
87 const int8x16_t vb67c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
88
89 vacc0x01 = vdotq_s32(vacc0x01, vb01c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
90 vacc0x23 = vdotq_s32(vacc0x23, vb23c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
91 vacc0x45 = vdotq_s32(vacc0x45, vb45c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
92 vacc0x67 = vdotq_s32(vacc0x67, vb67c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
93 }
94 if XNN_LIKELY(k != 0) {
95 assert(k == 8 * sizeof(int8_t));
96
97 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
98
99 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
100 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
101 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
102 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
103
104 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
105 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
106 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
107 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
108 }
109 p -= 1 * sizeof(void*);
110 } while (p != 0);
111
112 #if XNN_ARCH_ARM64
113 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
114 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
115 #else
116 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)));
117 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)));
118 #endif
119 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
120 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
121
122 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
123 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
124
125 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
126 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
127
128 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
129 #if XNN_ARCH_ARM64
130 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
131 #else
132 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
133 #endif
134 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
135 #if XNN_ARCH_ARM64
136 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
137 #else
138 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
139 #endif
140
141 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
142 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
143 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
144
145 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
146 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
147 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
148
149 if XNN_LIKELY(nc >= 8) {
150 vst1q_f32(c0, vout0x0123);
151 vst1q_f32(c0 + 4, vout0x4567);
152
153 a = (const int8_t**restrict) ((uintptr_t) a - ks);
154
155 c0 = (float*) ((uintptr_t) c0 + cn_stride);
156
157 nc -= 8;
158 } else {
159 if (nc & 4) {
160 vst1q_f32(c0, vout0x0123); c0 += 4;
161 vout0x0123 = vout0x4567;
162 }
163 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
164 if (nc & 2) {
165 vst1_f32(c0, vout0x01); c0 += 2;
166 vout0x01 = vget_high_f32(vout0x0123);
167 }
168 if (nc & 1) {
169 vst1_lane_f32(c0, vout0x01, 0);
170 }
171 nc = 0;
172 }
173 } while (nc != 0);
174 }