Debian Codegraph @

src/qd8-f16-qc8w-igemm/gen/qd8-f16-qc8w-igemm-1x16c4-minmax-neondotfp16arith.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c4-neondot.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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/igemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f16_qc8w_igemm_minmax_ukernel_1x16c4__neondotfp16arith(
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 xnn_float16* 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_f16_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, 4 * sizeof(int8_t));
46 uint16_t* c0 = (uint16_t*) c;
47
48 do {
49 const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
50 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
51 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
52 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
53 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
54 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
55 int32x4_t vacc0x89AB = vmulq_s32(vksum89AB, vinput_zero_point);
56 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
57 int32x4_t vacc0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point);
58
59 size_t p = ks;
60 do {
61 const int8_t* restrict a0 = a[0];
62 if XNN_UNPREDICTABLE(a0 != zero) {
63 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
64 } else {
65 a0 = zero_data;
66 }
67 a += 1;
68
69 // Inner accumulation loop along the 16 columns.
70 size_t k = kc;
71 // 2x partial unrolled loop to load 8 bytes at a time.
72 while (k >= 8 * sizeof(int8_t)) {
73 // Load a 1x8 block of activations.
74 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
75
76 // Load a 8x16 block of weights.
77 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
78 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
79 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
80 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
81 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
82 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
83 const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
84 const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
85
86 // Multiply-accumulate: 1x8 * 8x16 --> 1x16.
87 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
88 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
89 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
90 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
91 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
92 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
93 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1);
94 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
95
96 k -= 8 * sizeof(int8_t);
97 }
98 // Handle up to 4 final positions of `k`
99 if XNN_UNLIKELY(k != 0) {
100 // Load a 1x4 block of activations.
101 const int8x8_t va0x01234567 = vld1_s8(a0);
102
103 // Load a 4x16 block of weights.
104 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
105 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
106 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
107 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
108
109 // Multiply-accumulate: 1x4 * 4x16 --> 1x16.
110 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
111 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
112 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
113 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
114 }
115 p -= 1 * sizeof(void*);
116 } while (p != 0);
117
118 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
119 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
120 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
121 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
122 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
123 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
124 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
125 vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale);
126 vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale);
127
128 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
129 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
130 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
131 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
132
133 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
134 #if XNN_ARCH_ARM64
135 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
136 #else
137 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
138 #endif
139 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
140 #if XNN_ARCH_ARM64
141 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
142 #else
143 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
144 #endif
145 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
146 #if XNN_ARCH_ARM64
147 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
148 #else
149 vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
150 #endif
151 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
152 #if XNN_ARCH_ARM64
153 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
154 #else
155 vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
156 #endif
157
158 float16x8_t vfp16out0x01234567 = vcombine_f16(vcvt_f16_f32(vout0x0123), vcvt_f16_f32(vout0x4567));
159 float16x8_t vfp16out0x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout0x89AB), vcvt_f16_f32(vout0xCDEF));
160
161 const float16x8_t voutput_min = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
162 vfp16out0x01234567 = vmaxq_f16(vfp16out0x01234567, voutput_min);
163 vfp16out0x89ABCDEF = vmaxq_f16(vfp16out0x89ABCDEF, voutput_min);
164 const float16x8_t voutput_max = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
165 vfp16out0x01234567 = vminq_f16(vfp16out0x01234567, voutput_max);
166 vfp16out0x89ABCDEF = vminq_f16(vfp16out0x89ABCDEF, voutput_max);
167 if XNN_LIKELY(nc >= 16) {
168 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567));
169 vst1q_u16(c0 + 8, vreinterpretq_u16_f16(vfp16out0x89ABCDEF));
170
171 a = (const int8_t**restrict) ((uintptr_t) a - ks);
172
173 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
174
175 nc -= 16;
176 } else {
177 if (nc & 8) {
178 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); c0 += 8;
179 vfp16out0x01234567 = vfp16out0x89ABCDEF;
180 }
181 float16x4_t vfp16out0x0123 = vget_low_f16(vfp16out0x01234567);
182 if (nc & 4) {
183 vst1_u16(c0, vreinterpret_u16_f16(vfp16out0x0123)); c0 += 4;
184 vfp16out0x0123 = vget_high_f16(vfp16out0x01234567);
185 }
186 if (nc & 2) {
187 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vfp16out0x0123), 0); c0 += 2;
188 vfp16out0x0123 = vext_f16(vfp16out0x0123, vfp16out0x0123, 2);
189 }
190 if (nc & 1) {
191 vst1_lane_u16(c0, vreinterpret_u16_f16(vfp16out0x0123), 0);
192 }
193 nc = 0;
194 }
195 } while (nc != 0);
196 }