Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-1x16c8-minmax-fp32-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/intrinsics-polyfill.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x16c8__neondot_ld64(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 size_t ks,
24 const int8_t** restrict a,
25 const void* restrict w,
26 int8_t* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 size_t a_offset,
30 const int8_t* zero,
31 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
32 {
33 assert(mr != 0);
34 assert(mr <= 1);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (1 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(int8_t) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 kc = round_up_po2(kc, 8 * sizeof(int8_t));
45 int8_t* c0 = c;
46
47 do {
48 const int32x4_t vinit0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
49 const int32x4_t vinit0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
50 const int32x4_t vinit0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
51 const int32x4_t vinit0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
52 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
53 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
54 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
55 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
56 int32x4_t vacc0x89 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x89AB))));
57 int32x4_t vacc0xAB = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x89AB))));
58 int32x4_t vacc0xCD = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
59 int32x4_t vacc0xEF = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
60
61 size_t p = ks;
62 do {
63 const int8_t* restrict a0 = a[0];
64 if XNN_UNPREDICTABLE(a0 != zero) {
65 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
66 }
67 a += 1;
68
69 size_t k = kc;
70 do {
71 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
72
73 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
74 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
75 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
76 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
77 const int8x16_t vb89c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
78 const int8x16_t vbABc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
79 const int8x16_t vbCDc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
80 const int8x16_t vbEFc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
81
82 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
83 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
84 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
85 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
86 vacc0x89 = vdotq_s32(vacc0x89, vb89c01234567, va0c01234567);
87 vacc0xAB = vdotq_s32(vacc0xAB, vbABc01234567, va0c01234567);
88 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc01234567, va0c01234567);
89 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc01234567, va0c01234567);
90
91 k -= 8 * sizeof(int8_t);
92 } while (k != 0);
93 p -= 1 * sizeof(void*);
94 } while (p != 0);
95
96 #if XNN_ARCH_ARM64
97 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
98 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
99 int32x4_t vacc0x89AB = vpaddq_s32(vacc0x89, vacc0xAB);
100 int32x4_t vacc0xCDEF = vpaddq_s32(vacc0xCD, vacc0xEF);
101 #else
102 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)));
103 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)));
104 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)));
105 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)));
106 #endif
107
108 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
109 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
110 float32x4_t vfpacc0x89AB = vcvtq_f32_s32(vacc0x89AB);
111 float32x4_t vfpacc0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
112
113 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4;
114 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
115 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4;
116 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
117 const float32x4_t vscale89AB = vld1q_f32((const float*) w); w = (const float*) w + 4;
118 vfpacc0x89AB = vmulq_f32(vfpacc0x89AB, vscale89AB);
119 const float32x4_t vscaleCDEF = vld1q_f32((const float*) w); w = (const float*) w + 4;
120 vfpacc0xCDEF = vmulq_f32(vfpacc0xCDEF, vscaleCDEF);
121
122 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
123 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
124 vacc0x89AB = vcvtnq_s32_f32(vfpacc0x89AB);
125 vacc0xCDEF = vcvtnq_s32_f32(vfpacc0xCDEF);
126
127 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
128 #if XNN_ARCH_ARM64
129 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
130 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point);
131
132 int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
133 #else
134 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
135 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point);
136
137 int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
138 #endif
139 const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min);
140 const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max);
141
142 vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
143
144 vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
145
146 if (nc >= 16) {
147 // Main case where there the 16 columns fit in the destination.
148 vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
149
150 // Advance to the next 16 columns.
151 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
152
153 a = (const int8_t**restrict) ((uintptr_t) a - ks);
154
155 nc -= 16;
156 } else {
157 // Final case where not all of the 16 columns fit in the destination.
158 int8x8_t vout0x01234567 = vget_low_s8(vout0x0123456789ABCDEF);
159 if (nc & 8) {
160 vst1_s8(c0, vout0x01234567); c0 += 8;
161 vout0x01234567 = vget_high_s8(vout0x0123456789ABCDEF);
162 }
163 if (nc & 4) {
164 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
165 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
166 }
167 if (nc & 2) {
168 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
169 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
170 }
171 if (nc & 1) {
172 vst1_lane_s8(c0, vout0x01234567, 0);
173 }
174
175 nc = 0;
176 }
177 } while (nc != 0);
178 }