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