1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/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/gemm.h>
15
16
xnn_f32_gemminc_minmax_ukernel_1x16s4__fma3_broadcast(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)])17 void xnn_f32_gemminc_minmax_ukernel_1x16s4__fma3_broadcast(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 const float*restrict a,
22 size_t a_stride,
23 const float*restrict w,
24 float*restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 const float*restrict acc,
28 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 1);
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 assert(acc != NULL);
39
40 const float* a0 = a;
41 float* c0 = c;
42
43 do {
44 __m256 vacc0x01234567 = _mm256_load_ps(acc + 0);
45 __m256 vacc0x89ABCDEF = _mm256_load_ps(acc + 8);
46 acc += 16;
47
48 size_t k = kc;
49 while (k >= 4 * sizeof(float)) {
50 __m256 va0 = _mm256_broadcast_ps((const __m128*) a0);
51 a0 += 4;
52
53
54 const __m256 vb01234567c0 = _mm256_load_ps(w + 0);
55 const __m256 vb89ABCDEFc0 = _mm256_load_ps(w + 8);
56
57 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c0, vacc0x01234567);
58 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc0, vacc0x89ABCDEF);
59
60 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
61
62 const __m256 vb01234567c1 = _mm256_load_ps(w + 16);
63 const __m256 vb89ABCDEFc1 = _mm256_load_ps(w + 24);
64
65 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c1, vacc0x01234567);
66 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc1, vacc0x89ABCDEF);
67
68 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
69
70 const __m256 vb01234567c2 = _mm256_load_ps(w + 32);
71 const __m256 vb89ABCDEFc2 = _mm256_load_ps(w + 40);
72
73 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c2, vacc0x01234567);
74 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc2, vacc0x89ABCDEF);
75
76 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
77
78 const __m256 vb01234567c3 = _mm256_load_ps(w + 48);
79 const __m256 vb89ABCDEFc3 = _mm256_load_ps(w + 56);
80
81 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c3, vacc0x01234567);
82 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc3, vacc0x89ABCDEF);
83
84
85 w += 64;
86 k -= 4 * sizeof(float);
87 }
88 if XNN_UNLIKELY(k != 0) {
89 do {
90 const __m256 va0 = _mm256_broadcast_ss(a0);
91 a0 += 1;
92
93 const __m256 vb01234567 = _mm256_load_ps(w);
94 const __m256 vb89ABCDEF = _mm256_load_ps(w + 8);
95 w += 16;
96
97 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567, vacc0x01234567);
98 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEF, vacc0x89ABCDEF);
99
100 k -= sizeof(float);
101 } while (k != 0);
102 }
103
104 const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
105 vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
106 vacc0x89ABCDEF = _mm256_min_ps(vacc0x89ABCDEF, vmax);
107
108 const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
109 vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
110 vacc0x89ABCDEF = _mm256_max_ps(vacc0x89ABCDEF, vmin);
111
112 if XNN_LIKELY(nc >= 16) {
113 _mm256_storeu_ps(c0, vacc0x01234567);
114 _mm256_storeu_ps(c0 + 8, vacc0x89ABCDEF);
115 c0 = (float*) ((uintptr_t) c0 + cn_stride);
116
117 a0 = (const float*) ((uintptr_t) a0 - kc);
118
119 nc -= 16;
120 } else {
121 if (nc & 8) {
122 _mm256_storeu_ps(c0, vacc0x01234567);
123
124 vacc0x01234567 = vacc0x89ABCDEF;
125
126 c0 += 8;
127 }
128 __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567);
129 if (nc & 4) {
130 _mm_storeu_ps(c0, vacc0x0123);
131
132 vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1);
133
134 c0 += 4;
135 }
136 if (nc & 2) {
137 _mm_storel_pi((__m64*) c0, vacc0x0123);
138
139 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
140
141 c0 += 2;
142 }
143 if (nc & 1) {
144 _mm_store_ss(c0, vacc0x0123);
145 }
146
147 nc = 0;
148 }
149 } while (nc != 0);
150 }
151