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 <emmintrin.h>
13
14 #include <xnnpack/igemm.h>
15
16
xnn_f32_igemm_minmax_ukernel_1x8__sse2_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_1x8__sse2_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 <= 1);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(kc % sizeof(float) == 0);
36 assert(ks != 0);
37 assert(ks % (1 * 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
45 do {
46 __m128 vacc0x0123 = _mm_load_ps(w);
47 __m128 vacc0x4567 = _mm_load_ps(w + 4);
48 w += 8;
49
50 size_t p = ks;
51 do {
52 const float* restrict a0 = a[0];
53 assert(a0 != NULL);
54 if XNN_UNPREDICTABLE(a0 != zero) {
55 a0 = (const float*) ((uintptr_t) a0 + a_offset);
56 }
57 a += 1;
58
59 size_t k = kc;
60 while (k >= 4 * sizeof(float)) {
61 const __m128 va0 = _mm_loadu_ps(a0);
62 a0 += 4;
63
64
65 const __m128 va0c0000 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va0), _MM_SHUFFLE(0, 0, 0, 0)));
66
67 const __m128 vb0123c0 = _mm_load_ps(w + 0);
68 const __m128 vb4567c0 = _mm_load_ps(w + 4);
69
70 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c0000, vb0123c0));
71 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c0000, vb4567c0));
72
73 const __m128 va0c1111 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va0), _MM_SHUFFLE(1, 1, 1, 1)));
74
75 const __m128 vb0123c1 = _mm_load_ps(w + 8);
76 const __m128 vb4567c1 = _mm_load_ps(w + 12);
77
78 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c1111, vb0123c1));
79 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c1111, vb4567c1));
80
81 const __m128 va0c2222 = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(va0), _MM_SHUFFLE(2, 2, 2, 2)));
82
83 const __m128 vb0123c2 = _mm_load_ps(w + 16);
84 const __m128 vb4567c2 = _mm_load_ps(w + 20);
85
86 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c2222, vb0123c2));
87 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c2222, vb4567c2));
88
89 const __m128 va0c3333 = _mm_shuffle_ps(va0, va0, _MM_SHUFFLE(3, 3, 3, 3));
90
91 const __m128 vb0123c3 = _mm_load_ps(w + 24);
92 const __m128 vb4567c3 = _mm_load_ps(w + 28);
93
94 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0c3333, vb0123c3));
95 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0c3333, vb4567c3));
96
97 w += 32;
98 k -= 4 * sizeof(float);
99 }
100 if XNN_UNLIKELY(k != 0) {
101 do {
102 const __m128 vb0123 = _mm_load_ps(w);
103 const __m128 vb4567 = _mm_load_ps(w + 4);
104 w += 8;
105
106 const __m128 va0 = _mm_load1_ps(a0);
107 a0 += 1;
108
109 vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
110 vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
111 k -= sizeof(float);
112 } while (k != 0);
113 }
114 p -= 1 * sizeof(void*);
115 } while (p != 0);
116
117 const __m128 vmax = _mm_load_ps(params->sse.max);
118 vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
119 vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
120
121 const __m128 vmin = _mm_load_ps(params->sse.min);
122 vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
123 vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
124
125 if XNN_LIKELY(nc >= 8) {
126 _mm_storeu_ps(c0, vacc0x0123);
127 _mm_storeu_ps(c0 + 4, vacc0x4567);
128 c0 = (float*) ((uintptr_t) c0 + cn_stride);
129
130 a = (const float**restrict) ((uintptr_t) a - ks);
131 nc -= 8;
132 } else {
133 if (nc & 4) {
134 _mm_storeu_ps(c0, vacc0x0123);
135
136 vacc0x0123 = vacc0x4567;
137
138 c0 += 4;
139 }
140 if (nc & 2) {
141 _mm_storel_pi((__m64*) c0, vacc0x0123);
142
143 vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
144
145 c0 += 2;
146 }
147 if (nc & 1) {
148 _mm_store_ss(c0, vacc0x0123);
149 }
150
151 nc = 0;
152 }
153 } while (nc != 0);
154 }
155