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_gemminc_minmax_ukernel_3x8__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 float * restrict acc,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemminc_minmax_ukernel_3x8__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 float*restrict acc,
28     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(mr != 0);
31   assert(mr <= 3);
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   const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
43   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44   if XNN_UNPREDICTABLE(mr < 2) {
45     a1 = a0;
46     c1 = c0;
47   }
48   const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
49   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50   if XNN_UNPREDICTABLE(mr <= 2) {
51     a2 = a1;
52     c2 = c1;
53   }
54 
55   do {
56     __m128 vacc0x0123 = _mm_load_ps(acc + 0);
57     __m128 vacc0x4567 = _mm_load_ps(acc + 4);
58     __m128 vacc1x0123 = _mm_load_ps(acc + 8);
59     __m128 vacc1x4567 = _mm_load_ps(acc + 12);
60     __m128 vacc2x0123 = _mm_load_ps(acc + 16);
61     __m128 vacc2x4567 = _mm_load_ps(acc + 20);
62     acc += 24;
63 
64     size_t k = kc;
65     do {
66       const __m128 va0 = _mm_load1_ps(a0);
67       a0 += 1;
68       const __m128 va1 = _mm_load1_ps(a1);
69       a1 += 1;
70       const __m128 va2 = _mm_load1_ps(a2);
71       a2 += 1;
72 
73       const __m128 vb0123 = _mm_load_ps(w);
74       const __m128 vb4567 = _mm_load_ps(w + 4);
75       w += 8;
76 
77       vacc0x0123 = _mm_add_ps(vacc0x0123, _mm_mul_ps(va0, vb0123));
78       vacc1x0123 = _mm_add_ps(vacc1x0123, _mm_mul_ps(va1, vb0123));
79       vacc2x0123 = _mm_add_ps(vacc2x0123, _mm_mul_ps(va2, vb0123));
80       vacc0x4567 = _mm_add_ps(vacc0x4567, _mm_mul_ps(va0, vb4567));
81       vacc1x4567 = _mm_add_ps(vacc1x4567, _mm_mul_ps(va1, vb4567));
82       vacc2x4567 = _mm_add_ps(vacc2x4567, _mm_mul_ps(va2, vb4567));
83 
84       k -= sizeof(float);
85     } while (k != 0);
86 
87     const __m128 vmax = _mm_load_ps(params->sse.max);
88     vacc0x0123 = _mm_min_ps(vacc0x0123, vmax);
89     vacc1x0123 = _mm_min_ps(vacc1x0123, vmax);
90     vacc2x0123 = _mm_min_ps(vacc2x0123, vmax);
91     vacc0x4567 = _mm_min_ps(vacc0x4567, vmax);
92     vacc1x4567 = _mm_min_ps(vacc1x4567, vmax);
93     vacc2x4567 = _mm_min_ps(vacc2x4567, vmax);
94 
95     const __m128 vmin = _mm_load_ps(params->sse.min);
96     vacc0x0123 = _mm_max_ps(vacc0x0123, vmin);
97     vacc1x0123 = _mm_max_ps(vacc1x0123, vmin);
98     vacc2x0123 = _mm_max_ps(vacc2x0123, vmin);
99     vacc0x4567 = _mm_max_ps(vacc0x4567, vmin);
100     vacc1x4567 = _mm_max_ps(vacc1x4567, vmin);
101     vacc2x4567 = _mm_max_ps(vacc2x4567, vmin);
102 
103     if XNN_LIKELY(nc >= 8) {
104       _mm_storeu_ps(c2, vacc2x0123);
105       _mm_storeu_ps(c2 + 4, vacc2x4567);
106       c2 = (float*) ((uintptr_t) c2 + cn_stride);
107       _mm_storeu_ps(c1, vacc1x0123);
108       _mm_storeu_ps(c1 + 4, vacc1x4567);
109       c1 = (float*) ((uintptr_t) c1 + cn_stride);
110       _mm_storeu_ps(c0, vacc0x0123);
111       _mm_storeu_ps(c0 + 4, vacc0x4567);
112       c0 = (float*) ((uintptr_t) c0 + cn_stride);
113 
114       a2 = (const float*) ((uintptr_t) a2 - kc);
115       a1 = (const float*) ((uintptr_t) a1 - kc);
116       a0 = (const float*) ((uintptr_t) a0 - kc);
117 
118       nc -= 8;
119     } else {
120       if (nc & 4) {
121         _mm_storeu_ps(c2, vacc2x0123);
122         _mm_storeu_ps(c1, vacc1x0123);
123         _mm_storeu_ps(c0, vacc0x0123);
124 
125         vacc2x0123 = vacc2x4567;
126         vacc1x0123 = vacc1x4567;
127         vacc0x0123 = vacc0x4567;
128 
129         c2 += 4;
130         c1 += 4;
131         c0 += 4;
132       }
133       if (nc & 2) {
134         _mm_storel_pi((__m64*) c2, vacc2x0123);
135         _mm_storel_pi((__m64*) c1, vacc1x0123);
136         _mm_storel_pi((__m64*) c0, vacc0x0123);
137 
138         vacc2x0123 = _mm_movehl_ps(vacc2x0123, vacc2x0123);
139         vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
140         vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
141 
142         c2 += 2;
143         c1 += 2;
144         c0 += 2;
145       }
146       if (nc & 1) {
147         _mm_store_ss(c2, vacc2x0123);
148         _mm_store_ss(c1, vacc1x0123);
149         _mm_store_ss(c0, vacc0x0123);
150       }
151 
152       nc = 0;
153     }
154   } while (nc != 0);
155 }
156