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