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_gemm_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 union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemm_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 union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
28 {
29 assert(mr != 0);
30 assert(mr <= 1);
31 assert(nc != 0);
32 assert(kc != 0);
33 assert(kc % sizeof(float) == 0);
34 assert(a != NULL);
35 assert(w != NULL);
36 assert(c != NULL);
37
38 const float* a0 = a;
39 float* c0 = c;
40
41 do {
42 __m256 vacc0x01234567 = _mm256_load_ps(w + 0);
43 __m256 vacc0x89ABCDEF = _mm256_load_ps(w + 8);
44 w += 16;
45
46 size_t k = kc;
47 while (k >= 4 * sizeof(float)) {
48 __m256 va0 = _mm256_broadcast_ps((const __m128*) a0);
49 a0 += 4;
50
51
52 const __m256 vb01234567c0 = _mm256_load_ps(w + 0);
53 const __m256 vb89ABCDEFc0 = _mm256_load_ps(w + 8);
54
55 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c0, vacc0x01234567);
56 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc0, vacc0x89ABCDEF);
57
58 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
59
60 const __m256 vb01234567c1 = _mm256_load_ps(w + 16);
61 const __m256 vb89ABCDEFc1 = _mm256_load_ps(w + 24);
62
63 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c1, vacc0x01234567);
64 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc1, vacc0x89ABCDEF);
65
66 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
67
68 const __m256 vb01234567c2 = _mm256_load_ps(w + 32);
69 const __m256 vb89ABCDEFc2 = _mm256_load_ps(w + 40);
70
71 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c2, vacc0x01234567);
72 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc2, vacc0x89ABCDEF);
73
74 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
75
76 const __m256 vb01234567c3 = _mm256_load_ps(w + 48);
77 const __m256 vb89ABCDEFc3 = _mm256_load_ps(w + 56);
78
79 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567c3, vacc0x01234567);
80 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEFc3, vacc0x89ABCDEF);
81
82
83 w += 64;
84 k -= 4 * sizeof(float);
85 }
86 if XNN_UNLIKELY(k != 0) {
87 __m256 va0 = _mm256_broadcast_ps((const __m128*) a0);
88 a0 = (const float*) ((uintptr_t) a0 + k);
89
90 const __m256 vzero = _mm256_setzero_ps();
91
92 const __m256 vb01234567c0 = _mm256_load_ps(w + 0);
93 const __m256 vb89ABCDEFc0 = _mm256_load_ps(w + 8);
94
95 vacc0x01234567 = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb01234567c0, vzero, _CMP_NEQ_OQ)), vb01234567c0, vacc0x01234567);
96 vacc0x89ABCDEF = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb89ABCDEFc0, vzero, _CMP_NEQ_OQ)), vb89ABCDEFc0, vacc0x89ABCDEF);
97
98 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
99
100 const __m256 vb01234567c1 = _mm256_load_ps(w + 16);
101 const __m256 vb89ABCDEFc1 = _mm256_load_ps(w + 24);
102
103 vacc0x01234567 = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb01234567c1, vzero, _CMP_NEQ_OQ)), vb01234567c1, vacc0x01234567);
104 vacc0x89ABCDEF = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb89ABCDEFc1, vzero, _CMP_NEQ_OQ)), vb89ABCDEFc1, vacc0x89ABCDEF);
105
106 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
107
108 const __m256 vb01234567c2 = _mm256_load_ps(w + 32);
109 const __m256 vb89ABCDEFc2 = _mm256_load_ps(w + 40);
110
111 vacc0x01234567 = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb01234567c2, vzero, _CMP_NEQ_OQ)), vb01234567c2, vacc0x01234567);
112 vacc0x89ABCDEF = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb89ABCDEFc2, vzero, _CMP_NEQ_OQ)), vb89ABCDEFc2, vacc0x89ABCDEF);
113
114 va0 = _mm256_permute_ps(va0, _MM_SHUFFLE(0, 3, 2, 1));
115
116 const __m256 vb01234567c3 = _mm256_load_ps(w + 48);
117 const __m256 vb89ABCDEFc3 = _mm256_load_ps(w + 56);
118
119 vacc0x01234567 = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb01234567c3, vzero, _CMP_NEQ_OQ)), vb01234567c3, vacc0x01234567);
120 vacc0x89ABCDEF = _mm256_fmadd_ps(_mm256_and_ps(va0, _mm256_cmp_ps(vb89ABCDEFc3, vzero, _CMP_NEQ_OQ)), vb89ABCDEFc3, vacc0x89ABCDEF);
121
122
123 w += 64;
124 }
125
126 const __m256 vmin = _mm256_load_ps(params->avx.min);
127 vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
128 vacc0x89ABCDEF = _mm256_max_ps(vacc0x89ABCDEF, vmin);
129
130 const __m256 vmax = _mm256_load_ps(params->avx.max);
131 vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
132 vacc0x89ABCDEF = _mm256_min_ps(vacc0x89ABCDEF, vmax);
133
134 if XNN_LIKELY(nc >= 16) {
135 _mm256_storeu_ps(c0, vacc0x01234567);
136 _mm256_storeu_ps(c0 + 8, vacc0x89ABCDEF);
137 c0 = (float*) ((uintptr_t) c0 + cn_stride);
138
139 a0 = (const float*) ((uintptr_t) a0 - kc);
140
141 nc -= 16;
142 } else {
143 if (nc & 8) {
144 _mm256_storeu_ps(c0, vacc0x01234567);
145
146 vacc0x01234567 = vacc0x89ABCDEF;
147
148 c0 += 8;
149 }
150 __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567);
151 if (nc & 4) {
152 _mm_storeu_ps(c0, vacc0x0123);
153
154 vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1);
155
156 c0 += 4;
157 }
158 if (nc & 2) {
159 _mm_storel_pi((__m64*) c0, vacc0x0123);
160
161 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
162
163 c0 += 2;
164 }
165 if (nc & 1) {
166 _mm_store_ss(c0, vacc0x0123);
167 }
168
169 nc = 0;
170 }
171 } while (nc != 0);
172 }
173