1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/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/gemm.h>
15
16
xnn_f32_gemm_minmax_ukernel_4x8__sse_load1(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_4x8__sse_load1(
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 __m128 vacc0x0123 = _mm_load_ps(w + 0);
61 __m128 vacc0x4567 = _mm_load_ps(w + 4);
62 __m128 vacc1x0123 = vacc0x0123;
63 __m128 vacc1x4567 = vacc0x4567;
64 __m128 vacc2x0123 = vacc0x0123;
65 __m128 vacc2x4567 = vacc0x4567;
66 __m128 vacc3x0123 = vacc0x0123;
67 __m128 vacc3x4567 = vacc0x4567;
68 w += 8;
69
70 size_t k = kc;
71 do {
72 const __m128 va0 = _mm_load1_ps(a0);
73 a0 += 1;
74 const __m128 va1 = _mm_load1_ps(a1);
75 a1 += 1;
76 const __m128 va2 = _mm_load1_ps(a2);
77 a2 += 1;
78 const __m128 va3 = _mm_load1_ps(a3);
79 a3 += 1;
80
81 const __m128 vb0123 = _mm_load_ps(w);
82 const __m128 vb4567 = _mm_load_ps(w + 4);
83 w += 8;
84
85 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
86 vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1, vb0123));
87 vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2, vb0123));
88 vacc3x0123 = _mm_add_ps(vacc3x0123, _mm_mul_ps(va3, vb0123));
89 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
90 vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1, vb4567));
91 vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2, vb4567));
92 vacc3x4567 = _mm_add_ps(vacc3x4567, _mm_mul_ps(va3, vb4567));
93
94 k -= sizeof(float);
95 } while (k != 0);
96
97 const __m128 vmax = _mm_load_ps(params->sse.max);
98 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
99 vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
100 vacc2x0123 = _mm_min_ps(vacc2x0123, vmax);
101 vacc3x0123 = _mm_min_ps(vacc3x0123, vmax);
102 vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
103 vacc1x4567 = _mm_min_ps(vacc1x4567, vmax);
104 vacc2x4567 = _mm_min_ps(vacc2x4567, vmax);
105 vacc3x4567 = _mm_min_ps(vacc3x4567, vmax);
106
107 const __m128 vmin = _mm_load_ps(params->sse.min);
108 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
109 vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
110 vacc2x0123 = _mm_max_ps(vacc2x0123, vmin);
111 vacc3x0123 = _mm_max_ps(vacc3x0123, vmin);
112 vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
113 vacc1x4567 = _mm_max_ps(vacc1x4567, vmin);
114 vacc2x4567 = _mm_max_ps(vacc2x4567, vmin);
115 vacc3x4567 = _mm_max_ps(vacc3x4567, vmin);
116
117 if XNN_LIKELY(nc >= 8) {
118 _mm_storeu_ps(c3, vacc3x0123);
119 _mm_storeu_ps(c3 + 4, vacc3x4567);
120 c3 = (float*) ((uintptr_t) c3 + cn_stride);
121 _mm_storeu_ps(c2, vacc2x0123);
122 _mm_storeu_ps(c2 + 4, vacc2x4567);
123 c2 = (float*) ((uintptr_t) c2 + cn_stride);
124 _mm_storeu_ps(c1, vacc1x0123);
125 _mm_storeu_ps(c1 + 4, vacc1x4567);
126 c1 = (float*) ((uintptr_t) c1 + cn_stride);
127 _mm_storeu_ps(c0, vacc0x0123);
128 _mm_storeu_ps(c0 + 4, vacc0x4567);
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 -= 8;
137 } else {
138 if (nc & 4) {
139 _mm_storeu_ps(c3, vacc3x0123);
140 _mm_storeu_ps(c2, vacc2x0123);
141 _mm_storeu_ps(c1, vacc1x0123);
142 _mm_storeu_ps(c0, vacc0x0123);
143
144 vacc3x0123 = vacc3x4567;
145 vacc2x0123 = vacc2x4567;
146 vacc1x0123 = vacc1x4567;
147 vacc0x0123 = vacc0x4567;
148
149 c3 += 4;
150 c2 += 4;
151 c1 += 4;
152 c0 += 4;
153 }
154 if (nc & 2) {
155 _mm_storel_pi((__m64*) c3, vacc3x0123);
156 _mm_storel_pi((__m64*) c2, vacc2x0123);
157 _mm_storel_pi((__m64*) c1, vacc1x0123);
158 _mm_storel_pi((__m64*) c0, vacc0x0123);
159
160 vacc3x0123 = _mm_movehl_ps(vacc3x0123, vacc3x0123);
161 vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
162 vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
163 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
164
165 c3 += 2;
166 c2 += 2;
167 c1 += 2;
168 c0 += 2;
169 }
170 if (nc & 1) {
171 _mm_store_ss(c3, vacc3x0123);
172 _mm_store_ss(c2, vacc2x0123);
173 _mm_store_ss(c1, vacc1x0123);
174 _mm_store_ss(c0, vacc0x0123);
175 }
176
177 nc = 0;
178 }
179 } while (nc != 0);
180 }
181