1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/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
xnn_qs8_igemm_minmax_rndnu_ukernel_3x8c2s4__neon_mull(size_t mr,size_t nc,size_t kc,size_t ks,const int8_t ** restrict a,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const int8_t * zero,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_igemm_minmax_rndnu_ukernel_3x8c2s4__neon_mull(
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 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const int8_t* zero,
30 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32 assert(mr != 0);
33 assert(mr <= 3);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(ks != 0);
37 assert(ks % (3 * sizeof(void*)) == 0);
38 assert(a_offset % sizeof(int8_t) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 int8_t* c0 = c;
44 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr < 2) {
46 c1 = c0;
47 }
48 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
49 if XNN_UNPREDICTABLE(mr <= 2) {
50 c2 = c1;
51 }
52
53 kc = round_up_po2(kc, 8 * sizeof(int8_t));
54 do {
55 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
56 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
57 int32x4_t vacc1x0123 = vacc0x0123;
58 int32x4_t vacc1x4567 = vacc0x4567;
59 int32x4_t vacc2x0123 = vacc0x0123;
60 int32x4_t vacc2x4567 = vacc0x4567;
61
62 size_t p = ks;
63 do {
64 const int8_t* restrict a0 = a[0];
65 if XNN_UNPREDICTABLE(a0 != zero) {
66 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
67 }
68 const int8_t* restrict a1 = a[1];
69 if XNN_UNPREDICTABLE(a1 != zero) {
70 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
71 }
72 const int8_t* restrict a2 = a[2];
73 if XNN_UNPREDICTABLE(a2 != zero) {
74 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
75 }
76 a += 3;
77
78 size_t k = kc;
79 do {
80 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
81 int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
82 int8x8_t va2x0 = vld1_s8(a2); a2 += 8;
83
84 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
85 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
86 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
87 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
88 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
89 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
90 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
91 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
92
93 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0);
94 int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1x0);
95 int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0x0, va2x0);
96 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
97 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
98 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
99 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0);
100 int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1x0);
101 int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0x0, va2x0);
102 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
103 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
104 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
105 va0x0 = vext_s8(va0x0, va0x0, 2);
106 va1x0 = vext_s8(va1x0, va1x0, 2);
107 va2x0 = vext_s8(va2x0, va2x0, 2);
108 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0);
109 int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1x0);
110 int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1x0, va2x0);
111 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
112 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
113 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
114 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0);
115 int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1x0);
116 int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1x0, va2x0);
117 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
118 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
119 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
120 va0x0 = vext_s8(va0x0, va0x0, 2);
121 va1x0 = vext_s8(va1x0, va1x0, 2);
122 va2x0 = vext_s8(va2x0, va2x0, 2);
123 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0);
124 int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1x0);
125 int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2x0, va2x0);
126 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
127 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
128 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
129 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0);
130 int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1x0);
131 int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2x0, va2x0);
132 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
133 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
134 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
135 va0x0 = vext_s8(va0x0, va0x0, 2);
136 va1x0 = vext_s8(va1x0, va1x0, 2);
137 va2x0 = vext_s8(va2x0, va2x0, 2);
138 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0);
139 int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1x0);
140 int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3x0, va2x0);
141 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
142 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
143 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
144 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0);
145 int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1x0);
146 int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3x0, va2x0);
147 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
148 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
149 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
150
151 k -= 8 * sizeof(int8_t);
152 } while (k != 0);
153
154 p -= 3 * sizeof(void*);
155 } while (p != 0);
156
157 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
158 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
159 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
160
161 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
162 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
163 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
164 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
165 vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
166 vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
167
168 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
169 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
170 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
171 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
172 vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
173 vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
174
175 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
176 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
177 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
178 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
179 vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
180 vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
181
182 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
183 #if XNN_ARCH_ARM64
184 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
185 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
186 int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
187
188 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
189 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
190 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
191
192 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
193 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
194 #else
195 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
196 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
197 int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
198
199 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
200 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
201 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
202
203 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
204 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
205 #endif
206
207 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
208 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
209 vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min));
210
211 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
212 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
213 vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max));
214
215 if (nc >= 8) {
216 vst1_s8(c2 + 0, vout2x01234567);
217 vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
218 vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
219
220 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
221 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
222 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
223
224 a = (const int8_t**restrict) ((uintptr_t) a - ks);
225
226 nc -= 8;
227 } else {
228 if (nc & 4) {
229 vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
230 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
231 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
232 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
233 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
234 }
235 if (nc & 2) {
236 vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
237 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
238 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
239 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
240 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
241 }
242 if (nc & 1) {
243 vst1_lane_s8(c2, vout2x01234567, 0);
244 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
245 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
246 }
247
248 nc = 0;
249 }
250 } while (nc != 0);
251 }
252