• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-igemm/neon-ld128.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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 
11 #include <assert.h>
12 
13 #include <arm_neon.h>
14 
15 #include <xnnpack/igemm.h>
16 
17 
xnn_f32_igemm_ukernel_4x8__neon_dup_ld128(size_t mr,size_t nc,size_t kc,size_t ks,const float ** restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const float * zero,const union xnn_f32_output_params params[restrict static1])18 void xnn_f32_igemm_ukernel_4x8__neon_dup_ld128(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     size_t ks,
23     const float**restrict a,
24     const float*restrict w,
25     float*restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     size_t a_offset,
29     const float* zero,
30     const union xnn_f32_output_params params[restrict static 1])
31 {
32   assert(mr != 0);
33   assert(mr <= 4);
34   assert(nc != 0);
35   assert(kc != 0);
36   assert(kc % sizeof(float) == 0);
37   assert(ks != 0);
38   assert(ks % (4 * sizeof(void*)) == 0);
39   assert(a_offset % sizeof(float) == 0);
40   assert(a != NULL);
41   assert(w != NULL);
42   assert(c != NULL);
43 
44   float* c0 = c;
45   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
46   if XNN_UNPREDICTABLE(mr < 2) {
47     c1 = c0;
48   }
49   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50   if XNN_UNPREDICTABLE(mr <= 2) {
51     c2 = c1;
52   }
53   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
54   if XNN_UNPREDICTABLE(mr != 4) {
55     c3 = c2;
56   }
57 
58   do {
59     float32x4_t vacc0x0123 = vld1q_f32(w); w += 4;
60     float32x4_t vacc0x4567 = vld1q_f32(w); w += 4;
61     float32x4_t vacc1x0123 = vacc0x0123;
62     float32x4_t vacc1x4567 = vacc0x4567;
63     float32x4_t vacc2x0123 = vacc0x0123;
64     float32x4_t vacc2x4567 = vacc0x4567;
65     float32x4_t vacc3x0123 = vacc0x0123;
66     float32x4_t vacc3x4567 = vacc0x4567;
67 
68     size_t p = ks;
69     do {
70       const float* restrict a0 = a[0];
71       assert(a0 != NULL);
72       if XNN_UNPREDICTABLE(a0 != zero) {
73         a0 = (const float*) ((uintptr_t) a0 + a_offset);
74       }
75       const float* restrict a1 = a[1];
76       assert(a1 != NULL);
77       if XNN_UNPREDICTABLE(a1 != zero) {
78         a1 = (const float*) ((uintptr_t) a1 + a_offset);
79       }
80       const float* restrict a2 = a[2];
81       assert(a2 != NULL);
82       if XNN_UNPREDICTABLE(a2 != zero) {
83         a2 = (const float*) ((uintptr_t) a2 + a_offset);
84       }
85       const float* restrict a3 = a[3];
86       assert(a3 != NULL);
87       if XNN_UNPREDICTABLE(a3 != zero) {
88         a3 = (const float*) ((uintptr_t) a3 + a_offset);
89       }
90       a += 4;
91 
92       size_t k = kc;
93       for (; k >= 4 * sizeof(float); k -= 4 * sizeof(float)) {
94         const float32x4_t va0 = vld1q_f32(a0); a0 += 4;
95         const float32x4_t va1 = vld1q_f32(a1); a1 += 4;
96         const float32x4_t va2 = vld1q_f32(a2); a2 += 4;
97         const float32x4_t va3 = vld1q_f32(a3); a3 += 4;
98 
99 
100         const float32x4_t vb0123c0 = vld1q_f32(w); w += 4;
101         const float32x4_t vb4567c0 = vld1q_f32(w); w += 4;
102 
103         const float32x4_t va0c0 = vdupq_lane_f32(vget_low_f32(va0), 0);
104         const float32x4_t va1c0 = vdupq_lane_f32(vget_low_f32(va1), 0);
105         const float32x4_t va2c0 = vdupq_lane_f32(vget_low_f32(va2), 0);
106         const float32x4_t va3c0 = vdupq_lane_f32(vget_low_f32(va3), 0);
107         vacc0x0123 = vmlaq_f32(vacc0x0123, va0c0, vb0123c0);
108         vacc1x0123 = vmlaq_f32(vacc1x0123, va1c0, vb0123c0);
109         vacc2x0123 = vmlaq_f32(vacc2x0123, va2c0, vb0123c0);
110         vacc3x0123 = vmlaq_f32(vacc3x0123, va3c0, vb0123c0);
111         vacc0x4567 = vmlaq_f32(vacc0x4567, va0c0, vb4567c0);
112         vacc1x4567 = vmlaq_f32(vacc1x4567, va1c0, vb4567c0);
113         vacc2x4567 = vmlaq_f32(vacc2x4567, va2c0, vb4567c0);
114         vacc3x4567 = vmlaq_f32(vacc3x4567, va3c0, vb4567c0);
115 
116         const float32x4_t vb0123c1 = vld1q_f32(w); w += 4;
117         const float32x4_t vb4567c1 = vld1q_f32(w); w += 4;
118 
119         const float32x4_t va0c1 = vdupq_lane_f32(vget_low_f32(va0), 1);
120         const float32x4_t va1c1 = vdupq_lane_f32(vget_low_f32(va1), 1);
121         const float32x4_t va2c1 = vdupq_lane_f32(vget_low_f32(va2), 1);
122         const float32x4_t va3c1 = vdupq_lane_f32(vget_low_f32(va3), 1);
123         vacc0x0123 = vmlaq_f32(vacc0x0123, va0c1, vb0123c1);
124         vacc1x0123 = vmlaq_f32(vacc1x0123, va1c1, vb0123c1);
125         vacc2x0123 = vmlaq_f32(vacc2x0123, va2c1, vb0123c1);
126         vacc3x0123 = vmlaq_f32(vacc3x0123, va3c1, vb0123c1);
127         vacc0x4567 = vmlaq_f32(vacc0x4567, va0c1, vb4567c1);
128         vacc1x4567 = vmlaq_f32(vacc1x4567, va1c1, vb4567c1);
129         vacc2x4567 = vmlaq_f32(vacc2x4567, va2c1, vb4567c1);
130         vacc3x4567 = vmlaq_f32(vacc3x4567, va3c1, vb4567c1);
131 
132         const float32x4_t vb0123c2 = vld1q_f32(w); w += 4;
133         const float32x4_t vb4567c2 = vld1q_f32(w); w += 4;
134 
135         const float32x4_t va0c2 = vdupq_lane_f32(vget_high_f32(va0), 0);
136         const float32x4_t va1c2 = vdupq_lane_f32(vget_high_f32(va1), 0);
137         const float32x4_t va2c2 = vdupq_lane_f32(vget_high_f32(va2), 0);
138         const float32x4_t va3c2 = vdupq_lane_f32(vget_high_f32(va3), 0);
139         vacc0x0123 = vmlaq_f32(vacc0x0123, va0c2, vb0123c2);
140         vacc1x0123 = vmlaq_f32(vacc1x0123, va1c2, vb0123c2);
141         vacc2x0123 = vmlaq_f32(vacc2x0123, va2c2, vb0123c2);
142         vacc3x0123 = vmlaq_f32(vacc3x0123, va3c2, vb0123c2);
143         vacc0x4567 = vmlaq_f32(vacc0x4567, va0c2, vb4567c2);
144         vacc1x4567 = vmlaq_f32(vacc1x4567, va1c2, vb4567c2);
145         vacc2x4567 = vmlaq_f32(vacc2x4567, va2c2, vb4567c2);
146         vacc3x4567 = vmlaq_f32(vacc3x4567, va3c2, vb4567c2);
147 
148         const float32x4_t vb0123c3 = vld1q_f32(w); w += 4;
149         const float32x4_t vb4567c3 = vld1q_f32(w); w += 4;
150 
151         const float32x4_t va0c3 = vdupq_lane_f32(vget_high_f32(va0), 1);
152         const float32x4_t va1c3 = vdupq_lane_f32(vget_high_f32(va1), 1);
153         const float32x4_t va2c3 = vdupq_lane_f32(vget_high_f32(va2), 1);
154         const float32x4_t va3c3 = vdupq_lane_f32(vget_high_f32(va3), 1);
155         vacc0x0123 = vmlaq_f32(vacc0x0123, va0c3, vb0123c3);
156         vacc1x0123 = vmlaq_f32(vacc1x0123, va1c3, vb0123c3);
157         vacc2x0123 = vmlaq_f32(vacc2x0123, va2c3, vb0123c3);
158         vacc3x0123 = vmlaq_f32(vacc3x0123, va3c3, vb0123c3);
159         vacc0x4567 = vmlaq_f32(vacc0x4567, va0c3, vb4567c3);
160         vacc1x4567 = vmlaq_f32(vacc1x4567, va1c3, vb4567c3);
161         vacc2x4567 = vmlaq_f32(vacc2x4567, va2c3, vb4567c3);
162         vacc3x4567 = vmlaq_f32(vacc3x4567, va3c3, vb4567c3);
163       }
164       if XNN_UNLIKELY(k != 0) {
165         do {
166           const float32x4_t va0 = vld1q_dup_f32(a0); a0 += 1;
167           const float32x4_t va1 = vld1q_dup_f32(a1); a1 += 1;
168           const float32x4_t va2 = vld1q_dup_f32(a2); a2 += 1;
169           const float32x4_t va3 = vld1q_dup_f32(a3); a3 += 1;
170 
171           const float32x4_t vb0123 = vld1q_f32(w); w += 4;
172           const float32x4_t vb4567 = vld1q_f32(w); w += 4;
173 
174           vacc0x0123 = vmlaq_f32(vacc0x0123, va0, vb0123);
175           vacc1x0123 = vmlaq_f32(vacc1x0123, va1, vb0123);
176           vacc2x0123 = vmlaq_f32(vacc2x0123, va2, vb0123);
177           vacc3x0123 = vmlaq_f32(vacc3x0123, va3, vb0123);
178           vacc0x4567 = vmlaq_f32(vacc0x4567, va0, vb4567);
179           vacc1x4567 = vmlaq_f32(vacc1x4567, va1, vb4567);
180           vacc2x4567 = vmlaq_f32(vacc2x4567, va2, vb4567);
181           vacc3x4567 = vmlaq_f32(vacc3x4567, va3, vb4567);
182 
183           k -= sizeof(float);
184         } while (k != 0);
185       }
186 
187       p -= 4 * sizeof(void*);
188     } while (p != 0);
189 
190     const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
191     vacc0x0123 = vminq_f32(vacc0x0123, vmax);
192     vacc1x0123 = vminq_f32(vacc1x0123, vmax);
193     vacc2x0123 = vminq_f32(vacc2x0123, vmax);
194     vacc3x0123 = vminq_f32(vacc3x0123, vmax);
195     vacc0x4567 = vminq_f32(vacc0x4567, vmax);
196     vacc1x4567 = vminq_f32(vacc1x4567, vmax);
197     vacc2x4567 = vminq_f32(vacc2x4567, vmax);
198     vacc3x4567 = vminq_f32(vacc3x4567, vmax);
199 
200     const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
201     vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
202     vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
203     vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
204     vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
205     vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
206     vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
207     vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
208     vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
209 
210     if XNN_LIKELY(nc >= 8) {
211       vst1q_f32(c3, vacc3x0123);
212       vst1q_f32(c3 + 4, vacc3x4567);
213       c3 = (float*) ((uintptr_t) c3 + cn_stride);
214       vst1q_f32(c2, vacc2x0123);
215       vst1q_f32(c2 + 4, vacc2x4567);
216       c2 = (float*) ((uintptr_t) c2 + cn_stride);
217       vst1q_f32(c1, vacc1x0123);
218       vst1q_f32(c1 + 4, vacc1x4567);
219       c1 = (float*) ((uintptr_t) c1 + cn_stride);
220       vst1q_f32(c0, vacc0x0123);
221       vst1q_f32(c0 + 4, vacc0x4567);
222       c0 = (float*) ((uintptr_t) c0 + cn_stride);
223 
224       a = (const float**restrict) ((uintptr_t) a - ks);
225       nc -= 8;
226     } else {
227       if (nc & 4) {
228         vst1q_f32(c3, vacc3x0123); c3 += 4;
229         vst1q_f32(c2, vacc2x0123); c2 += 4;
230         vst1q_f32(c1, vacc1x0123); c1 += 4;
231         vst1q_f32(c0, vacc0x0123); c0 += 4;
232 
233         vacc3x0123 = vacc3x4567;
234         vacc2x0123 = vacc2x4567;
235         vacc1x0123 = vacc1x4567;
236         vacc0x0123 = vacc0x4567;
237       }
238       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
239       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
240       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
241       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
242       if (nc & 2) {
243         vst1_f32(c3, vacc3x01); c3 += 2;
244         vst1_f32(c2, vacc2x01); c2 += 2;
245         vst1_f32(c1, vacc1x01); c1 += 2;
246         vst1_f32(c0, vacc0x01); c0 += 2;
247 
248         vacc3x01 = vget_high_f32(vacc3x0123);
249         vacc2x01 = vget_high_f32(vacc2x0123);
250         vacc1x01 = vget_high_f32(vacc1x0123);
251         vacc0x01 = vget_high_f32(vacc0x0123);
252       }
253       if (nc & 1) {
254         vst1_lane_f32(c3, vacc3x01, 0);
255         vst1_lane_f32(c2, vacc2x01, 0);
256         vst1_lane_f32(c1, vacc1x01, 0);
257         vst1_lane_f32(c0, vacc0x01, 0);
258       }
259 
260       nc = 0;
261     }
262   } while (nc != 0);
263 }
264