1 // Auto-generated file. Do not edit!
2 // Template: src/f32-spmm/sse.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 <immintrin.h>
13
14 #include <xnnpack/spmm.h>
15
16
xnn_f32_spmm_minmax_ukernel_8x1__sse(size_t mc,size_t nc,const float * restrict input,const float * restrict weights,const int32_t * restrict widx_dmap,const uint32_t * restrict nidx_nnzmap,float * restrict output,size_t output_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_spmm_minmax_ukernel_8x1__sse(
18 size_t mc,
19 size_t nc,
20 const float*restrict input,
21 const float*restrict weights,
22 const int32_t*restrict widx_dmap,
23 const uint32_t*restrict nidx_nnzmap,
24 float*restrict output,
25 size_t output_stride,
26 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
27 {
28 assert(mc != 0);
29 assert(mc % sizeof(float) == 0);
30 assert(nc != 0);
31
32 const __m128 vmin = _mm_load_ps(params->sse.min);
33 const __m128 vmax = _mm_load_ps(params->sse.max);
34 size_t output_decrement = output_stride * nc - 8 * sizeof(float);
35 while XNN_LIKELY(mc >= 8 * sizeof(float)) {
36 const float*restrict w = weights;
37 const int32_t* dmap = widx_dmap;
38 const uint32_t* nnzmap = nidx_nnzmap;
39 size_t n = nc;
40 do {
41 uint32_t nnz = *nnzmap++;
42 __m128 vacc0123 = _mm_load1_ps(w); w += 1;
43 __m128 vacc4567 = vacc0123;
44 if XNN_LIKELY(nnz != 0) {
45 do {
46 const intptr_t diff = *dmap++;
47 const __m128 vi0123 = _mm_loadu_ps(input);
48 const __m128 vi4567 = _mm_loadu_ps(input + 4);
49 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
50 const __m128 vw = _mm_load1_ps(w); w += 1;
51 vacc0123 = _mm_add_ps(vacc0123, _mm_mul_ps(vi0123, vw));
52 vacc4567 = _mm_add_ps(vacc4567, _mm_mul_ps(vi4567, vw));
53 } while (--nnz != 0);
54 }
55 __m128 vout0123 = _mm_min_ps(vacc0123, vmax);
56 __m128 vout4567 = _mm_min_ps(vacc4567, vmax);
57 vout0123 = _mm_max_ps(vout0123, vmin);
58 vout4567 = _mm_max_ps(vout4567, vmin);
59 _mm_storeu_ps(output, vout0123);
60 _mm_storeu_ps(output + 4, vout4567);
61 output = (float*restrict) ((uintptr_t) output + output_stride);
62 } while (--n != 0);
63 output = (float*restrict) ((uintptr_t) output - output_decrement);
64 input += 8;
65 mc -= 8 * sizeof(float);
66 }
67 if XNN_UNLIKELY(mc != 0) {
68 output_decrement += 4 * sizeof(float);
69 if (mc & (4 * sizeof(float))) {
70 const float*restrict w = weights;
71 const int32_t* dmap = widx_dmap;
72 const uint32_t* nnzmap = nidx_nnzmap;
73 size_t n = nc;
74 do {
75 uint32_t nnz = *nnzmap++;
76 __m128 vacc0123 = _mm_load1_ps(w); w += 1;
77 if XNN_LIKELY(nnz != 0) {
78 do {
79 const intptr_t diff = *dmap++;
80 const __m128 vi0123 = _mm_loadu_ps(input);
81 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
82 const __m128 vw = _mm_load1_ps(w); w += 1;
83 vacc0123 = _mm_add_ps(vacc0123, _mm_mul_ps(vi0123, vw));
84 } while (--nnz != 0);
85 }
86 __m128 vout0123 = _mm_min_ps(vacc0123, vmax);
87 vout0123 = _mm_max_ps(vout0123, vmin);
88 _mm_storeu_ps(output, vout0123);
89 output = (float*restrict) ((uintptr_t) output + output_stride);
90 } while (--n != 0);
91 output = (float*restrict) ((uintptr_t) output - output_decrement);
92 input += 4;
93 }
94 output_decrement += 2 * sizeof(float);
95 if (mc & (2 * sizeof(float))) {
96 const float*restrict w = weights;
97 const int32_t* dmap = widx_dmap;
98 const uint32_t* nnzmap = nidx_nnzmap;
99 size_t n = nc;
100 do {
101 uint32_t nnz = *nnzmap++;
102 __m128 vacc01 = _mm_load_ss(w); w += 1;
103 vacc01 = _mm_unpacklo_ps(vacc01, vacc01);
104 if XNN_LIKELY(nnz != 0) {
105 do {
106 const intptr_t diff = *dmap++;
107 const __m128 vi01 = _mm_loadl_pi(_mm_undefined_ps(), (const __m64*) input);
108 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
109 __m128 vw = _mm_load_ss(w); w += 1;
110 vw = _mm_unpacklo_ps(vw, vw);
111 vacc01 = _mm_add_ps(vacc01, _mm_mul_ps(vi01, vw));
112 } while (--nnz != 0);
113 }
114 __m128 vout01 = _mm_min_ps(vacc01, vmax);
115 vout01 = _mm_max_ps(vout01, vmin);
116 _mm_storel_pi((__m64*) output, vout01);
117 output = (float*restrict) ((uintptr_t) output + output_stride);
118 } while (--n != 0);
119 output = (float*restrict) ((uintptr_t) output - output_decrement);
120 input += 2;
121 }
122 output_decrement += 1 * sizeof(float);
123 if (mc & (1 * sizeof(float))) {
124 const float*restrict w = weights;
125 const int32_t* dmap = widx_dmap;
126 const uint32_t* nnzmap = nidx_nnzmap;
127 size_t n = nc;
128 do {
129 uint32_t nnz = *nnzmap++;
130 __m128 vacc0 = _mm_load_ss(w); w += 1;
131 if XNN_LIKELY(nnz != 0) {
132 do {
133 const intptr_t diff = *dmap++;
134 const __m128 vi0 = _mm_load_ss(input);
135 input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
136 const __m128 vw = _mm_load_ss(w); w += 1;
137 vacc0 = _mm_add_ss(vacc0, _mm_mul_ss(vi0, vw));
138 } while (--nnz != 0);
139 }
140 __m128 vout0 = _mm_min_ss(vacc0, vmax);
141 vout0 = _mm_max_ss(vout0, vmin);
142 _mm_store_ss(output, vout0);
143 output = (float*restrict) ((uintptr_t) output + output_stride);
144 } while (--n != 0);
145 output = (float*restrict) ((uintptr_t) output - output_decrement);
146 input += 1;
147 }
148 }
149 }
150