1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/avx-broadcast.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_4x16__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_4x16__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)])
28 {
29 assert(mr != 0);
30 assert(mr <= 4);
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 const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
41 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
42 if XNN_UNPREDICTABLE(mr < 2) {
43 a1 = a0;
44 c1 = c0;
45 }
46 const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
47 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
48 if XNN_UNPREDICTABLE(mr <= 2) {
49 a2 = a1;
50 c2 = c1;
51 }
52 const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
53 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
54 if XNN_UNPREDICTABLE(mr != 4) {
55 a3 = a2;
56 c3 = c2;
57 }
58
59 do {
60 __m256 vacc0x01234567 = _mm256_load_ps(w + 0);
61 __m256 vacc0x89ABCDEF = _mm256_load_ps(w + 8);
62 __m256 vacc1x01234567 = vacc0x01234567;
63 __m256 vacc1x89ABCDEF = vacc0x89ABCDEF;
64 __m256 vacc2x01234567 = vacc0x01234567;
65 __m256 vacc2x89ABCDEF = vacc0x89ABCDEF;
66 __m256 vacc3x01234567 = vacc0x01234567;
67 __m256 vacc3x89ABCDEF = vacc0x89ABCDEF;
68 w += 16;
69
70 size_t k = kc;
71 do {
72 const __m256 va0 = _mm256_broadcast_ss(a0);
73 a0 += 1;
74 const __m256 va1 = _mm256_broadcast_ss(a1);
75 a1 += 1;
76 const __m256 va2 = _mm256_broadcast_ss(a2);
77 a2 += 1;
78 const __m256 va3 = _mm256_broadcast_ss(a3);
79 a3 += 1;
80
81 const __m256 vb01234567 = _mm256_load_ps(w);
82 const __m256 vb89ABCDEF = _mm256_load_ps(w + 8);
83 w += 16;
84
85 vacc0x01234567 = _mm256_fmadd_ps(va0, vb01234567, vacc0x01234567);
86 vacc1x01234567 = _mm256_fmadd_ps(va1, vb01234567, vacc1x01234567);
87 vacc2x01234567 = _mm256_fmadd_ps(va2, vb01234567, vacc2x01234567);
88 vacc3x01234567 = _mm256_fmadd_ps(va3, vb01234567, vacc3x01234567);
89 vacc0x89ABCDEF = _mm256_fmadd_ps(va0, vb89ABCDEF, vacc0x89ABCDEF);
90 vacc1x89ABCDEF = _mm256_fmadd_ps(va1, vb89ABCDEF, vacc1x89ABCDEF);
91 vacc2x89ABCDEF = _mm256_fmadd_ps(va2, vb89ABCDEF, vacc2x89ABCDEF);
92 vacc3x89ABCDEF = _mm256_fmadd_ps(va3, vb89ABCDEF, vacc3x89ABCDEF);
93
94 k -= sizeof(float);
95 } while (k != 0);
96
97 const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
98 vacc0x01234567 = _mm256_min_ps(vacc0x01234567, vmax);
99 vacc1x01234567 = _mm256_min_ps(vacc1x01234567, vmax);
100 vacc2x01234567 = _mm256_min_ps(vacc2x01234567, vmax);
101 vacc3x01234567 = _mm256_min_ps(vacc3x01234567, vmax);
102 vacc0x89ABCDEF = _mm256_min_ps(vacc0x89ABCDEF, vmax);
103 vacc1x89ABCDEF = _mm256_min_ps(vacc1x89ABCDEF, vmax);
104 vacc2x89ABCDEF = _mm256_min_ps(vacc2x89ABCDEF, vmax);
105 vacc3x89ABCDEF = _mm256_min_ps(vacc3x89ABCDEF, vmax);
106
107 const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
108 vacc0x01234567 = _mm256_max_ps(vacc0x01234567, vmin);
109 vacc1x01234567 = _mm256_max_ps(vacc1x01234567, vmin);
110 vacc2x01234567 = _mm256_max_ps(vacc2x01234567, vmin);
111 vacc3x01234567 = _mm256_max_ps(vacc3x01234567, vmin);
112 vacc0x89ABCDEF = _mm256_max_ps(vacc0x89ABCDEF, vmin);
113 vacc1x89ABCDEF = _mm256_max_ps(vacc1x89ABCDEF, vmin);
114 vacc2x89ABCDEF = _mm256_max_ps(vacc2x89ABCDEF, vmin);
115 vacc3x89ABCDEF = _mm256_max_ps(vacc3x89ABCDEF, vmin);
116
117 if XNN_LIKELY(nc >= 16) {
118 _mm256_storeu_ps(c3, vacc3x01234567);
119 _mm256_storeu_ps(c3 + 8, vacc3x89ABCDEF);
120 c3 = (float*) ((uintptr_t) c3 + cn_stride);
121 _mm256_storeu_ps(c2, vacc2x01234567);
122 _mm256_storeu_ps(c2 + 8, vacc2x89ABCDEF);
123 c2 = (float*) ((uintptr_t) c2 + cn_stride);
124 _mm256_storeu_ps(c1, vacc1x01234567);
125 _mm256_storeu_ps(c1 + 8, vacc1x89ABCDEF);
126 c1 = (float*) ((uintptr_t) c1 + cn_stride);
127 _mm256_storeu_ps(c0, vacc0x01234567);
128 _mm256_storeu_ps(c0 + 8, vacc0x89ABCDEF);
129 c0 = (float*) ((uintptr_t) c0 + cn_stride);
130
131 a3 = (const float*) ((uintptr_t) a3 - kc);
132 a2 = (const float*) ((uintptr_t) a2 - kc);
133 a1 = (const float*) ((uintptr_t) a1 - kc);
134 a0 = (const float*) ((uintptr_t) a0 - kc);
135
136 nc -= 16;
137 } else {
138 if (nc & 8) {
139 _mm256_storeu_ps(c3, vacc3x01234567);
140 _mm256_storeu_ps(c2, vacc2x01234567);
141 _mm256_storeu_ps(c1, vacc1x01234567);
142 _mm256_storeu_ps(c0, vacc0x01234567);
143
144 vacc3x01234567 = vacc3x89ABCDEF;
145 vacc2x01234567 = vacc2x89ABCDEF;
146 vacc1x01234567 = vacc1x89ABCDEF;
147 vacc0x01234567 = vacc0x89ABCDEF;
148
149 c3 += 8;
150 c2 += 8;
151 c1 += 8;
152 c0 += 8;
153 }
154 __m128 vacc3x0123 = _mm256_castps256_ps128(vacc3x01234567);
155 __m128 vacc2x0123 = _mm256_castps256_ps128(vacc2x01234567);
156 __m128 vacc1x0123 = _mm256_castps256_ps128(vacc1x01234567);
157 __m128 vacc0x0123 = _mm256_castps256_ps128(vacc0x01234567);
158 if (nc & 4) {
159 _mm_storeu_ps(c3, vacc3x0123);
160 _mm_storeu_ps(c2, vacc2x0123);
161 _mm_storeu_ps(c1, vacc1x0123);
162 _mm_storeu_ps(c0, vacc0x0123);
163
164 vacc3x0123 = _mm256_extractf128_ps(vacc3x01234567, 1);
165 vacc2x0123 = _mm256_extractf128_ps(vacc2x01234567, 1);
166 vacc1x0123 = _mm256_extractf128_ps(vacc1x01234567, 1);
167 vacc0x0123 = _mm256_extractf128_ps(vacc0x01234567, 1);
168
169 c3 += 4;
170 c2 += 4;
171 c1 += 4;
172 c0 += 4;
173 }
174 if (nc & 2) {
175 _mm_storel_pi((__m64*) c3, vacc3x0123);
176 _mm_storel_pi((__m64*) c2, vacc2x0123);
177 _mm_storel_pi((__m64*) c1, vacc1x0123);
178 _mm_storel_pi((__m64*) c0, vacc0x0123);
179
180 vacc3x0123 = _mm_movehl_ps(vacc3x0123, vacc3x0123);
181 vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
182 vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
183 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
184
185 c3 += 2;
186 c2 += 2;
187 c1 += 2;
188 c0 += 2;
189 }
190 if (nc & 1) {
191 _mm_store_ss(c3, vacc3x0123);
192 _mm_store_ss(c2, vacc2x0123);
193 _mm_store_ss(c1, vacc1x0123);
194 _mm_store_ss(c0, vacc0x0123);
195 }
196
197 nc = 0;
198 }
199 } while (nc != 0);
200 }
201