• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-igemm/avx-shuffle4.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 #include <assert.h>
11 
12 #include <immintrin.h>
13 
14 #include <xnnpack/igemm.h>
15 
16 
xnn_f32_igemm_minmax_ukernel_5x16s4__fma3_broadcast(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_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_igemm_minmax_ukernel_5x16s4__fma3_broadcast(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     size_t ks,
22     const float**restrict a,
23     const float*restrict w,
24     float*restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     size_t a_offset,
28     const float* zero,
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(ks != 0);
37   assert(ks % (5 * sizeof(void*)) == 0);
38   assert(a_offset % sizeof(float) == 0);
39   assert(a != NULL);
40   assert(w != NULL);
41   assert(c != NULL);
42 
43   float* c0 = c;
44   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
45   if XNN_UNPREDICTABLE(mr < 2) {
46     c1 = c0;
47   }
48   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 2) {
50     c2 = c1;
51   }
52   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
53   if XNN_UNPREDICTABLE(mr < 4) {
54     c3 = c2;
55   }
56   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
57   if XNN_UNPREDICTABLE(mr <= 4) {
58     c4 = c3;
59   }
60 
61   do {
62     __m256 vacc0x01234567 = _mm256_load_ps(w);
63     __m256 vacc0x89ABCDEF = _mm256_load_ps(w + 8);
64     __m256 vacc1x01234567 = vacc0x01234567;
65     __m256 vacc1x89ABCDEF = vacc0x89ABCDEF;
66     __m256 vacc2x01234567 = vacc0x01234567;
67     __m256 vacc2x89ABCDEF = vacc0x89ABCDEF;
68     __m256 vacc3x01234567 = vacc0x01234567;
69     __m256 vacc3x89ABCDEF = vacc0x89ABCDEF;
70     __m256 vacc4x01234567 = vacc0x01234567;
71     __m256 vacc4x89ABCDEF = vacc0x89ABCDEF;
72     w += 16;
73 
74     size_t p = ks;
75     do {
76       const float* restrict a0 = a[0];
77       assert(a0 != NULL);
78       if XNN_UNPREDICTABLE(a0 != zero) {
79         a0 = (const float*) ((uintptr_t) a0 + a_offset);
80       }
81       const float* restrict a1 = a[1];
82       assert(a1 != NULL);
83       if XNN_UNPREDICTABLE(a1 != zero) {
84         a1 = (const float*) ((uintptr_t) a1 + a_offset);
85       }
86       const float* restrict a2 = a[2];
87       assert(a2 != NULL);
88       if XNN_UNPREDICTABLE(a2 != zero) {
89         a2 = (const float*) ((uintptr_t) a2 + a_offset);
90       }
91       const float* restrict a3 = a[3];
92       assert(a3 != NULL);
93       if XNN_UNPREDICTABLE(a3 != zero) {
94         a3 = (const float*) ((uintptr_t) a3 + a_offset);
95       }
96       const float* restrict a4 = a[4];
97       assert(a4 != NULL);
98       if XNN_UNPREDICTABLE(a4 != zero) {
99         a4 = (const float*) ((uintptr_t) a4 + a_offset);
100       }
101       a += 5;
102 
103       size_t k = kc;
104       while (k >= 4 * sizeof(float)) {
105         __m256 va0 = _mm256_broadcast_ps((const __m128*) a0);
106         a0 += 4;
107         __m256 va1 = _mm256_broadcast_ps((const __m128*) a1);
108         a1 += 4;
109         __m256 va2 = _mm256_broadcast_ps((const __m128*) a2);
110         a2 += 4;
111         __m256 va3 = _mm256_broadcast_ps((const __m128*) a3);
112         a3 += 4;
113         __m256 va4 = _mm256_broadcast_ps((const __m128*) a4);
114         a4 += 4;
115 
116 
117         const __m256 vb01234567c0 = _mm256_load_ps(w + 0);
118         const __m256 vb89ABCDEFc0 = _mm256_load_ps(w + 8);
119 
120         vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c0, vacc0x01234567);
121         vacc1x01234567 = _mm256_fmadd_ps(va1, vb01234567c0, vacc1x01234567);
122         vacc2x01234567 = _mm256_fmadd_ps(va2, vb01234567c0, vacc2x01234567);
123         vacc3x01234567 = _mm256_fmadd_ps(va3, vb01234567c0, vacc3x01234567);
124         vacc4x01234567 = _mm256_fmadd_ps(va4, vb01234567c0, vacc4x01234567);
125         vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc0, vacc0x89ABCDEF);
126         vacc1x89ABCDEF = _mm256_fmadd_ps(va1, vb89ABCDEFc0, vacc1x89ABCDEF);
127         vacc2x89ABCDEF = _mm256_fmadd_ps(va2, vb89ABCDEFc0, vacc2x89ABCDEF);
128         vacc3x89ABCDEF = _mm256_fmadd_ps(va3, vb89ABCDEFc0, vacc3x89ABCDEF);
129         vacc4x89ABCDEF = _mm256_fmadd_ps(va4, vb89ABCDEFc0, vacc4x89ABCDEF);
130 
131         va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
132         va1 = _mm256_permute_ps(va1, _MM_SHUFFLE(0, 3, 2, 1));
133         va2 = _mm256_permute_ps(va2, _MM_SHUFFLE(0, 3, 2, 1));
134         va3 = _mm256_permute_ps(va3, _MM_SHUFFLE(0, 3, 2, 1));
135         va4 = _mm256_permute_ps(va4, _MM_SHUFFLE(0, 3, 2, 1));
136 
137         const __m256 vb01234567c1 = _mm256_load_ps(w + 16);
138         const __m256 vb89ABCDEFc1 = _mm256_load_ps(w + 24);
139 
140         vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c1, vacc0x01234567);
141         vacc1x01234567 = _mm256_fmadd_ps(va1, vb01234567c1, vacc1x01234567);
142         vacc2x01234567 = _mm256_fmadd_ps(va2, vb01234567c1, vacc2x01234567);
143         vacc3x01234567 = _mm256_fmadd_ps(va3, vb01234567c1, vacc3x01234567);
144         vacc4x01234567 = _mm256_fmadd_ps(va4, vb01234567c1, vacc4x01234567);
145         vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc1, vacc0x89ABCDEF);
146         vacc1x89ABCDEF = _mm256_fmadd_ps(va1, vb89ABCDEFc1, vacc1x89ABCDEF);
147         vacc2x89ABCDEF = _mm256_fmadd_ps(va2, vb89ABCDEFc1, vacc2x89ABCDEF);
148         vacc3x89ABCDEF = _mm256_fmadd_ps(va3, vb89ABCDEFc1, vacc3x89ABCDEF);
149         vacc4x89ABCDEF = _mm256_fmadd_ps(va4, vb89ABCDEFc1, vacc4x89ABCDEF);
150 
151         va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
152         va1 = _mm256_permute_ps(va1, _MM_SHUFFLE(0, 3, 2, 1));
153         va2 = _mm256_permute_ps(va2, _MM_SHUFFLE(0, 3, 2, 1));
154         va3 = _mm256_permute_ps(va3, _MM_SHUFFLE(0, 3, 2, 1));
155         va4 = _mm256_permute_ps(va4, _MM_SHUFFLE(0, 3, 2, 1));
156 
157         const __m256 vb01234567c2 = _mm256_load_ps(w + 32);
158         const __m256 vb89ABCDEFc2 = _mm256_load_ps(w + 40);
159 
160         vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c2, vacc0x01234567);
161         vacc1x01234567 = _mm256_fmadd_ps(va1, vb01234567c2, vacc1x01234567);
162         vacc2x01234567 = _mm256_fmadd_ps(va2, vb01234567c2, vacc2x01234567);
163         vacc3x01234567 = _mm256_fmadd_ps(va3, vb01234567c2, vacc3x01234567);
164         vacc4x01234567 = _mm256_fmadd_ps(va4, vb01234567c2, vacc4x01234567);
165         vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc2, vacc0x89ABCDEF);
166         vacc1x89ABCDEF = _mm256_fmadd_ps(va1, vb89ABCDEFc2, vacc1x89ABCDEF);
167         vacc2x89ABCDEF = _mm256_fmadd_ps(va2, vb89ABCDEFc2, vacc2x89ABCDEF);
168         vacc3x89ABCDEF = _mm256_fmadd_ps(va3, vb89ABCDEFc2, vacc3x89ABCDEF);
169         vacc4x89ABCDEF = _mm256_fmadd_ps(va4, vb89ABCDEFc2, vacc4x89ABCDEF);
170 
171         va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
172         va1 = _mm256_permute_ps(va1, _MM_SHUFFLE(0, 3, 2, 1));
173         va2 = _mm256_permute_ps(va2, _MM_SHUFFLE(0, 3, 2, 1));
174         va3 = _mm256_permute_ps(va3, _MM_SHUFFLE(0, 3, 2, 1));
175         va4 = _mm256_permute_ps(va4, _MM_SHUFFLE(0, 3, 2, 1));
176 
177         const __m256 vb01234567c3 = _mm256_load_ps(w + 48);
178         const __m256 vb89ABCDEFc3 = _mm256_load_ps(w + 56);
179 
180         vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c3, vacc0x01234567);
181         vacc1x01234567 = _mm256_fmadd_ps(va1, vb01234567c3, vacc1x01234567);
182         vacc2x01234567 = _mm256_fmadd_ps(va2, vb01234567c3, vacc2x01234567);
183         vacc3x01234567 = _mm256_fmadd_ps(va3, vb01234567c3, vacc3x01234567);
184         vacc4x01234567 = _mm256_fmadd_ps(va4, vb01234567c3, vacc4x01234567);
185         vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc3, vacc0x89ABCDEF);
186         vacc1x89ABCDEF = _mm256_fmadd_ps(va1, vb89ABCDEFc3, vacc1x89ABCDEF);
187         vacc2x89ABCDEF = _mm256_fmadd_ps(va2, vb89ABCDEFc3, vacc2x89ABCDEF);
188         vacc3x89ABCDEF = _mm256_fmadd_ps(va3, vb89ABCDEFc3, vacc3x89ABCDEF);
189         vacc4x89ABCDEF = _mm256_fmadd_ps(va4, vb89ABCDEFc3, vacc4x89ABCDEF);
190 
191 
192         w += 64;
193         k -= 4 * sizeof(float);
194       }
195       if XNN_UNLIKELY(k != 0) {
196         do {
197           const __m256 va0 = _mm256_broadcast_ss(a0);
198           a0 += 1;
199           const __m256 va1 = _mm256_broadcast_ss(a1);
200           a1 += 1;
201           const __m256 va2 = _mm256_broadcast_ss(a2);
202           a2 += 1;
203           const __m256 va3 = _mm256_broadcast_ss(a3);
204           a3 += 1;
205           const __m256 va4 = _mm256_broadcast_ss(a4);
206           a4 += 1;
207 
208           const __m256 vb01234567 = _mm256_load_ps(w);
209           const __m256 vb89ABCDEF = _mm256_load_ps(w + 8);
210           w += 16;
211 
212           vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567, vacc0x01234567);
213           vacc1x01234567 = _mm256_fmadd_ps(va1, vb01234567, vacc1x01234567);
214           vacc2x01234567 = _mm256_fmadd_ps(va2, vb01234567, vacc2x01234567);
215           vacc3x01234567 = _mm256_fmadd_ps(va3, vb01234567, vacc3x01234567);
216           vacc4x01234567 = _mm256_fmadd_ps(va4, vb01234567, vacc4x01234567);
217           vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEF, vacc0x89ABCDEF);
218           vacc1x89ABCDEF = _mm256_fmadd_ps(va1, vb89ABCDEF, vacc1x89ABCDEF);
219           vacc2x89ABCDEF = _mm256_fmadd_ps(va2, vb89ABCDEF, vacc2x89ABCDEF);
220           vacc3x89ABCDEF = _mm256_fmadd_ps(va3, vb89ABCDEF, vacc3x89ABCDEF);
221           vacc4x89ABCDEF = _mm256_fmadd_ps(va4, vb89ABCDEF, vacc4x89ABCDEF);
222 
223           k -= sizeof(float);
224         } while (k != 0);
225       }
226       p -= 5 * sizeof(void*);
227     } while (p != 0);
228 
229     const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
230     vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
231     vacc1x01234567 = _mm256_min_ps(vacc1x01234567, vmax);
232     vacc2x01234567 = _mm256_min_ps(vacc2x01234567, vmax);
233     vacc3x01234567 = _mm256_min_ps(vacc3x01234567, vmax);
234     vacc4x01234567 = _mm256_min_ps(vacc4x01234567, vmax);
235     vacc0x89ABCDEF = _mm256_min_ps(vacc0x89ABCDEF, vmax);
236     vacc1x89ABCDEF = _mm256_min_ps(vacc1x89ABCDEF, vmax);
237     vacc2x89ABCDEF = _mm256_min_ps(vacc2x89ABCDEF, vmax);
238     vacc3x89ABCDEF = _mm256_min_ps(vacc3x89ABCDEF, vmax);
239     vacc4x89ABCDEF = _mm256_min_ps(vacc4x89ABCDEF, vmax);
240 
241     const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
242     vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
243     vacc1x01234567 = _mm256_max_ps(vacc1x01234567, vmin);
244     vacc2x01234567 = _mm256_max_ps(vacc2x01234567, vmin);
245     vacc3x01234567 = _mm256_max_ps(vacc3x01234567, vmin);
246     vacc4x01234567 = _mm256_max_ps(vacc4x01234567, vmin);
247     vacc0x89ABCDEF = _mm256_max_ps(vacc0x89ABCDEF, vmin);
248     vacc1x89ABCDEF = _mm256_max_ps(vacc1x89ABCDEF, vmin);
249     vacc2x89ABCDEF = _mm256_max_ps(vacc2x89ABCDEF, vmin);
250     vacc3x89ABCDEF = _mm256_max_ps(vacc3x89ABCDEF, vmin);
251     vacc4x89ABCDEF = _mm256_max_ps(vacc4x89ABCDEF, vmin);
252 
253     if XNN_LIKELY(nc >= 16) {
254       _mm256_storeu_ps(c4, vacc4x01234567);
255       _mm256_storeu_ps(c4 + 8, vacc4x89ABCDEF);
256       c4 = (float*) ((uintptr_t) c4 + cn_stride);
257       _mm256_storeu_ps(c3, vacc3x01234567);
258       _mm256_storeu_ps(c3 + 8, vacc3x89ABCDEF);
259       c3 = (float*) ((uintptr_t) c3 + cn_stride);
260       _mm256_storeu_ps(c2, vacc2x01234567);
261       _mm256_storeu_ps(c2 + 8, vacc2x89ABCDEF);
262       c2 = (float*) ((uintptr_t) c2 + cn_stride);
263       _mm256_storeu_ps(c1, vacc1x01234567);
264       _mm256_storeu_ps(c1 + 8, vacc1x89ABCDEF);
265       c1 = (float*) ((uintptr_t) c1 + cn_stride);
266       _mm256_storeu_ps(c0, vacc0x01234567);
267       _mm256_storeu_ps(c0 + 8, vacc0x89ABCDEF);
268       c0 = (float*) ((uintptr_t) c0 + cn_stride);
269 
270       a = (const float**restrict) ((uintptr_t) a - ks);
271       nc -= 16;
272     } else {
273       if (nc & 8) {
274         _mm256_storeu_ps(c4, vacc4x01234567);
275         _mm256_storeu_ps(c3, vacc3x01234567);
276         _mm256_storeu_ps(c2, vacc2x01234567);
277         _mm256_storeu_ps(c1, vacc1x01234567);
278         _mm256_storeu_ps(c0, vacc0x01234567);
279 
280         vacc4x01234567 = vacc4x89ABCDEF;
281         vacc3x01234567 = vacc3x89ABCDEF;
282         vacc2x01234567 = vacc2x89ABCDEF;
283         vacc1x01234567 = vacc1x89ABCDEF;
284         vacc0x01234567 = vacc0x89ABCDEF;
285 
286         c4 += 8;
287         c3 += 8;
288         c2 += 8;
289         c1 += 8;
290         c0 += 8;
291       }
292       __m128 vacc4x0123 = _mm256_castps256_ps128(vacc4x01234567);
293       __m128 vacc3x0123 = _mm256_castps256_ps128(vacc3x01234567);
294       __m128 vacc2x0123 = _mm256_castps256_ps128(vacc2x01234567);
295       __m128 vacc1x0123 = _mm256_castps256_ps128(vacc1x01234567);
296       __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567);
297       if (nc & 4) {
298         _mm_storeu_ps(c4, vacc4x0123);
299         _mm_storeu_ps(c3, vacc3x0123);
300         _mm_storeu_ps(c2, vacc2x0123);
301         _mm_storeu_ps(c1, vacc1x0123);
302         _mm_storeu_ps(c0, vacc0x0123);
303 
304         vacc4x0123 = _mm256_extractf128_ps(vacc4x01234567, 1);
305         vacc3x0123 = _mm256_extractf128_ps(vacc3x01234567, 1);
306         vacc2x0123 = _mm256_extractf128_ps(vacc2x01234567, 1);
307         vacc1x0123 = _mm256_extractf128_ps(vacc1x01234567, 1);
308         vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1);
309 
310         c4 += 4;
311         c3 += 4;
312         c2 += 4;
313         c1 += 4;
314         c0 += 4;
315       }
316       if (nc & 2) {
317         _mm_storel_pi((__m64*) c4, vacc4x0123);
318         _mm_storel_pi((__m64*) c3, vacc3x0123);
319         _mm_storel_pi((__m64*) c2, vacc2x0123);
320         _mm_storel_pi((__m64*) c1, vacc1x0123);
321         _mm_storel_pi((__m64*) c0, vacc0x0123);
322 
323         vacc4x0123 = _mm_movehl_ps(vacc4x0123, vacc4x0123);
324         vacc3x0123 = _mm_movehl_ps(vacc3x0123, vacc3x0123);
325         vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
326         vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
327         vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
328 
329         c4 += 2;
330         c3 += 2;
331         c2 += 2;
332         c1 += 2;
333         c0 += 2;
334       }
335       if (nc & 1) {
336         _mm_store_ss(c4, vacc4x0123);
337         _mm_store_ss(c3, vacc3x0123);
338         _mm_store_ss(c2, vacc2x0123);
339         _mm_store_ss(c1, vacc1x0123);
340         _mm_store_ss(c0, vacc0x0123);
341       }
342 
343       nc = 0;
344     }
345   } while (nc != 0);
346 }
347