• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-igemm/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/igemm.h>
15 
16 
xnn_f32_igemm_minmax_ukernel_3x8__sse_dup(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_3x8__sse_dup(
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 <= 3);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(kc % sizeof(float) == 0);
36   assert(ks != 0);
37   assert(ks % (3 * 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 
53   do {
54     __m128 vacc0x0123 = _mm_load_ps(w);
55     __m128 vacc0x4567 = _mm_load_ps(w + 4);
56     __m128 vacc1x0123 = vacc0x0123;
57     __m128 vacc1x4567 = vacc0x4567;
58     __m128 vacc2x0123 = vacc0x0123;
59     __m128 vacc2x4567 = vacc0x4567;
60     w += 8;
61 
62     size_t p = ks;
63     do {
64       const float* restrict a0 = a[0];
65       assert(a0 != NULL);
66       if XNN_UNPREDICTABLE(a0 != zero) {
67         a0 = (const float*) ((uintptr_t) a0 + a_offset);
68       }
69       const float* restrict a1 = a[1];
70       assert(a1 != NULL);
71       if XNN_UNPREDICTABLE(a1 != zero) {
72         a1 = (const float*) ((uintptr_t) a1 + a_offset);
73       }
74       const float* restrict a2 = a[2];
75       assert(a2 != NULL);
76       if XNN_UNPREDICTABLE(a2 != zero) {
77         a2 = (const float*) ((uintptr_t) a2 + a_offset);
78       }
79       a += 3;
80 
81       size_t k = kc;
82       while (k >= 4 * sizeof(float)) {
83         const __m128 va0 = _mm_loadu_ps(a0);
84         a0 += 4;
85         const __m128 va1 = _mm_loadu_ps(a1);
86         a1 += 4;
87         const __m128 va2 = _mm_loadu_ps(a2);
88         a2 += 4;
89 
90 
91         const __m128 va0c0000 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(0, 0, 0, 0));
92         const __m128 va1c0000 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(0, 0, 0, 0));
93         const __m128 va2c0000 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(0, 0, 0, 0));
94 
95         const __m128 vb0123c0 = _mm_load_ps(w + 0);
96         const __m128 vb4567c0 = _mm_load_ps(w + 4);
97 
98         vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c0000, vb0123c0));
99         vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c0000, vb0123c0));
100         vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c0000, vb0123c0));
101         vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c0000, vb4567c0));
102         vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c0000, vb4567c0));
103         vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c0000, vb4567c0));
104 
105         const __m128 va0c1111 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(1, 1, 1, 1));
106         const __m128 va1c1111 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(1, 1, 1, 1));
107         const __m128 va2c1111 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(1, 1, 1, 1));
108 
109         const __m128 vb0123c1 = _mm_load_ps(w + 8);
110         const __m128 vb4567c1 = _mm_load_ps(w + 12);
111 
112         vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c1111, vb0123c1));
113         vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c1111, vb0123c1));
114         vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c1111, vb0123c1));
115         vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c1111, vb4567c1));
116         vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c1111, vb4567c1));
117         vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c1111, vb4567c1));
118 
119         const __m128 va0c2222 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(2, 2, 2, 2));
120         const __m128 va1c2222 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(2, 2, 2, 2));
121         const __m128 va2c2222 = _mm_shuffle_ps(va2, va2, _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         vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c2222, vb4567c2));
130         vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c2222, vb4567c2));
131         vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c2222, vb4567c2));
132 
133         const __m128 va0c3333 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(3, 3, 3, 3));
134         const __m128 va1c3333 = _mm_shuffle_ps(va1, va1, _MM_SHUFFLE(3, 3, 3, 3));
135         const __m128 va2c3333 = _mm_shuffle_ps(va2, va2, _MM_SHUFFLE(3, 3, 3, 3));
136 
137         const __m128 vb0123c3 = _mm_load_ps(w + 24);
138         const __m128 vb4567c3 = _mm_load_ps(w + 28);
139 
140         vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c3333, vb0123c3));
141         vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1c3333, vb0123c3));
142         vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2c3333, vb0123c3));
143         vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c3333, vb4567c3));
144         vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1c3333, vb4567c3));
145         vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2c3333, vb4567c3));
146 
147         w += 32;
148         k -= 4 * sizeof(float);
149       }
150       if XNN_UNLIKELY(k != 0) {
151         do {
152           const __m128 vb0123 = _mm_load_ps(w);
153           const __m128 vb4567 = _mm_load_ps(w + 4);
154           w += 8;
155 
156           const __m128 va0 = _mm_load1_ps(a0);
157           a0 += 1;
158           const __m128 va1 = _mm_load1_ps(a1);
159           a1 += 1;
160           const __m128 va2 = _mm_load1_ps(a2);
161           a2 += 1;
162 
163           vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
164           vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
165           vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1, vb0123));
166           vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1, vb4567));
167           vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2, vb0123));
168           vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2, vb4567));
169           k -= sizeof(float);
170         } while (k != 0);
171       }
172       p -= 3 * sizeof(void*);
173     } while (p != 0);
174 
175     const __m128 vmax = _mm_load_ps(params->sse.max);
176     vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
177     vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
178     vacc2x0123 = _mm_min_ps(vacc2x0123, vmax);
179     vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
180     vacc1x4567 = _mm_min_ps(vacc1x4567, vmax);
181     vacc2x4567 = _mm_min_ps(vacc2x4567, vmax);
182 
183     const __m128 vmin = _mm_load_ps(params->sse.min);
184     vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
185     vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
186     vacc2x0123 = _mm_max_ps(vacc2x0123, vmin);
187     vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
188     vacc1x4567 = _mm_max_ps(vacc1x4567, vmin);
189     vacc2x4567 = _mm_max_ps(vacc2x4567, vmin);
190 
191     if XNN_LIKELY(nc >= 8) {
192       _mm_storeu_ps(c2, vacc2x0123);
193       _mm_storeu_ps(c2 + 4, vacc2x4567);
194       c2 = (float*) ((uintptr_t) c2 + cn_stride);
195       _mm_storeu_ps(c1, vacc1x0123);
196       _mm_storeu_ps(c1 + 4, vacc1x4567);
197       c1 = (float*) ((uintptr_t) c1 + cn_stride);
198       _mm_storeu_ps(c0, vacc0x0123);
199       _mm_storeu_ps(c0 + 4, vacc0x4567);
200       c0 = (float*) ((uintptr_t) c0 + cn_stride);
201 
202       a = (const float**restrict) ((uintptr_t) a - ks);
203       nc -= 8;
204     } else {
205       if (nc & 4) {
206         _mm_storeu_ps(c2, vacc2x0123);
207         _mm_storeu_ps(c1, vacc1x0123);
208         _mm_storeu_ps(c0, vacc0x0123);
209 
210         vacc2x0123 = vacc2x4567;
211         vacc1x0123 = vacc1x4567;
212         vacc0x0123 = vacc0x4567;
213 
214         c2 += 4;
215         c1 += 4;
216         c0 += 4;
217       }
218       if (nc & 2) {
219         _mm_storel_pi((__m64*) c2, vacc2x0123);
220         _mm_storel_pi((__m64*) c1, vacc1x0123);
221         _mm_storel_pi((__m64*) c0, vacc0x0123);
222 
223         vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
224         vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
225         vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
226 
227         c2 += 2;
228         c1 += 2;
229         c0 += 2;
230       }
231       if (nc & 1) {
232         _mm_store_ss(c2, vacc2x0123);
233         _mm_store_ss(c1, vacc1x0123);
234         _mm_store_ss(c0, vacc0x0123);
235       }
236 
237       nc = 0;
238     }
239   } while (nc != 0);
240 }
241