• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-igemm/c2-neon-mull-dup.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/intrinsics-polyfill.h>
16 #include <xnnpack/math.h>
17 
xnn_qc8_igemm_minmax_fp32_ukernel_1x8c2__neonv8_mlal_ld1r(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_1x8c2__neonv8_mlal_ld1r(
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   kc = round_up_po2(kc, 2 * sizeof(int8_t));
44   int8_t* c0 = c;
45 
46   do {
47     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
48     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
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 
60       while (k >= 16 * sizeof(int8_t)) {
61         const int16x4_t va00x0 = vld1_dup_s16((const void*)a0);
62         const int16x4_t va01x0 = vld1_dup_s16((const void*)(a0 + 2));
63         const int16x4_t va02x0 = vld1_dup_s16((const void*)(a0 + 4));
64         const int16x4_t va03x0 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
65         const int16x4_t va00x1 = vld1_dup_s16((const void*)a0);
66         const int16x4_t va01x1 = vld1_dup_s16((const void*)(a0 + 2));
67         const int16x4_t va02x1 = vld1_dup_s16((const void*)(a0 + 4));
68         const int16x4_t va03x1 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
69 
70         const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
71         const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
72         const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
73         const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
74         const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
75         const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
76         const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
77         const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
78 
79         const int8x8_t va0c0x0 = vreinterpret_s8_s16(va00x0);
80         const int8x8_t va0c0x1 = vreinterpret_s8_s16(va00x1);
81 
82         int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0);
83         const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
84         vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1);
85         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
86         int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0);
87         const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
88         vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1);
89         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
90         const int8x8_t va0c1x0 = vreinterpret_s8_s16(va01x0);
91         const int8x8_t va0c1x1 = vreinterpret_s8_s16(va01x1);
92 
93         int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0);
94         const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
95         vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1);
96         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
97         int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0);
98         const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
99         vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1);
100         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
101         const int8x8_t va0c2x0 = vreinterpret_s8_s16(va02x0);
102         const int8x8_t va0c2x1 = vreinterpret_s8_s16(va02x1);
103 
104         int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0);
105         const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
106         vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1);
107         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
108         int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0);
109         const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
110         vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1);
111         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
112         const int8x8_t va0c3x0 = vreinterpret_s8_s16(va03x0);
113         const int8x8_t va0c3x1 = vreinterpret_s8_s16(va03x1);
114 
115         int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0);
116         const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
117         vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1);
118         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
119         int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0);
120         const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
121         vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1);
122         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
123 
124         k -= 16 * sizeof(int8_t);
125       }
126 
127       if (k >= 8 * sizeof(int8_t)) {
128         const int16x4_t va00 = vld1_dup_s16((const void*)a0);
129         const int16x4_t va01 = vld1_dup_s16((const void*)(a0 + 2));
130         const int16x4_t va02 = vld1_dup_s16((const void*)(a0 + 4));
131         const int16x4_t va03 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
132 
133         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
134         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
135         const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
136         const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
137         const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
138         const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
139         const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
140         const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
141 
142         const int8x8_t va0c0 = vreinterpret_s8_s16(va00);
143 
144         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
145         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
146         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
147         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
148         const int8x8_t va0c1 = vreinterpret_s8_s16(va01);
149 
150         const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
151         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
152         const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
153         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
154         const int8x8_t va0c2 = vreinterpret_s8_s16(va02);
155 
156         const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
157         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
158         const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
159         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
160         const int8x8_t va0c3 = vreinterpret_s8_s16(va03);
161 
162         const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
163         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
164         const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
165         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
166 
167         k -= 8 * sizeof(int8_t);
168       }
169 
170       if XNN_UNLIKELY(k != 0) {
171         const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
172 
173         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
174         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
175 
176         const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
177         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
178         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
179         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
180         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
181 
182         if (k > 2 * sizeof(int8_t)) {
183           const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
184           const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
185 
186           const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
187           const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
188           vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
189           const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
190           vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
191 
192           if (k > 4 * sizeof(int8_t)) {
193             const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
194             const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
195 
196             const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
197             const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
198             vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
199             const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
200             vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
201           }
202         }
203       }
204       p -= 1 * sizeof(void*);
205     } while (p != 0);
206 
207     float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
208     float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
209 
210     const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
211     vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
212     const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
213     vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
214 
215     vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
216     vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
217 
218     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
219 #if XNN_ARCH_ARM64
220     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
221 
222     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
223 
224     int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
225 #else
226     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
227 
228     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
229 
230     int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
231 #endif
232 
233     const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neonv8.output_min);
234     vout0x01234567 = vmax_s8(vout0x01234567, voutput_min);
235 
236     const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neonv8.output_max);
237     vout0x01234567 = vmin_s8(vout0x01234567, voutput_max);
238 
239     if (nc >= 8) {
240       vst1_s8(c0 + 0, vout0x01234567);
241 
242       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
243 
244       a = (const int8_t**restrict) ((uintptr_t) a - ks);
245 
246       nc -= 8;
247     } else {
248       if (nc & 4) {
249         vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
250         vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
251       }
252       if (nc & 2) {
253         vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
254         vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
255       }
256       if (nc & 1) {
257         vst1_lane_s8(c0, vout0x01234567, 0);
258       }
259 
260       nc = 0;
261     }
262   } while (nc != 0);
263 }
264