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