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_3x8__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_3x8__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 <= 3);
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
55 do {
56 __m128 vacc0x0123 = _mm_load_ps(acc + 0);
57 __m128 vacc0x4567 = _mm_load_ps(acc + 4);
58 __m128 vacc1x0123 = _mm_load_ps(acc + 8);
59 __m128 vacc1x4567 = _mm_load_ps(acc + 12);
60 __m128 vacc2x0123 = _mm_load_ps(acc + 16);
61 __m128 vacc2x4567 = _mm_load_ps(acc + 20);
62 acc += 24;
63
64 size_t k = kc;
65 while (k >= 4 * sizeof(float)) {
66 const __m128 va0 = _mm_loadu_ps(a0);
67 a0 += 4;
68 const __m128 va1 = _mm_loadu_ps(a1);
69 a1 += 4;
70 const __m128 va2 = _mm_loadu_ps(a2);
71 a2 += 4;
72
73
74 const __m128 va0c0000 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 0, 0, 0));
75 const __m128 va1c0000 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(0, 0, 0, 0));
76 const __m128 va2c0000 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(0, 0, 0, 0));
77
78 const __m128 vb0123c0 = _mm_load_ps(w + 0);
79 const __m128 vb4567c0 = _mm_load_ps(w + 4);
80
81 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c0000, vb0123c0));
82 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c0000, vb0123c0));
83 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c0000, vb0123c0));
84 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c0000, vb4567c0));
85 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c0000, vb4567c0));
86 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c0000, vb4567c0));
87
88 const __m128 va0c1111 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(1, 1, 1, 1));
89 const __m128 va1c1111 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(1, 1, 1, 1));
90 const __m128 va2c1111 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(1, 1, 1, 1));
91
92 const __m128 vb0123c1 = _mm_load_ps(w + 8);
93 const __m128 vb4567c1 = _mm_load_ps(w + 12);
94
95 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c1111, vb0123c1));
96 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c1111, vb0123c1));
97 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c1111, vb0123c1));
98 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c1111, vb4567c1));
99 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c1111, vb4567c1));
100 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c1111, vb4567c1));
101
102 const __m128 va0c2222 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(2, 2, 2, 2));
103 const __m128 va1c2222 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(2, 2, 2, 2));
104 const __m128 va2c2222 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(2, 2, 2, 2));
105
106 const __m128 vb0123c2 = _mm_load_ps(w + 16);
107 const __m128 vb4567c2 = _mm_load_ps(w + 20);
108
109 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c2222, vb0123c2));
110 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c2222, vb0123c2));
111 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c2222, vb0123c2));
112 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c2222, vb4567c2));
113 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c2222, vb4567c2));
114 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c2222, vb4567c2));
115
116 const __m128 va0c3333 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(3, 3, 3, 3));
117 const __m128 va1c3333 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(3, 3, 3, 3));
118 const __m128 va2c3333 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(3, 3, 3, 3));
119
120 const __m128 vb0123c3 = _mm_load_ps(w + 24);
121 const __m128 vb4567c3 = _mm_load_ps(w + 28);
122
123 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c3333, vb0123c3));
124 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c3333, vb0123c3));
125 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c3333, vb0123c3));
126 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c3333, vb4567c3));
127 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c3333, vb4567c3));
128 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c3333, vb4567c3));
129
130 w += 32;
131 k -= 4 * sizeof(float);
132 }
133 if XNN_UNLIKELY(k != 0) {
134 do {
135 const __m128 va0 = _mm_load1_ps(a0);
136 a0 += 1;
137 const __m128 va1 = _mm_load1_ps(a1);
138 a1 += 1;
139 const __m128 va2 = _mm_load1_ps(a2);
140 a2 += 1;
141
142 const __m128 vb0123 = _mm_load_ps(w);
143 const __m128 vb4567 = _mm_load_ps(w + 4);
144 w += 8;
145
146 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
147 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1, vb0123));
148 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2, vb0123));
149 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
150 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1, vb4567));
151 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2, vb4567));
152
153 k -= sizeof(float);
154 } while (k != 0);
155 }
156
157 const __m128 vmax = _mm_load_ps(params->sse.max);
158 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
159 vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
160 vacc2x0123 = _mm_min_ps(vacc2x0123, vmax);
161 vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
162 vacc1x4567 = _mm_min_ps(vacc1x4567, vmax);
163 vacc2x4567 = _mm_min_ps(vacc2x4567, vmax);
164
165 const __m128 vmin = _mm_load_ps(params->sse.min);
166 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
167 vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
168 vacc2x0123 = _mm_max_ps(vacc2x0123, vmin);
169 vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
170 vacc1x4567 = _mm_max_ps(vacc1x4567, vmin);
171 vacc2x4567 = _mm_max_ps(vacc2x4567, vmin);
172
173 if XNN_LIKELY(nc >= 8) {
174 _mm_storeu_ps(c2, vacc2x0123);
175 _mm_storeu_ps(c2 + 4, vacc2x4567);
176 c2 = (float*) ((uintptr_t) c2 + cn_stride);
177 _mm_storeu_ps(c1, vacc1x0123);
178 _mm_storeu_ps(c1 + 4, vacc1x4567);
179 c1 = (float*) ((uintptr_t) c1 + cn_stride);
180 _mm_storeu_ps(c0, vacc0x0123);
181 _mm_storeu_ps(c0 + 4, vacc0x4567);
182 c0 = (float*) ((uintptr_t) c0 + cn_stride);
183
184 a2 = (const float*) ((uintptr_t) a2 - kc);
185 a1 = (const float*) ((uintptr_t) a1 - kc);
186 a0 = (const float*) ((uintptr_t) a0 - kc);
187
188 nc -= 8;
189 } else {
190 if (nc & 4) {
191 _mm_storeu_ps(c2, vacc2x0123);
192 _mm_storeu_ps(c1, vacc1x0123);
193 _mm_storeu_ps(c0, vacc0x0123);
194
195 vacc2x0123 = vacc2x4567;
196 vacc1x0123 = vacc1x4567;
197 vacc0x0123 = vacc0x4567;
198
199 c2 += 4;
200 c1 += 4;
201 c0 += 4;
202 }
203 if (nc & 2) {
204 _mm_storel_pi((__m64*) c2, vacc2x0123);
205 _mm_storel_pi((__m64*) c1, vacc1x0123);
206 _mm_storel_pi((__m64*) c0, vacc0x0123);
207
208 vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
209 vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
210 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
211
212 c2 += 2;
213 c1 += 2;
214 c0 += 2;
215 }
216 if (nc & 1) {
217 _mm_store_ss(c2, vacc2x0123);
218 _mm_store_ss(c1, vacc1x0123);
219 _mm_store_ss(c0, vacc0x0123);
220 }
221
222 nc = 0;
223 }
224 } while (nc != 0);
225 }
226