Debian Codegraph @

src/qd8-f16-qc8w-gemm/gen/qd8-f16-qc8w-gemm-1x8c2s4-minmax-neonfp16arith.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/c2-neon-mull-shuffle.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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_f16_qc8w_gemm_minmax_ukernel_1x8c2s4__neonfp16arith(
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 xnn_float16* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_f16_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 const int8_t* a0 = a;
41 uint16_t* c0 = (uint16_t*) c;
42
43 kc = round_up_po2(kc, 8 * sizeof(int8_t));
44 do {
45 const int32x4_t vizp0 = vld1q_dup_s32(&quantization_params[0].zero_point);
46 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
47 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vizp0);
48 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
49 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vizp0);
50
51 size_t k = kc;
52 while (k >= 16 * sizeof(int8_t)) {
53 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
54 int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
55
56 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
57 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
58 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
59 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
60 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
61 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
62 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
63 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
64
65 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0);
66 const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
67 vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0x1);
68 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
69 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0);
70 const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
71 vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0x1);
72 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
73 va0x0 = vext_s8(va0x0, va0x0, 2);
74 va0x1 = vext_s8(va0x1, va0x1, 2);
75 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0);
76 const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
77 vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0x1);
78 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
79 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0);
80 const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
81 vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0x1);
82 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
83 va0x0 = vext_s8(va0x0, va0x0, 2);
84 va0x1 = vext_s8(va0x1, va0x1, 2);
85 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0);
86 const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const int8_t*) w + 8;
87 vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0x1);
88 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
89 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0);
90 const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const int8_t*) w + 8;
91 vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0x1);
92 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
93 va0x0 = vext_s8(va0x0, va0x0, 2);
94 va0x1 = vext_s8(va0x1, va0x1, 2);
95 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0);
96 const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const int8_t*) w + 8;
97 vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0x1);
98 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
99 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0);
100 const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const int8_t*) w + 8;
101 vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0x1);
102 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
103
104 k -= 16 * sizeof(int8_t);
105 }
106 if (k != 0) {
107 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
108
109 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
110 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
111 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
112 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
113 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
114 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
115 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
116 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
117
118 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0);
119 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
120 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0);
121 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
122 va0x0 = vext_s8(va0x0, va0x0, 2);
123 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0);
124 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
125 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0);
126 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
127 va0x0 = vext_s8(va0x0, va0x0, 2);
128 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0);
129 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
130 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0);
131 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
132 va0x0 = vext_s8(va0x0, va0x0, 2);
133 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0);
134 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
135 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0);
136 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
137
138 }
139
140 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
141 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
142
143 const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale);
144 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale0);
145 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale0);
146
147 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
148 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
149
150 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
151 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
152 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
153 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
154
155 float16x8_t vfp16out0x01234567 = vcombine_f16(vcvt_f16_f32(vout0x0123), vcvt_f16_f32(vout0x4567));
156
157 #if XNN_ARCH_ARM64
158 const uint16x8x2_t voutput_minmax = vld2q_dup_u16((const uint16_t*) &params->scalar.min);
159 const float16x8_t voutput_min = vreinterpretq_f16_u16(voutput_minmax.val[0]);
160 const float16x8_t voutput_max = vreinterpretq_f16_u16(voutput_minmax.val[1]);
161 #else
162 const float16x8_t voutput_min = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
163 const float16x8_t voutput_max = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
164 #endif
165 vfp16out0x01234567 = vmaxq_f16(vfp16out0x01234567, voutput_min);
166 vfp16out0x01234567 = vminq_f16(vfp16out0x01234567, voutput_max);
167 if XNN_LIKELY(nc >= 8) {
168 vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567));
169
170 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
171
172 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
173
174 nc -= 8;
175 } else {
176 float16x4_t vfp16out0x0123 = vget_low_f16(vfp16out0x01234567);
177 if (nc & 4) {
178 vst1_u16(c0, vreinterpret_u16_f16(vfp16out0x0123)); c0 += 4;
179 vfp16out0x0123 = vget_high_f16(vfp16out0x01234567);
180 }
181 if (nc & 2) {
182 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vfp16out0x0123), 0); c0 += 2;
183 vfp16out0x0123 = vext_f16(vfp16out0x0123, vfp16out0x0123, 2);
184 }
185 if (nc & 1) {
186 vst1_lane_u16(c0, vreinterpret_u16_f16(vfp16out0x0123), 0);
187 }
188 nc = 0;
189 }
190 } while (nc != 0);
191 }