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/intrinsics-polyfill.h>
16 #include <xnnpack/math.h>
17
xnn_qs8_igemm_minmax_fp32_ukernel_1x8c2__neonv8_mlal_dup(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_fp32_ukernel_1x8c2__neonv8_mlal_dup(
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 <= 1);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(ks != 0);
37 assert(ks % (1 * 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 kc = round_up_po2(kc, 2 * sizeof(int8_t));
44 int8_t* c0 = c;
45
46 do {
47 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
48 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
49
50 size_t p = ks;
51 do {
52 const int8_t* restrict a0 = a[0];
53 if XNN_UNPREDICTABLE(a0 != zero) {
54 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
55 }
56 a += 1;
57
58 size_t k = kc;
59
60 while (k >= 16 * sizeof(int8_t)) {
61 const int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
62 const int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
63
64 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
65 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
66 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
67 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
68 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
69 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
70 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
71 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
72
73 const int8x8_t va0c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 0));
74 const int8x8_t va0c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 0));
75
76 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0);
77 const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
78 vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1);
79 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
80 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0);
81 const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
82 vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1);
83 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
84 const int8x8_t va0c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 1));
85 const int8x8_t va0c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 1));
86
87 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0);
88 const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
89 vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1);
90 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
91 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0);
92 const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
93 vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1);
94 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
95 const int8x8_t va0c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 2));
96 const int8x8_t va0c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 2));
97
98 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0);
99 const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
100 vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1);
101 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
102 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0);
103 const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
104 vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1);
105 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
106 const int8x8_t va0c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 3));
107 const int8x8_t va0c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 3));
108
109 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0);
110 const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
111 vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1);
112 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
113 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0);
114 const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
115 vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1);
116 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
117
118 k -= 16 * sizeof(int8_t);
119 }
120
121 if (k >= 8 * sizeof(int8_t)) {
122 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
123
124 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
125 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
126 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
127 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
128 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
129 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
130 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
131 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
132
133 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
134
135 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
136 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
137 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
138 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
139 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
140
141 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
142 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
143 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
144 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
145 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
146
147 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
148 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
149 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
150 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
151 const int8x8_t va0c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3));
152
153 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
154 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
155 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
156 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
157
158 k -= 8 * sizeof(int8_t);
159 }
160
161 if XNN_UNLIKELY(k != 0) {
162 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
163
164 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
165 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
166
167 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
168 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
169 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
170 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
171 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
172
173 if (k > 2 * sizeof(int8_t)) {
174 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
175 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
176
177 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
178 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
179 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
180 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
181 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
182
183 if (k > 4 * sizeof(int8_t)) {
184 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
185 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
186
187 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
188 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
189 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
190 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
191 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
192 }
193 }
194 }
195 p -= 1 * sizeof(void*);
196 } while (p != 0);
197
198 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
199 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
200
201 const float32x4_t vscale = vld1q_dup_f32(¶ms->fp32_neonv8.scale);
202 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale);
203 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale);
204
205 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
206 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
207
208 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point);
209 #if XNN_ARCH_ARM64
210 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
211
212 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
213
214 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
215 #else
216 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
217
218 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
219
220 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
221 #endif
222
223 const int8x8_t voutput_min = vld1_dup_s8(¶ms->fp32_neonv8.output_min);
224 vout0x01234567 = vmax_s8(vout0x01234567, voutput_min);
225
226 const int8x8_t voutput_max = vld1_dup_s8(¶ms->fp32_neonv8.output_max);
227 vout0x01234567 = vmin_s8(vout0x01234567, voutput_max);
228
229 if (nc >= 8) {
230 vst1_s8(c0 + 0, vout0x01234567);
231
232 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
233
234 a = (const int8_t**restrict) ((uintptr_t) a - ks);
235
236 nc -= 8;
237 } else {
238 if (nc & 4) {
239 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
240 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
241 }
242 if (nc & 2) {
243 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
244 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
245 }
246 if (nc & 1) {
247 vst1_lane_s8(c0, vout0x01234567, 0);
248 }
249
250 nc = 0;
251 }
252 } while (nc != 0);
253 }
254