1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/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_gemm_minmax_rndnu_ukernel_2x8c2s4__neon_mull(size_t mr,size_t nc,size_t kc,const int8_t * restrict a,size_t a_stride,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_gemm_minmax_rndnu_ukernel_2x8c2s4__neon_mull(
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_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
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 kc = round_up_po2(kc, 8 * sizeof(int8_t));
49 do {
50 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
51 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
52 int32x4_t vacc1x0123 = vacc0x0123;
53 int32x4_t vacc1x4567 = vacc0x4567;
54
55 size_t k = kc;
56 do {
57 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
58 int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
59
60 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
61 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
62 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
63 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
64 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
65 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8;
66 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
67 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8;
68
69 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0);
70 int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1x0);
71 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
72 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
73 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0);
74 int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1x0);
75 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
76 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
77 va0x0 = vext_s8(va0x0, va0x0, 2);
78 va1x0 = vext_s8(va1x0, va1x0, 2);
79 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0);
80 int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1x0);
81 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
82 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
83 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0);
84 int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1x0);
85 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
86 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
87 va0x0 = vext_s8(va0x0, va0x0, 2);
88 va1x0 = vext_s8(va1x0, va1x0, 2);
89 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0);
90 int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1x0);
91 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
92 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
93 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0);
94 int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1x0);
95 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
96 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
97 va0x0 = vext_s8(va0x0, va0x0, 2);
98 va1x0 = vext_s8(va1x0, va1x0, 2);
99 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0);
100 int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1x0);
101 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
102 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
103 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0);
104 int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1x0);
105 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
106 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
107
108 k -= 8 * sizeof(int8_t);
109 } while (k != 0);
110
111 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
112 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
113 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
114
115 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
116 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
117 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
118 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
119
120 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
121 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
122 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
123 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
124
125 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
126 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
127 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
128 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
129
130 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
131 #if XNN_ARCH_ARM64
132 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
133 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
134
135 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
136 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
137
138 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
139 #else
140 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
141 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
142
143 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
144 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
145
146 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
147 #endif
148
149 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
150 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
151
152 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
153 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
154
155 if (nc >= 8) {
156 vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
157 vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
158
159 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
160 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
161
162 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
163 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
164
165 nc -= 8;
166 } else {
167 // Final case where not all of the 8 columns fit in the destination.
168 if (nc & 4) {
169 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
170 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
171 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
172 }
173 if (nc & 2) {
174 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
175 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
176 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
177 }
178 if (nc & 1) {
179 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
180 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
181 }
182
183 nc = 0;
184 }
185 } while (nc != 0);
186 }
187