1 // Auto-generated file. Do not edit!
2 // Template: src/f32-igemm/sse-load1.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/igemm.h>
15
16
xnn_f32_igemm_minmax_ukernel_4x8__sse_load1(size_t mr,size_t nc,size_t kc,size_t ks,const float ** restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const float * zero,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_igemm_minmax_ukernel_4x8__sse_load1(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const float**restrict a,
23 const float*restrict w,
24 float*restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const float* zero,
29 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31 assert(mr != 0);
32 assert(mr <= 4);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(kc % sizeof(float) == 0);
36 assert(ks != 0);
37 assert(ks % (4 * sizeof(void*)) == 0);
38 assert(a_offset % sizeof(float) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 float* c0 = c;
44 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr < 2) {
46 c1 = c0;
47 }
48 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
49 if XNN_UNPREDICTABLE(mr <= 2) {
50 c2 = c1;
51 }
52 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
53 if XNN_UNPREDICTABLE(mr != 4) {
54 c3 = c2;
55 }
56
57 do {
58 __m128 vacc0x0123 = _mm_load_ps(w);
59 __m128 vacc0x4567 = _mm_load_ps(w + 4);
60 __m128 vacc1x0123 = vacc0x0123;
61 __m128 vacc1x4567 = vacc0x4567;
62 __m128 vacc2x0123 = vacc0x0123;
63 __m128 vacc2x4567 = vacc0x4567;
64 __m128 vacc3x0123 = vacc0x0123;
65 __m128 vacc3x4567 = vacc0x4567;
66 w += 8;
67
68 size_t p = ks;
69 do {
70 const float* restrict a0 = a[0];
71 assert(a0 != NULL);
72 if XNN_UNPREDICTABLE(a0 != zero) {
73 a0 = (const float*) ((uintptr_t) a0 + a_offset);
74 }
75 const float* restrict a1 = a[1];
76 assert(a1 != NULL);
77 if XNN_UNPREDICTABLE(a1 != zero) {
78 a1 = (const float*) ((uintptr_t) a1 + a_offset);
79 }
80 const float* restrict a2 = a[2];
81 assert(a2 != NULL);
82 if XNN_UNPREDICTABLE(a2 != zero) {
83 a2 = (const float*) ((uintptr_t) a2 + a_offset);
84 }
85 const float* restrict a3 = a[3];
86 assert(a3 != NULL);
87 if XNN_UNPREDICTABLE(a3 != zero) {
88 a3 = (const float*) ((uintptr_t) a3 + a_offset);
89 }
90 a += 4;
91
92 size_t k = kc;
93 do {
94 const __m128 vb0123 = _mm_load_ps(w);
95 const __m128 vb4567 = _mm_load_ps(w + 4);
96 w += 8;
97
98 const __m128 va0 = _mm_load1_ps(a0);
99 a0 += 1;
100 const __m128 va1 = _mm_load1_ps(a1);
101 a1 += 1;
102 const __m128 va2 = _mm_load1_ps(a2);
103 a2 += 1;
104 const __m128 va3 = _mm_load1_ps(a3);
105 a3 += 1;
106
107 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
108 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
109 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1, vb0123));
110 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1, vb4567));
111 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2, vb0123));
112 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2, vb4567));
113 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3, vb0123));
114 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3, vb4567));
115 k -= sizeof(float);
116 } while (k != 0);
117 p -= 4 * sizeof(void*);
118 } while (p != 0);
119
120 const __m128 vmax = _mm_load_ps(params->sse.max);
121 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
122 vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
123 vacc2x0123 = _mm_min_ps(vacc2x0123, vmax);
124 vacc3x0123 = _mm_min_ps(vacc3x0123, vmax);
125 vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
126 vacc1x4567 = _mm_min_ps(vacc1x4567, vmax);
127 vacc2x4567 = _mm_min_ps(vacc2x4567, vmax);
128 vacc3x4567 = _mm_min_ps(vacc3x4567, vmax);
129
130 const __m128 vmin = _mm_load_ps(params->sse.min);
131 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
132 vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
133 vacc2x0123 = _mm_max_ps(vacc2x0123, vmin);
134 vacc3x0123 = _mm_max_ps(vacc3x0123, vmin);
135 vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
136 vacc1x4567 = _mm_max_ps(vacc1x4567, vmin);
137 vacc2x4567 = _mm_max_ps(vacc2x4567, vmin);
138 vacc3x4567 = _mm_max_ps(vacc3x4567, vmin);
139
140 if XNN_LIKELY(nc >= 8) {
141 _mm_storeu_ps(c3, vacc3x0123);
142 _mm_storeu_ps(c3 + 4, vacc3x4567);
143 c3 = (float*) ((uintptr_t) c3 + cn_stride);
144 _mm_storeu_ps(c2, vacc2x0123);
145 _mm_storeu_ps(c2 + 4, vacc2x4567);
146 c2 = (float*) ((uintptr_t) c2 + cn_stride);
147 _mm_storeu_ps(c1, vacc1x0123);
148 _mm_storeu_ps(c1 + 4, vacc1x4567);
149 c1 = (float*) ((uintptr_t) c1 + cn_stride);
150 _mm_storeu_ps(c0, vacc0x0123);
151 _mm_storeu_ps(c0 + 4, vacc0x4567);
152 c0 = (float*) ((uintptr_t) c0 + cn_stride);
153
154 a = (const float**restrict) ((uintptr_t) a - ks);
155 nc -= 8;
156 } else {
157 if (nc & 4) {
158 _mm_storeu_ps(c3, vacc3x0123);
159 _mm_storeu_ps(c2, vacc2x0123);
160 _mm_storeu_ps(c1, vacc1x0123);
161 _mm_storeu_ps(c0, vacc0x0123);
162
163 vacc3x0123 = vacc3x4567;
164 vacc2x0123 = vacc2x4567;
165 vacc1x0123 = vacc1x4567;
166 vacc0x0123 = vacc0x4567;
167
168 c3 += 4;
169 c2 += 4;
170 c1 += 4;
171 c0 += 4;
172 }
173 if (nc & 2) {
174 _mm_storel_pi((__m64*) c3, vacc3x0123);
175 _mm_storel_pi((__m64*) c2, vacc2x0123);
176 _mm_storel_pi((__m64*) c1, vacc1x0123);
177 _mm_storel_pi((__m64*) c0, vacc0x0123);
178
179 vacc3x0123 = _mm_movehl_ps(vacc3x0123, vacc3x0123);
180 vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
181 vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
182 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
183
184 c3 += 2;
185 c2 += 2;
186 c1 += 2;
187 c0 += 2;
188 }
189 if (nc & 1) {
190 _mm_store_ss(c3, vacc3x0123);
191 _mm_store_ss(c2, vacc2x0123);
192 _mm_store_ss(c1, vacc1x0123);
193 _mm_store_ss(c0, vacc0x0123);
194 }
195
196 nc = 0;
197 }
198 } while (nc != 0);
199 }
200