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