1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/neon-mlal-lane.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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/igemm.h>
16 #include <xnnpack/intrinsics-polyfill.h>
17
18
xnn_qc8_igemm_minmax_fp32_ukernel_1x8__neonv8_mlal_lane(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_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qc8_igemm_minmax_fp32_ukernel_1x8__neonv8_mlal_lane(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 size_t ks,
24 const int8_t** restrict a,
25 const void* restrict w,
26 int8_t* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 size_t a_offset,
30 const int8_t* zero,
31 const union xnn_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
32 {
33 assert(mr != 0);
34 assert(mr <= 1);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (1 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(int8_t) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 int8_t* c0 = c;
45
46 do {
47 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
48 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
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 while (k >= 8 * sizeof(int8_t)) {
60 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
61 const int16x8_t vxa0 = vmovl_s8(va0);
62
63 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
64 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
65
66 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
67 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
68 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
69 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
70
71 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
72 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
73 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
74 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
75
76 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
77 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
78 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
79 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
80
81 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
82 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
83
84
85 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
86 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
87
88 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
89 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
90 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
91 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
92
93 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
94 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
95 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
96 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
97
98 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
99 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
100 const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
101 const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7);
102
103 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
104 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
105
106 k -= 8 * sizeof(int8_t);
107 }
108 if XNN_UNLIKELY(k != 0) {
109 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
110 const int16x8_t vxa0 = vmovl_s8(va0);
111
112 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
113 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
114
115 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
116 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
117
118 if (k >= 2 * sizeof(int8_t)) {
119 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
120 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
121
122 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
123 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
124
125 if (k > 2 * sizeof(int8_t)) {
126 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
127 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
128
129 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
130 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
131
132 if (k >= 4 * sizeof(int8_t)) {
133 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
134 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
135
136 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
137 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
138
139 if (k > 4 * sizeof(int8_t)) {
140 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
141 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
142
143 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
144 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
145
146 if (k >= 6 * sizeof(int8_t)) {
147 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
148 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
149
150 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
151 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
152
153 if (k > 6 * sizeof(int8_t)) {
154 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
155 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
156
157 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
158 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
159 }
160 }
161 }
162 }
163 }
164 }
165 }
166 p -= 1 * sizeof(void*);
167 } while (p != 0);
168
169 // Post-accumulation work
170 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
171 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
172
173 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
174 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
175 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
176 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
177
178 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
179 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
180
181 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point);
182 #if XNN_ARCH_ARM64
183 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
184
185 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
186
187 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
188 #else
189 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
190
191 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
192
193 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
194 #endif
195
196 const int8x8_t voutput_min = vld1_dup_s8(¶ms->fp32_neonv8.output_min);
197 vout0x01234567 = vmax_s8(vout0x01234567, voutput_min);
198
199 const int8x8_t voutput_max = vld1_dup_s8(¶ms->fp32_neonv8.output_max);
200 vout0x01234567 = vmin_s8(vout0x01234567, voutput_max);
201
202 if (nc >= 8) {
203 vst1_s8(c0 + 0, vout0x01234567);
204
205 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
206
207 a = (const int8_t**restrict) ((uintptr_t) a - ks);
208
209 nc -= 8;
210 } else {
211 if (nc & 4) {
212 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
213 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
214 }
215 if (nc & 2) {
216 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
217 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
218 }
219 if (nc & 1) {
220 vst1_lane_s8(c0, vout0x01234567, 0);
221 }
222
223 nc = 0;
224 }
225 } while (nc != 0);
226 }
227