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
17
xnn_qc8_igemm_minmax_fp32_ukernel_1x8__neon_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)])18 void xnn_qc8_igemm_minmax_fp32_ukernel_1x8__neon_mlal_lane(
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_qc8_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 int8_t* c0 = c;
44
45 do {
46 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
47 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
48
49 size_t p = ks;
50 do {
51 const int8_t* restrict a0 = a[0];
52 if XNN_UNPREDICTABLE(a0 != zero) {
53 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
54 }
55 a += 1;
56
57 size_t k = kc;
58 while (k >= 8 * sizeof(int8_t)) {
59 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
60 const int16x8_t vxa0 = vmovl_s8(va0);
61
62 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
63 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
64
65 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
66 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
67 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
68 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
69
70 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
71 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
72 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
73 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
74
75 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
76 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
77 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
78 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
79
80 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
81 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
82
83
84 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
85 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
86
87 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
88 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
89 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
90 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
91
92 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
93 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
94 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
95 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
96
97 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
98 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
99 const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
100 const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7);
101
102 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
103 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
104
105 k -= 8 * sizeof(int8_t);
106 }
107 if XNN_UNLIKELY(k != 0) {
108 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
109 const int16x8_t vxa0 = vmovl_s8(va0);
110
111 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
112 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
113
114 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
115 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
116
117 if (k >= 2 * sizeof(int8_t)) {
118 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
119 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
120
121 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
122 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
123
124 if (k > 2 * sizeof(int8_t)) {
125 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
126 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
127
128 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
129 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
130
131 if (k >= 4 * sizeof(int8_t)) {
132 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
133 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
134
135 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
136 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
137
138 if (k > 4 * sizeof(int8_t)) {
139 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
140 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
141
142 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
143 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
144
145 if (k >= 6 * sizeof(int8_t)) {
146 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
147 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
148
149 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
150 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
151
152 if (k > 6 * sizeof(int8_t)) {
153 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
154 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
155
156 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
157 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
158 }
159 }
160 }
161 }
162 }
163 }
164 }
165 p -= 1 * sizeof(void*);
166 } while (p != 0);
167
168 // Post-accumulation work
169 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
170 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
171
172 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
173 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
174 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
175 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
176
177 const float32x4_t vmagic_bias = vld1q_dup_f32(¶ms->fp32_neon.magic_bias);
178 vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias));
179 vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias));
180
181 const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(¶ms->fp32_neon.magic_bias_less_output_zero_point);
182 vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point);
183 vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point);
184
185 #if XNN_ARCH_ARM64
186 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
187
188
189 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
190 #else
191 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
192
193
194 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
195 #endif
196
197 const int8x8_t voutput_min = vld1_dup_s8(¶ms->fp32_neon.output_min);
198 vout0x01234567 = vmax_s8(vout0x01234567, voutput_min);
199
200 const int8x8_t voutput_max = vld1_dup_s8(¶ms->fp32_neon.output_max);
201 vout0x01234567 = vmin_s8(vout0x01234567, voutput_max);
202
203 if (nc >= 8) {
204 vst1_s8(c0 + 0, vout0x01234567);
205
206 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
207
208 a = (const int8_t**restrict) ((uintptr_t) a - ks);
209
210 nc -= 8;
211 } else {
212 if (nc & 4) {
213 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
214 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
215 }
216 if (nc & 2) {
217 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
218 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
219 }
220 if (nc & 1) {
221 vst1_lane_s8(c0, vout0x01234567, 0);
222 }
223
224 nc = 0;
225 }
226 } while (nc != 0);
227 }
228