1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/sse-shuffle.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_1x8s4__sse(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_1x8s4__sse(
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)]) XNN_OOB_READS
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 __m128 vacc0x0123 = _mm_load_ps(acc + 0);
45 __m128 vacc0x4567 = _mm_load_ps(acc + 4);
46 acc += 8;
47
48 size_t k = kc;
49 while (k >= 4 * sizeof(float)) {
50 __m128 va0 = _mm_loadu_ps(a0);
51 a0 += 4;
52
53
54 const __m128 vb0123c0 = _mm_load_ps(w + 0);
55 const __m128 vb4567c0 = _mm_load_ps(w + 4);
56
57 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123c0));
58 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567c0));
59
60 va0 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 3, 2, 1));
61
62 const __m128 vb0123c1 = _mm_load_ps(w + 8);
63 const __m128 vb4567c1 = _mm_load_ps(w + 12);
64
65 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123c1));
66 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567c1));
67
68 va0 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 3, 2, 1));
69
70 const __m128 vb0123c2 = _mm_load_ps(w + 16);
71 const __m128 vb4567c2 = _mm_load_ps(w + 20);
72
73 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123c2));
74 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567c2));
75
76 va0 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 3, 2, 1));
77
78 const __m128 vb0123c3 = _mm_load_ps(w + 24);
79 const __m128 vb4567c3 = _mm_load_ps(w + 28);
80
81 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123c3));
82 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567c3));
83
84
85 w += 32;
86 k -= 4 * sizeof(float);
87 }
88 if XNN_UNLIKELY(k != 0) {
89 __m128 va0 = _mm_loadu_ps(a0);
90 a0 = (const float*) ((uintptr_t) a0 + k);
91
92
93 const __m128 vb0123c0 = _mm_load_ps(w + 0);
94 const __m128 vb4567c0 = _mm_load_ps(w + 4);
95
96 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb0123c0), va0), vb0123c0));
97 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb4567c0), va0), vb4567c0));
98
99 va0 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 3, 2, 1));
100
101 const __m128 vb0123c1 = _mm_load_ps(w + 8);
102 const __m128 vb4567c1 = _mm_load_ps(w + 12);
103
104 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb0123c1), va0), vb0123c1));
105 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb4567c1), va0), vb4567c1));
106
107 va0 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 3, 2, 1));
108
109 const __m128 vb0123c2 = _mm_load_ps(w + 16);
110 const __m128 vb4567c2 = _mm_load_ps(w + 20);
111
112 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb0123c2), va0), vb0123c2));
113 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb4567c2), va0), vb4567c2));
114
115 va0 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 3, 2, 1));
116
117 const __m128 vb0123c3 = _mm_load_ps(w + 24);
118 const __m128 vb4567c3 = _mm_load_ps(w + 28);
119
120 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb0123c3), va0), vb0123c3));
121 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(_mm_andnot_ps(_mm_cmpeq_ps(_mm_setzero_ps(), vb4567c3), va0), vb4567c3));
122
123
124 w += 32;
125 }
126
127 const __m128 vmax = _mm_load_ps(params->sse.max);
128 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
129 vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
130
131 const __m128 vmin = _mm_load_ps(params->sse.min);
132 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
133 vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
134
135 if XNN_LIKELY(nc >= 8) {
136 _mm_storeu_ps(c0, vacc0x0123);
137 _mm_storeu_ps(c0 + 4, vacc0x4567);
138 c0 = (float*) ((uintptr_t) c0 + cn_stride);
139
140 a0 = (const float*) ((uintptr_t) a0 - kc);
141
142 nc -= 8;
143 } else {
144 if (nc & 4) {
145 _mm_storeu_ps(c0, vacc0x0123);
146
147 vacc0x0123 = vacc0x4567;
148
149 c0 += 4;
150 }
151 if (nc & 2) {
152 _mm_storel_pi((__m64*) c0, vacc0x0123);
153
154 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
155
156 c0 += 2;
157 }
158 if (nc & 1) {
159 _mm_store_ss(c0, vacc0x0123);
160 }
161
162 nc = 0;
163 }
164 } while (nc != 0);
165 }
166