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_gemminc_minmax_ukernel_4x8__neonfma_lane_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 float * restrict acc,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_gemminc_minmax_ukernel_4x8__neonfma_lane_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 float*restrict acc,
29 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31 assert(mr != 0);
32 assert(mr <= 4);
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
62 do {
63 float32x4_t vacc0x0123 = vld1q_f32(acc); acc += 4;
64 float32x4_t vacc0x4567 = vld1q_f32(acc); acc += 4;
65 float32x4_t vacc1x0123 = vld1q_f32(acc); acc += 4;
66 float32x4_t vacc1x4567 = vld1q_f32(acc); acc += 4;
67 float32x4_t vacc2x0123 = vld1q_f32(acc); acc += 4;
68 float32x4_t vacc2x4567 = vld1q_f32(acc); acc += 4;
69 float32x4_t vacc3x0123 = vld1q_f32(acc); acc += 4;
70 float32x4_t vacc3x4567 = vld1q_f32(acc); acc += 4;
71
72 size_t k = kc;
73 for (; k >= 4 * sizeof(float); k -= 4 * sizeof(float)) {
74 const float32x4_t va0 = vld1q_f32(a0); a0 += 4;
75 const float32x4_t va1 = vld1q_f32(a1); a1 += 4;
76 const float32x4_t va2 = vld1q_f32(a2); a2 += 4;
77 const float32x4_t va3 = vld1q_f32(a3); a3 += 4;
78
79
80 const float32x4_t vb0123c0 = vld1q_f32(w); w += 4;
81 const float32x4_t vb4567c0 = vld1q_f32(w); w += 4;
82
83 vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123c0, vget_low_f32(va0), 0);
84 vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123c0, vget_low_f32(va1), 0);
85 vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123c0, vget_low_f32(va2), 0);
86 vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123c0, vget_low_f32(va3), 0);
87 vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567c0, vget_low_f32(va0), 0);
88 vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567c0, vget_low_f32(va1), 0);
89 vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567c0, vget_low_f32(va2), 0);
90 vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567c0, vget_low_f32(va3), 0);
91
92 const float32x4_t vb0123c1 = vld1q_f32(w); w += 4;
93 const float32x4_t vb4567c1 = vld1q_f32(w); w += 4;
94
95 vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123c1, vget_low_f32(va0), 1);
96 vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123c1, vget_low_f32(va1), 1);
97 vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123c1, vget_low_f32(va2), 1);
98 vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123c1, vget_low_f32(va3), 1);
99 vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567c1, vget_low_f32(va0), 1);
100 vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567c1, vget_low_f32(va1), 1);
101 vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567c1, vget_low_f32(va2), 1);
102 vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567c1, vget_low_f32(va3), 1);
103
104 const float32x4_t vb0123c2 = vld1q_f32(w); w += 4;
105 const float32x4_t vb4567c2 = vld1q_f32(w); w += 4;
106
107 vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123c2, vget_high_f32(va0), 0);
108 vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123c2, vget_high_f32(va1), 0);
109 vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123c2, vget_high_f32(va2), 0);
110 vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123c2, vget_high_f32(va3), 0);
111 vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567c2, vget_high_f32(va0), 0);
112 vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567c2, vget_high_f32(va1), 0);
113 vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567c2, vget_high_f32(va2), 0);
114 vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567c2, vget_high_f32(va3), 0);
115
116 const float32x4_t vb0123c3 = vld1q_f32(w); w += 4;
117 const float32x4_t vb4567c3 = vld1q_f32(w); w += 4;
118
119 vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123c3, vget_high_f32(va0), 1);
120 vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123c3, vget_high_f32(va1), 1);
121 vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123c3, vget_high_f32(va2), 1);
122 vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123c3, vget_high_f32(va3), 1);
123 vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567c3, vget_high_f32(va0), 1);
124 vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567c3, vget_high_f32(va1), 1);
125 vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567c3, vget_high_f32(va2), 1);
126 vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567c3, vget_high_f32(va3), 1);
127 }
128 if XNN_UNLIKELY(k != 0) {
129 do {
130 const float32x4_t va0 = vld1q_dup_f32(a0); a0 += 1;
131 const float32x4_t va1 = vld1q_dup_f32(a1); a1 += 1;
132 const float32x4_t va2 = vld1q_dup_f32(a2); a2 += 1;
133 const float32x4_t va3 = vld1q_dup_f32(a3); a3 += 1;
134
135 const float32x4_t vb0123 = vld1q_f32(w); w += 4;
136 const float32x4_t vb4567 = vld1q_f32(w); w += 4;
137
138 vacc0x0123 = vfmaq_f32(vacc0x0123, va0, vb0123);
139 vacc1x0123 = vfmaq_f32(vacc1x0123, va1, vb0123);
140 vacc2x0123 = vfmaq_f32(vacc2x0123, va2, vb0123);
141 vacc3x0123 = vfmaq_f32(vacc3x0123, va3, vb0123);
142 vacc0x4567 = vfmaq_f32(vacc0x4567, va0, vb4567);
143 vacc1x4567 = vfmaq_f32(vacc1x4567, va1, vb4567);
144 vacc2x4567 = vfmaq_f32(vacc2x4567, va2, vb4567);
145 vacc3x4567 = vfmaq_f32(vacc3x4567, va3, vb4567);
146
147 k -= sizeof(float);
148 } while (k != 0);
149 }
150 const float32x4_t vmax = vld1q_dup_f32(¶ms->scalar.max);
151 vacc0x0123 = vminq_f32(vacc0x0123, vmax);
152 vacc1x0123 = vminq_f32(vacc1x0123, vmax);
153 vacc2x0123 = vminq_f32(vacc2x0123, vmax);
154 vacc3x0123 = vminq_f32(vacc3x0123, vmax);
155 vacc0x4567 = vminq_f32(vacc0x4567, vmax);
156 vacc1x4567 = vminq_f32(vacc1x4567, vmax);
157 vacc2x4567 = vminq_f32(vacc2x4567, vmax);
158 vacc3x4567 = vminq_f32(vacc3x4567, vmax);
159
160 const float32x4_t vmin = vld1q_dup_f32(¶ms->scalar.min);
161 vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
162 vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
163 vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
164 vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
165 vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
166 vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
167 vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
168 vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
169
170 if XNN_LIKELY(nc >= 8) {
171 vst1q_f32(c3, vacc3x0123);
172 vst1q_f32(c3 + 4, vacc3x4567);
173 c3 = (float*) ((uintptr_t) c3 + cn_stride);
174 vst1q_f32(c2, vacc2x0123);
175 vst1q_f32(c2 + 4, vacc2x4567);
176 c2 = (float*) ((uintptr_t) c2 + cn_stride);
177 vst1q_f32(c1, vacc1x0123);
178 vst1q_f32(c1 + 4, vacc1x4567);
179 c1 = (float*) ((uintptr_t) c1 + cn_stride);
180 vst1q_f32(c0, vacc0x0123);
181 vst1q_f32(c0 + 4, vacc0x4567);
182 c0 = (float*) ((uintptr_t) c0 + cn_stride);
183
184 a3 = (const float*) ((uintptr_t) a3 - kc);
185 a2 = (const float*) ((uintptr_t) a2 - kc);
186 a1 = (const float*) ((uintptr_t) a1 - kc);
187 a0 = (const float*) ((uintptr_t) a0 - kc);
188
189 nc -= 8;
190
191 } else {
192 if (nc & 4) {
193 vst1q_f32(c3, vacc3x0123); c3 += 4;
194 vst1q_f32(c2, vacc2x0123); c2 += 4;
195 vst1q_f32(c1, vacc1x0123); c1 += 4;
196 vst1q_f32(c0, vacc0x0123); c0 += 4;
197
198 vacc3x0123 = vacc3x4567;
199 vacc2x0123 = vacc2x4567;
200 vacc1x0123 = vacc1x4567;
201 vacc0x0123 = vacc0x4567;
202 }
203 float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
204 float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
205 float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
206 float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
207 if (nc & 2) {
208 vst1_f32(c3, vacc3x01); c3 += 2;
209 vst1_f32(c2, vacc2x01); c2 += 2;
210 vst1_f32(c1, vacc1x01); c1 += 2;
211 vst1_f32(c0, vacc0x01); c0 += 2;
212
213 vacc3x01 = vget_high_f32(vacc3x0123);
214 vacc2x01 = vget_high_f32(vacc2x0123);
215 vacc1x01 = vget_high_f32(vacc1x0123);
216 vacc0x01 = vget_high_f32(vacc0x0123);
217 }
218 if (nc & 1) {
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