1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/sse-dup.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 <xmmintrin.h>
13
14 #include <xnnpack/gemm.h>
15
16
xnn_f32_gemminc_minmax_ukernel_4x8__sse_dup(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_4x8__sse_dup(
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 <= 4);
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 const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
43 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44 if XNN_UNPREDICTABLE(mr < 2) {
45 a1 = a0;
46 c1 = c0;
47 }
48 const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
49 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 a2 = a1;
52 c2 = c1;
53 }
54 const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
55 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
56 if XNN_UNPREDICTABLE(mr != 4) {
57 a3 = a2;
58 c3 = c2;
59 }
60
61 do {
62 __m128 vacc0x0123 = _mm_load_ps(acc + 0);
63 __m128 vacc0x4567 = _mm_load_ps(acc + 4);
64 __m128 vacc1x0123 = _mm_load_ps(acc + 8);
65 __m128 vacc1x4567 = _mm_load_ps(acc + 12);
66 __m128 vacc2x0123 = _mm_load_ps(acc + 16);
67 __m128 vacc2x4567 = _mm_load_ps(acc + 20);
68 __m128 vacc3x0123 = _mm_load_ps(acc + 24);
69 __m128 vacc3x4567 = _mm_load_ps(acc + 28);
70 acc += 32;
71
72 size_t k = kc;
73 while (k >= 4 * sizeof(float)) {
74 const __m128 va0 = _mm_loadu_ps(a0);
75 a0 += 4;
76 const __m128 va1 = _mm_loadu_ps(a1);
77 a1 += 4;
78 const __m128 va2 = _mm_loadu_ps(a2);
79 a2 += 4;
80 const __m128 va3 = _mm_loadu_ps(a3);
81 a3 += 4;
82
83
84 const __m128 va0c0000 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 0, 0, 0));
85 const __m128 va1c0000 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(0, 0, 0, 0));
86 const __m128 va2c0000 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(0, 0, 0, 0));
87 const __m128 va3c0000 = _mm_shuffle_ps(va3, va3, _MM_SHUFFLE(0, 0, 0, 0));
88
89 const __m128 vb0123c0 = _mm_load_ps(w + 0);
90 const __m128 vb4567c0 = _mm_load_ps(w + 4);
91
92 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c0000, vb0123c0));
93 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c0000, vb0123c0));
94 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c0000, vb0123c0));
95 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c0000, vb0123c0));
96 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c0000, vb4567c0));
97 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c0000, vb4567c0));
98 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c0000, vb4567c0));
99 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c0000, vb4567c0));
100
101 const __m128 va0c1111 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(1, 1, 1, 1));
102 const __m128 va1c1111 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(1, 1, 1, 1));
103 const __m128 va2c1111 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(1, 1, 1, 1));
104 const __m128 va3c1111 = _mm_shuffle_ps(va3, va3, _MM_SHUFFLE(1, 1, 1, 1));
105
106 const __m128 vb0123c1 = _mm_load_ps(w + 8);
107 const __m128 vb4567c1 = _mm_load_ps(w + 12);
108
109 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c1111, vb0123c1));
110 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c1111, vb0123c1));
111 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c1111, vb0123c1));
112 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c1111, vb0123c1));
113 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c1111, vb4567c1));
114 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c1111, vb4567c1));
115 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c1111, vb4567c1));
116 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c1111, vb4567c1));
117
118 const __m128 va0c2222 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(2, 2, 2, 2));
119 const __m128 va1c2222 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(2, 2, 2, 2));
120 const __m128 va2c2222 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(2, 2, 2, 2));
121 const __m128 va3c2222 = _mm_shuffle_ps(va3, va3, _MM_SHUFFLE(2, 2, 2, 2));
122
123 const __m128 vb0123c2 = _mm_load_ps(w + 16);
124 const __m128 vb4567c2 = _mm_load_ps(w + 20);
125
126 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c2222, vb0123c2));
127 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c2222, vb0123c2));
128 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c2222, vb0123c2));
129 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c2222, vb0123c2));
130 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c2222, vb4567c2));
131 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c2222, vb4567c2));
132 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c2222, vb4567c2));
133 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c2222, vb4567c2));
134
135 const __m128 va0c3333 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(3, 3, 3, 3));
136 const __m128 va1c3333 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(3, 3, 3, 3));
137 const __m128 va2c3333 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(3, 3, 3, 3));
138 const __m128 va3c3333 = _mm_shuffle_ps(va3, va3, _MM_SHUFFLE(3, 3, 3, 3));
139
140 const __m128 vb0123c3 = _mm_load_ps(w + 24);
141 const __m128 vb4567c3 = _mm_load_ps(w + 28);
142
143 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c3333, vb0123c3));
144 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c3333, vb0123c3));
145 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c3333, vb0123c3));
146 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3c3333, vb0123c3));
147 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c3333, vb4567c3));
148 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c3333, vb4567c3));
149 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c3333, vb4567c3));
150 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3c3333, vb4567c3));
151
152 w += 32;
153 k -= 4 * sizeof(float);
154 }
155 if XNN_UNLIKELY(k != 0) {
156 do {
157 const __m128 va0 = _mm_load1_ps(a0);
158 a0 += 1;
159 const __m128 va1 = _mm_load1_ps(a1);
160 a1 += 1;
161 const __m128 va2 = _mm_load1_ps(a2);
162 a2 += 1;
163 const __m128 va3 = _mm_load1_ps(a3);
164 a3 += 1;
165
166 const __m128 vb0123 = _mm_load_ps(w);
167 const __m128 vb4567 = _mm_load_ps(w + 4);
168 w += 8;
169
170 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
171 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1, vb0123));
172 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2, vb0123));
173 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3, vb0123));
174 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
175 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1, vb4567));
176 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2, vb4567));
177 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3, vb4567));
178
179 k -= sizeof(float);
180 } while (k != 0);
181 }
182
183 const __m128 vmax = _mm_load_ps(params->sse.max);
184 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
185 vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
186 vacc2x0123 = _mm_min_ps(vacc2x0123, vmax);
187 vacc3x0123 = _mm_min_ps(vacc3x0123, vmax);
188 vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
189 vacc1x4567 = _mm_min_ps(vacc1x4567, vmax);
190 vacc2x4567 = _mm_min_ps(vacc2x4567, vmax);
191 vacc3x4567 = _mm_min_ps(vacc3x4567, vmax);
192
193 const __m128 vmin = _mm_load_ps(params->sse.min);
194 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
195 vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
196 vacc2x0123 = _mm_max_ps(vacc2x0123, vmin);
197 vacc3x0123 = _mm_max_ps(vacc3x0123, vmin);
198 vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
199 vacc1x4567 = _mm_max_ps(vacc1x4567, vmin);
200 vacc2x4567 = _mm_max_ps(vacc2x4567, vmin);
201 vacc3x4567 = _mm_max_ps(vacc3x4567, vmin);
202
203 if XNN_LIKELY(nc >= 8) {
204 _mm_storeu_ps(c3, vacc3x0123);
205 _mm_storeu_ps(c3 + 4, vacc3x4567);
206 c3 = (float*) ((uintptr_t) c3 + cn_stride);
207 _mm_storeu_ps(c2, vacc2x0123);
208 _mm_storeu_ps(c2 + 4, vacc2x4567);
209 c2 = (float*) ((uintptr_t) c2 + cn_stride);
210 _mm_storeu_ps(c1, vacc1x0123);
211 _mm_storeu_ps(c1 + 4, vacc1x4567);
212 c1 = (float*) ((uintptr_t) c1 + cn_stride);
213 _mm_storeu_ps(c0, vacc0x0123);
214 _mm_storeu_ps(c0 + 4, vacc0x4567);
215 c0 = (float*) ((uintptr_t) c0 + cn_stride);
216
217 a3 = (const float*) ((uintptr_t) a3 - kc);
218 a2 = (const float*) ((uintptr_t) a2 - kc);
219 a1 = (const float*) ((uintptr_t) a1 - kc);
220 a0 = (const float*) ((uintptr_t) a0 - kc);
221
222 nc -= 8;
223 } else {
224 if (nc & 4) {
225 _mm_storeu_ps(c3, vacc3x0123);
226 _mm_storeu_ps(c2, vacc2x0123);
227 _mm_storeu_ps(c1, vacc1x0123);
228 _mm_storeu_ps(c0, vacc0x0123);
229
230 vacc3x0123 = vacc3x4567;
231 vacc2x0123 = vacc2x4567;
232 vacc1x0123 = vacc1x4567;
233 vacc0x0123 = vacc0x4567;
234
235 c3 += 4;
236 c2 += 4;
237 c1 += 4;
238 c0 += 4;
239 }
240 if (nc & 2) {
241 _mm_storel_pi((__m64*) c3, vacc3x0123);
242 _mm_storel_pi((__m64*) c2, vacc2x0123);
243 _mm_storel_pi((__m64*) c1, vacc1x0123);
244 _mm_storel_pi((__m64*) c0, vacc0x0123);
245
246 vacc3x0123 = _mm_movehl_ps(vacc3x0123, vacc3x0123);
247 vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
248 vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
249 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
250
251 c3 += 2;
252 c2 += 2;
253 c1 += 2;
254 c0 += 2;
255 }
256 if (nc & 1) {
257 _mm_store_ss(c3, vacc3x0123);
258 _mm_store_ss(c2, vacc2x0123);
259 _mm_store_ss(c1, vacc1x0123);
260 _mm_store_ss(c0, vacc0x0123);
261 }
262
263 nc = 0;
264 }
265 } while (nc != 0);
266 }
267