Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-1x8-minmax-rndnu-neon-mlal-lane.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/neon-mlal-lane.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
11 #include <assert.h>
12
13 #include <arm_neon.h>
14
15 #include "xnnpack/common.h"
16 #include "xnnpack/igemm.h"
17
18
19 void xnn_qu8_igemm_minmax_rndnu_ukernel_1x8__neon_mlal_lane(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 size_t ks,
24 const uint8_t** restrict a,
25 const void* restrict w,
26 uint8_t* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 size_t a_offset,
30 const uint8_t* zero,
31 const union xnn_qu8_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(uint8_t) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 uint8_t* c0 = c;
45
46 const uint8x8_t vb_zero_point = vld1_dup_u8(&params->rndnu_neon.kernel_zero_point[0]);
47 do {
48 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
49 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
50
51 size_t p = ks;
52 do {
53 const uint8_t* restrict a0 = a[0];
54 if XNN_UNPREDICTABLE(a0 != zero) {
55 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
56 }
57 a += 1;
58
59 size_t k = kc;
60 while (k >= 8 * sizeof(uint8_t)) {
61 const uint8x8_t va0 = vld1_u8(a0); a0 += 8;
62 const int16x8_t vxa0 = vreinterpretq_s16_u16(vmovl_u8(va0));
63
64 const uint8x8_t vb01234567c0 = vld1_u8(w); w = (const uint8_t*) w + 8;
65 const int16x8_t vxb01234567c0 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c0, vb_zero_point));
66
67 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
68 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
69 const uint8x8_t vb01234567c1 = vld1_u8(w); w = (const uint8_t*) w + 8;
70 const int16x8_t vxb01234567c1 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c1, vb_zero_point));
71
72 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
73 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
74 const uint8x8_t vb01234567c2 = vld1_u8(w); w = (const uint8_t*) w + 8;
75 const int16x8_t vxb01234567c2 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c2, vb_zero_point));
76
77 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
78 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
79 const uint8x8_t vb01234567c3 = vld1_u8(w); w = (const uint8_t*) w + 8;
80 const int16x8_t vxb01234567c3 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c3, vb_zero_point));
81
82 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
83 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
84
85
86 const uint8x8_t vb01234567c4 = vld1_u8(w); w = (const uint8_t*) w + 8;
87 const int16x8_t vxb01234567c4 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c4, vb_zero_point));
88
89 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
90 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
91 const uint8x8_t vb01234567c5 = vld1_u8(w); w = (const uint8_t*) w + 8;
92 const int16x8_t vxb01234567c5 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c5, vb_zero_point));
93
94 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
95 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
96 const uint8x8_t vb01234567c6 = vld1_u8(w); w = (const uint8_t*) w + 8;
97 const int16x8_t vxb01234567c6 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c6, vb_zero_point));
98
99 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
100 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
101 const uint8x8_t vb01234567c7 = vld1_u8(w); w = (const uint8_t*) w + 8;
102 const int16x8_t vxb01234567c7 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c7, vb_zero_point));
103
104 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
105 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
106
107 k -= 8 * sizeof(uint8_t);
108 }
109 if XNN_UNLIKELY(k != 0) {
110 const uint8x8_t va0 = vld1_u8(a0); a0 = (const uint8_t*) ((uintptr_t) a0 + k);
111 const int16x8_t vxa0 = vreinterpretq_s16_u16(vmovl_u8(va0));
112
113 const uint8x8_t vb01234567c0 = vld1_u8(w); w = (const uint8_t*) w + 8;
114 const int16x8_t vxb01234567c0 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c0, vb_zero_point));
115
116 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
117 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
118
119 if (k >= 2 * sizeof(uint8_t)) {
120 const uint8x8_t vb01234567c1 = vld1_u8(w); w = (const uint8_t*) w + 8;
121 const int16x8_t vxb01234567c1 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c1, vb_zero_point));
122
123 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
124 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
125
126 if (k > 2 * sizeof(uint8_t)) {
127 const uint8x8_t vb01234567c2 = vld1_u8(w); w = (const uint8_t*) w + 8;
128 const int16x8_t vxb01234567c2 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c2, vb_zero_point));
129
130 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
131 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
132
133 if (k >= 4 * sizeof(uint8_t)) {
134 const uint8x8_t vb01234567c3 = vld1_u8(w); w = (const uint8_t*) w + 8;
135 const int16x8_t vxb01234567c3 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c3, vb_zero_point));
136
137 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
138 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
139
140 if (k > 4 * sizeof(uint8_t)) {
141 const uint8x8_t vb01234567c4 = vld1_u8(w); w = (const uint8_t*) w + 8;
142 const int16x8_t vxb01234567c4 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c4, vb_zero_point));
143
144 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
145 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
146
147 if (k >= 6 * sizeof(uint8_t)) {
148 const uint8x8_t vb01234567c5 = vld1_u8(w); w = (const uint8_t*) w + 8;
149 const int16x8_t vxb01234567c5 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c5, vb_zero_point));
150
151 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
152 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
153
154 if (k > 6 * sizeof(uint8_t)) {
155 const uint8x8_t vb01234567c6 = vld1_u8(w); w = (const uint8_t*) w + 8;
156 const int16x8_t vxb01234567c6 = vreinterpretq_s16_u16(vsubl_u8(vb01234567c6, vb_zero_point));
157
158 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
159 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
160 }
161 }
162 }
163 }
164 }
165 }
166 }
167 p -= 1 * sizeof(void*);
168 } while (p != 0);
169
170 // Post-accumulation work
171 const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
172 const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
173 const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
174
175 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
176 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
177
178 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
179 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
180
181 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
182 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
183
184 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
185 #if XNN_ARCH_ARM64
186 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
187
188 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
189
190 uint8x8_t vout0x01234567 = vqmovun_s16(vacc0x01234567);
191 #else
192 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
193
194 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
195
196 uint8x8_t vout0x01234567 = vqmovun_s16(vacc0x01234567);
197 #endif
198
199 const uint8x8_t voutput_min = vld1_dup_u8(&params->rndnu_neon.output_min);
200 vout0x01234567 = vmax_u8(vout0x01234567, voutput_min);
201
202 const uint8x8_t voutput_max = vld1_dup_u8(&params->rndnu_neon.output_max);
203 vout0x01234567 = vmin_u8(vout0x01234567, voutput_max);
204
205 if (nc >= 8) {
206 vst1_u8(c0 + 0, vout0x01234567);
207
208 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
209
210 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
211
212 nc -= 8;
213 } else {
214 if (nc & 4) {
215 vst1_lane_u32((void*) c0, vreinterpret_u32_u8(vout0x01234567), 0); c0 += 4;
216 vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 4);
217 }
218 if (nc & 2) {
219 vst1_lane_u16((void*) c0, vreinterpret_u16_u8(vout0x01234567), 0); c0 += 2;
220 vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 2);
221 }
222 if (nc & 1) {
223 vst1_lane_u8(c0, vout0x01234567, 0);
224 }
225
226 nc = 0;
227 }
228 } while (nc != 0);
229 }