Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x8c8-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_1x8c8__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 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 do {
72 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
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, va0c01234567);
80 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
81 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
82 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
83
84 k -= 8 * sizeof(int8_t);
85 } while (k != 0);
86 p -= 1 * sizeof(void*);
87 } while (p != 0);
88
89 #if XNN_ARCH_ARM64
90 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
91 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
92 #else
93 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)));
94 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)));
95 #endif
96 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
97 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
98
99 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
100 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
101
102 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
103 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
104
105 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
106 #if XNN_ARCH_ARM64
107 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
108 #else
109 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
110 #endif
111 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
112 #if XNN_ARCH_ARM64
113 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
114 #else
115 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
116 #endif
117
118 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
119 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
120 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
121
122 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
123 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
124 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
125
126 if XNN_LIKELY(nc >= 8) {
127 vst1q_f32(c0, vout0x0123);
128 vst1q_f32(c0 + 4, vout0x4567);
129
130 a = (const int8_t**restrict) ((uintptr_t) a - ks);
131
132 c0 = (float*) ((uintptr_t) c0 + cn_stride);
133
134 nc -= 8;
135 } else {
136 if (nc & 4) {
137 vst1q_f32(c0, vout0x0123); c0 += 4;
138 vout0x0123 = vout0x4567;
139 }
140 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
141 if (nc & 2) {
142 vst1_f32(c0, vout0x01); c0 += 2;
143 vout0x01 = vget_high_f32(vout0x0123);
144 }
145 if (nc & 1) {
146 vst1_lane_f32(c0, vout0x01, 0);
147 }
148 nc = 0;
149 }
150 } while (nc != 0);
151 }