blob: 5d4e7350222dfcd62d78194df094e20b98cf383e [file] [log] [blame]
Frank Barchard2302ffd2021-01-22 14:08:02 -08001// Auto-generated file. Do not edit!
2// Template: src/qs8-gemm/c2-neon-mull-padal-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/common.h>
15#include <xnnpack/gemm.h>
16
17
18void xnn_qs8_gemm_minmax_ukernel_2x8c2__neon_mull_padal_dup(
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 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_qs8_gemm_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
29{
30 assert(mr != 0);
31 assert(mr <= 2);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(int8_t) == 0);
35 assert(a != NULL);
36 assert(w != NULL);
37 assert(c != NULL);
38
39 const int8_t* a0 = a;
40 int8_t* c0 = c;
41 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
42 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr != 2) {
44 a1 = a0;
45 c1 = c0;
46 }
47
48 do {
49 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
50 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
51 int32x4_t vacc1x0123 = vacc0x0123;
52 int32x4_t vacc1x4567 = vacc0x4567;
53
54 size_t k = kc;
Frank Barchard7e1f3712021-02-05 11:52:23 -080055
56
Frank Barchard2302ffd2021-01-22 14:08:02 -080057 while (k >= 8 * sizeof(int8_t)) {
58 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
59 const int8x8_t va1 = vld1_s8(a1); a1 += 8;
60
61 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
Frank Barchard2302ffd2021-01-22 14:08:02 -080062 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
Frank Barchard2302ffd2021-01-22 14:08:02 -080063 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
Frank Barchard2302ffd2021-01-22 14:08:02 -080064 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
Frank Barchard2302ffd2021-01-22 14:08:02 -080065 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
Frank Barchard2302ffd2021-01-22 14:08:02 -080066 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
Frank Barchard2302ffd2021-01-22 14:08:02 -080067 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
Frank Barchard2302ffd2021-01-22 14:08:02 -080068 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
69
Frank Barchard7e1f3712021-02-05 11:52:23 -080070 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
71 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
72 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
73 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3)));
74 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
75 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
76 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
77 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
78 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
79 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
80 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
Frank Barchard2302ffd2021-01-22 14:08:02 -080081 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3)));
Frank Barchard7e1f3712021-02-05 11:52:23 -080082 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
83 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
84 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
Frank Barchard2302ffd2021-01-22 14:08:02 -080085 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
Frank Barchard7e1f3712021-02-05 11:52:23 -080086 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
87 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
88 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
89 const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3)));
90 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
91 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
92 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
93 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
94 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
95 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
96 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
Frank Barchard2302ffd2021-01-22 14:08:02 -080097 const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3)));
Frank Barchard7e1f3712021-02-05 11:52:23 -080098 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
99 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
100 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
Frank Barchard2302ffd2021-01-22 14:08:02 -0800101 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
102
103 k -= 8 * sizeof(int8_t);
104 }
Frank Barchard7e1f3712021-02-05 11:52:23 -0800105
Frank Barchard2302ffd2021-01-22 14:08:02 -0800106 if XNN_UNLIKELY(k != 0) {
107 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
108 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
109
110 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
111 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
112
113 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
114 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
115 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
116 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
117 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
118 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
119 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
120 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
121
122 if (k > 2 * sizeof(int8_t)) {
123 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
124 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
125
126 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
127 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
128 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
129 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
130 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
131 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
132 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
133 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
134
135 if (k > 4 * sizeof(int8_t)) {
136 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
137 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
138
139 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
140 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
141 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
142 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
143 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
144 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
145 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
146 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
147
148 if (k > 6 * sizeof(int8_t)) {
149 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
150 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
151
152 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3)));
153 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
154 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3)));
155 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
156 const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3)));
157 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
158 const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3)));
159 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
160 }
161 }
162 }
163 }
164 const int32x4_t vmultiplier = vld1q_dup_s32(&params->neon.multiplier);
165 vacc0x0123 = vqrdmulhq_s32(vacc0x0123, vmultiplier);
166 vacc0x4567 = vqrdmulhq_s32(vacc0x4567, vmultiplier);
167 vacc1x0123 = vqrdmulhq_s32(vacc1x0123, vmultiplier);
168 vacc1x4567 = vqrdmulhq_s32(vacc1x4567, vmultiplier);
169
170 const int32x4_t vright_shift = vld1q_dup_s32(&params->neon.right_shift);
171 const int32x4_t vzero_shift_mask = vreinterpretq_s32_u32(vceqq_s32(vright_shift, vmovq_n_s32(0)));
172 vacc0x0123 = vsraq_n_s32(vacc0x0123, vbicq_s32(vacc0x0123, vzero_shift_mask), 31);
173 vacc0x4567 = vsraq_n_s32(vacc0x4567, vbicq_s32(vacc0x4567, vzero_shift_mask), 31);
174 vacc1x0123 = vsraq_n_s32(vacc1x0123, vbicq_s32(vacc1x0123, vzero_shift_mask), 31);
175 vacc1x4567 = vsraq_n_s32(vacc1x4567, vbicq_s32(vacc1x4567, vzero_shift_mask), 31);
176
177 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_shift);
178 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_shift);
179 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_shift);
180 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_shift);
181
182 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->neon.output_zero_point);
183#if XNN_ARCH_ARM64
184 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
185 const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
186
187 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
188#else
189 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
190 const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
191
192 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
193#endif
194 const int8x16_t voutput_min = vld1q_dup_s8(&params->neon.output_min);
195 const int8x16_t voutput_max = vld1q_dup_s8(&params->neon.output_max);
196
197 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
198
199 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
200
201 if (nc >= 8) {
202 vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
203 vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
204
205 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
206 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
207
208 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
209 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
210
211 nc -= 8;
212 } else {
213 if (nc & 4) {
214 vst1q_lane_u32(__builtin_assume_aligned(c0, 1), vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
215 vst1q_lane_u32(__builtin_assume_aligned(c1, 1), vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
216 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
217 }
218 if (nc & 2) {
219 vst1q_lane_u16(__builtin_assume_aligned(c0, 1), vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
220 vst1q_lane_u16(__builtin_assume_aligned(c1, 1), vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
221 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
222 }
223 if (nc & 1) {
224 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
225 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
226 }
227
228 nc = 0;
229 }
230 } while (nc != 0);
231}