Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8c8-minmax-aarch64-neondot-ld128.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/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_gemm_minmax_ukernel_1x8c8__aarch64_neondot_ld128(
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 kc = round_up_po2(kc, 8 * sizeof(int8_t));
41 const int8_t* a0 = a;
42 float* c0 = c;
43
44 do {
45 const int32x4_t vinput_zero_point0 = vld1q_dup_s32(&quantization_params[0].zero_point);
46 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
47 const int32x4_t vinit0x0123 = vmulq_s32(vksum0123, vinput_zero_point0);
48 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
49 const int32x4_t vinit0x4567 = vmulq_s32(vksum4567, vinput_zero_point0);
50 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
51 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
52 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
53 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
54
55 size_t k = kc;
56 for (; k >= 16 * sizeof(int8_t); k -= 16 * sizeof(int8_t)) {
57 const uint64x2x2_t va0c0123456789ABCDEF = vld2q_dup_u64((const void*) a0); a0 += 16;
58
59 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
60 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
61 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
62 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
63
64 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
65 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
66 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
67 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
68
69 const int8x16_t vb01c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
70 const int8x16_t vb23c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
71 const int8x16_t vb45c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
72 const int8x16_t vb67c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
73
74 vacc0x01 = vdotq_s32(vacc0x01, vb01c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
75 vacc0x23 = vdotq_s32(vacc0x23, vb23c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
76 vacc0x45 = vdotq_s32(vacc0x45, vb45c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
77 vacc0x67 = vdotq_s32(vacc0x67, vb67c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
78 }
79 if XNN_LIKELY(k != 0) {
80 assert(k == 8 * sizeof(int8_t));
81
82 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
83
84 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
85 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
86 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
87 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
88
89 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
90 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
91 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
92 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
93 }
94
95 #if XNN_ARCH_ARM64
96 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
97 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
98 #else
99 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)));
100 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)));
101 #endif
102
103 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
104 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
105
106 const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale);
107 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale0);
108 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale0);
109
110 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
111 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
112
113 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
114 #if XNN_ARCH_ARM64
115 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
116 #else
117 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
118 #endif
119 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
120 #if XNN_ARCH_ARM64
121 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
122 #else
123 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
124 #endif
125
126 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
127 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
128 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
129
130 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
131 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
132 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
133
134 if XNN_LIKELY(nc >= 8) {
135 vst1q_f32(c0, vout0x0123);
136 vst1q_f32(c0 + 4, vout0x4567);
137
138 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
139
140 c0 = (float*) ((uintptr_t) c0 + cn_stride);
141
142 nc -= 8;
143 } else {
144 if (nc & 4) {
145 vst1q_f32(c0, vout0x0123); c0 += 4;
146 vout0x0123 = vout0x4567;
147 }
148 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
149 if (nc & 2) {
150 vst1_f32(c0, vout0x01); c0 += 2;
151 vout0x01 = vget_high_f32(vout0x0123);
152 }
153 if (nc & 1) {
154 vst1_lane_f32(c0, vout0x01, 0);
155 }
156 nc = 0;
157 }
158 } while (nc != 0);
159 }