• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-prelu/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 <smmintrin.h>
13 
14 #include <xnnpack/math.h>
15 #include <xnnpack/prelu.h>
16 
17 
xnn_f32_prelu_ukernel__sse41_2x8(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride)18 void xnn_f32_prelu_ukernel__sse41_2x8(
19     size_t rows,
20     size_t channels,
21     const float*restrict input,
22     size_t input_stride,
23     const float*restrict weights,
24     float*restrict output,
25     size_t output_stride) XNN_DISABLE_TSAN
26 {
27   assert(rows != 0);
28   assert(channels != 0);
29   assert(channels % sizeof(float) == 0);
30 
31   const float* i0 = input;
32   float* o0 = output;
33   const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
34   float* o1 = (float*) ((uintptr_t) o0 + output_stride);
35   if XNN_UNPREDICTABLE(rows < 2) {
36     i1 = i0;
37     o1 = o0;
38   }
39 
40   const size_t input_increment = input_stride * 2 - channels;
41   const size_t output_increment = output_stride * 2 - channels;
42 
43   do {
44     const float* w = weights;
45     size_t c = channels;
46     for (; c >= 8 * sizeof(float); c -= 8 * sizeof(float)) {
47       const __m128 vw0123 = _mm_load_ps(w);
48       const __m128 vw4567 = _mm_load_ps(w + 4);
49       w += 8;
50 
51       const __m128 vi0x0123 = _mm_loadu_ps(i0);
52       const __m128 vi0x4567 = _mm_loadu_ps(i0 + 4);
53       i0 += 8;
54       const __m128 vi1x0123 = _mm_loadu_ps(i1);
55       const __m128 vi1x4567 = _mm_loadu_ps(i1 + 4);
56       i1 += 8;
57 
58       const __m128 vprod0x0123 = _mm_mul_ps(vi0x0123, vw0123);
59       const __m128 vprod0x4567 = _mm_mul_ps(vi0x4567, vw4567);
60       const __m128 vprod1x0123 = _mm_mul_ps(vi1x0123, vw0123);
61       const __m128 vprod1x4567 = _mm_mul_ps(vi1x4567, vw4567);
62 
63       const __m128 vacc0x0123 = _mm_blendv_ps(vi0x0123, vprod0x0123, vi0x0123);
64       const __m128 vacc0x4567 = _mm_blendv_ps(vi0x4567, vprod0x4567, vi0x4567);
65       const __m128 vacc1x0123 = _mm_blendv_ps(vi1x0123, vprod1x0123, vi1x0123);
66       const __m128 vacc1x4567 = _mm_blendv_ps(vi1x4567, vprod1x4567, vi1x4567);
67 
68       _mm_storeu_ps(o0, vacc0x0123);
69       _mm_storeu_ps(o0 + 4, vacc0x4567);
70       o0 += 8;
71       _mm_storeu_ps(o1, vacc1x0123);
72       _mm_storeu_ps(o1 + 4, vacc1x4567);
73       o1 += 8;
74     }
75     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
76       const __m128 vw0123 = _mm_load_ps(w);
77       w += 4;
78 
79       const __m128 vi0x0123 = _mm_loadu_ps(i0);
80       i0 += 4;
81       const __m128 vi1x0123 = _mm_loadu_ps(i1);
82       i1 += 4;
83 
84       const __m128 vprod0x0123 = _mm_mul_ps(vi0x0123, vw0123);
85       const __m128 vprod1x0123 = _mm_mul_ps(vi1x0123, vw0123);
86 
87       __m128 vacc0x0123 = _mm_blendv_ps(vi0x0123, vprod0x0123, vi0x0123);
88       __m128 vacc1x0123 = _mm_blendv_ps(vi1x0123, vprod1x0123, vi1x0123);
89 
90       _mm_storeu_ps(o0, vacc0x0123);
91       o0 += 4;
92       _mm_storeu_ps(o1, vacc1x0123);
93       o1 += 4;
94     }
95     if XNN_UNLIKELY(c != 0) {
96       const __m128 vw0123 = _mm_load_ps(w);
97       w = (const float*) ((uintptr_t) w + c);
98 
99       const __m128 vi0x0123 = _mm_loadu_ps(i0);
100       i0 = (const float*) ((uintptr_t) i0 + c);
101       const __m128 vi1x0123 = _mm_loadu_ps(i1);
102       i1 = (const float*) ((uintptr_t) i1 + c);
103 
104       const __m128 vprod0x0123 = _mm_mul_ps(vi0x0123, vw0123);
105       const __m128 vprod1x0123 = _mm_mul_ps(vi1x0123, vw0123);
106 
107       __m128 vacc0x0123 = _mm_blendv_ps(vi0x0123, vprod0x0123, vi0x0123);
108       __m128 vacc1x0123 = _mm_blendv_ps(vi1x0123, vprod1x0123, vi1x0123);
109 
110       if (c & (2 * sizeof(float))) {
111         _mm_storel_pi((__m64*) o0, vacc0x0123);
112         _mm_storel_pi((__m64*) o1, vacc1x0123);
113 
114         vacc0x0123 = _mm_movehl_ps(vacc0x0123, vacc0x0123);
115         vacc1x0123 = _mm_movehl_ps(vacc1x0123, vacc1x0123);
116 
117         o0 += 2;
118         o1 += 2;
119       }
120       if (c & (1 * sizeof(float))) {
121         _mm_store_ss(o0, vacc0x0123);
122         _mm_store_ss(o1, vacc1x0123);
123 
124         o0 += 1;
125         o1 += 1;
126       }
127     }
128     i0 = (const float*) ((uintptr_t) i0 + input_increment);
129     o0 = (float*) ((uintptr_t) o0 + output_increment);
130     i1 = (const float*) ((uintptr_t) i1 + input_increment);
131     o1 = (float*) ((uintptr_t) o1 + output_increment);
132     if XNN_UNPREDICTABLE(rows < 4) {
133       i1 = i0;
134       o1 = o0;
135     }
136     rows = doz(rows, 2);
137   } while (rows != 0);
138 }
139