• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_16x1__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_16x1__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 - 16 * sizeof(float);
35   while XNN_LIKELY(mc >= 16 * 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       __m128 vacc89AB = vacc0123;
45       __m128 vaccCDEF = vacc0123;
46       if XNN_LIKELY(nnz != 0) {
47         do {
48           const intptr_t diff = *dmap++;
49           const __m128 vi0123 = _mm_loadu_ps(input);
50           const __m128 vi4567 = _mm_loadu_ps(input + 4);
51           const __m128 vi89AB = _mm_loadu_ps(input + 8);
52           const __m128 viCDEF = _mm_loadu_ps(input + 12);
53           input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
54           const __m128 vw = _mm_load1_ps(w); w += 1;
55           vacc0123 = _mm_add_ps(vacc0123, _mm_mul_ps(vi0123, vw));
56           vacc4567 = _mm_add_ps(vacc4567, _mm_mul_ps(vi4567, vw));
57           vacc89AB = _mm_add_ps(vacc89AB, _mm_mul_ps(vi89AB, vw));
58           vaccCDEF = _mm_add_ps(vaccCDEF, _mm_mul_ps(viCDEF, vw));
59         } while (--nnz != 0);
60       }
61       __m128 vout0123 = _mm_min_ps(vacc0123, vmax);
62       __m128 vout4567 = _mm_min_ps(vacc4567, vmax);
63       __m128 vout89AB = _mm_min_ps(vacc89AB, vmax);
64       __m128 voutCDEF = _mm_min_ps(vaccCDEF, vmax);
65       vout0123 = _mm_max_ps(vout0123, vmin);
66       vout4567 = _mm_max_ps(vout4567, vmin);
67       vout89AB = _mm_max_ps(vout89AB, vmin);
68       voutCDEF = _mm_max_ps(voutCDEF, vmin);
69       _mm_storeu_ps(output, vout0123);
70       _mm_storeu_ps(output + 4, vout4567);
71       _mm_storeu_ps(output + 8, vout89AB);
72       _mm_storeu_ps(output + 12, voutCDEF);
73       output = (float*restrict) ((uintptr_t) output + output_stride);
74     } while (--n != 0);
75     output = (float*restrict) ((uintptr_t) output - output_decrement);
76     input += 16;
77     mc -= 16 * sizeof(float);
78   }
79   if XNN_UNLIKELY(mc != 0) {
80     output_decrement += 8 * sizeof(float);
81     if (mc & (8 * sizeof(float))) {
82       const float*restrict w = weights;
83       const int32_t* dmap = widx_dmap;
84       const uint32_t* nnzmap = nidx_nnzmap;
85       size_t n = nc;
86       do {
87         uint32_t nnz = *nnzmap++;
88         __m128 vacc0123 = _mm_load1_ps(w); w += 1;
89         __m128 vacc4567 = vacc0123;
90         if XNN_LIKELY(nnz != 0) {
91           do {
92             const intptr_t diff = *dmap++;
93             const __m128 vi0123 = _mm_loadu_ps(input);
94             const __m128 vi4567 = _mm_loadu_ps(input + 4);
95             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
96             const __m128 vw = _mm_load1_ps(w); w += 1;
97             vacc0123 = _mm_add_ps(vacc0123, _mm_mul_ps(vi0123, vw));
98             vacc4567 = _mm_add_ps(vacc4567, _mm_mul_ps(vi4567, vw));
99           } while (--nnz != 0);
100         }
101         __m128 vout0123 = _mm_min_ps(vacc0123, vmax);
102         __m128 vout4567 = _mm_min_ps(vacc4567, vmax);
103         vout0123 = _mm_max_ps(vout0123, vmin);
104         vout4567 = _mm_max_ps(vout4567, vmin);
105         _mm_storeu_ps(output, vout0123);
106         _mm_storeu_ps(output + 4, vout4567);
107         output = (float*restrict) ((uintptr_t) output + output_stride);
108       } while (--n != 0);
109       output = (float*restrict) ((uintptr_t) output - output_decrement);
110       input += 8;
111     }
112     output_decrement += 4 * sizeof(float);
113     if (mc & (4 * sizeof(float))) {
114       const float*restrict w = weights;
115       const int32_t* dmap = widx_dmap;
116       const uint32_t* nnzmap = nidx_nnzmap;
117       size_t n = nc;
118       do {
119         uint32_t nnz = *nnzmap++;
120         __m128 vacc0123 = _mm_load1_ps(w); w += 1;
121         if XNN_LIKELY(nnz != 0) {
122           do {
123             const intptr_t diff = *dmap++;
124             const __m128 vi0123 = _mm_loadu_ps(input);
125             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
126             const __m128 vw = _mm_load1_ps(w); w += 1;
127             vacc0123 = _mm_add_ps(vacc0123, _mm_mul_ps(vi0123, vw));
128           } while (--nnz != 0);
129         }
130         __m128 vout0123 = _mm_min_ps(vacc0123, vmax);
131         vout0123 = _mm_max_ps(vout0123, vmin);
132         _mm_storeu_ps(output, vout0123);
133         output = (float*restrict) ((uintptr_t) output + output_stride);
134       } while (--n != 0);
135       output = (float*restrict) ((uintptr_t) output - output_decrement);
136       input += 4;
137     }
138     output_decrement += 2 * sizeof(float);
139     if (mc & (2 * sizeof(float))) {
140       const float*restrict w = weights;
141       const int32_t* dmap = widx_dmap;
142       const uint32_t* nnzmap = nidx_nnzmap;
143       size_t n = nc;
144       do {
145         uint32_t nnz = *nnzmap++;
146         __m128 vacc01 = _mm_load_ss(w); w += 1;
147         vacc01 = _mm_unpacklo_ps(vacc01, vacc01);
148         if XNN_LIKELY(nnz != 0) {
149           do {
150             const intptr_t diff = *dmap++;
151             const __m128 vi01 = _mm_loadl_pi(_mm_undefined_ps(), (const __m64*) input);
152             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
153             __m128 vw = _mm_load_ss(w); w += 1;
154             vw = _mm_unpacklo_ps(vw, vw);
155             vacc01 = _mm_add_ps(vacc01, _mm_mul_ps(vi01, vw));
156           } while (--nnz != 0);
157         }
158         __m128 vout01 = _mm_min_ps(vacc01, vmax);
159         vout01 = _mm_max_ps(vout01, vmin);
160         _mm_storel_pi((__m64*) output, vout01);
161         output = (float*restrict) ((uintptr_t) output + output_stride);
162       } while (--n != 0);
163       output = (float*restrict) ((uintptr_t) output - output_decrement);
164       input += 2;
165     }
166     output_decrement += 1 * sizeof(float);
167     if (mc & (1 * sizeof(float))) {
168       const float*restrict w = weights;
169       const int32_t* dmap = widx_dmap;
170       const uint32_t* nnzmap = nidx_nnzmap;
171       size_t n = nc;
172       do {
173         uint32_t nnz = *nnzmap++;
174         __m128 vacc0 = _mm_load_ss(w); w += 1;
175         if XNN_LIKELY(nnz != 0) {
176           do {
177             const intptr_t diff = *dmap++;
178             const __m128 vi0 = _mm_load_ss(input);
179             input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff);
180             const __m128 vw = _mm_load_ss(w); w += 1;
181             vacc0 = _mm_add_ss(vacc0, _mm_mul_ss(vi0, vw));
182           } while (--nnz != 0);
183         }
184         __m128 vout0 = _mm_min_ss(vacc0, vmax);
185         vout0 = _mm_max_ss(vout0, vmin);
186         _mm_store_ss(output, vout0);
187         output = (float*restrict) ((uintptr_t) output + output_stride);
188       } while (--n != 0);
189       output = (float*restrict) ((uintptr_t) output - output_decrement);
190       input += 1;
191     }
192   }
193 }
194