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