• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <assert.h>
7 
8 #include <xmmintrin.h>
9 
10 #include <xnnpack/pavgpool.h>
11 
12 
xnn_f32_pavgpool_ukernel_up9__sse(size_t n,size_t ks,size_t kc,const float ** input,const float * zero,const float * multiplier,float * output,size_t input_increment,size_t output_increment,const union xnn_f32_output_params params[restrict static1])13 void xnn_f32_pavgpool_ukernel_up9__sse(
14     size_t n,
15     size_t ks,
16     size_t kc,
17     const float** input,
18     const float* zero,
19     const float* multiplier,
20     float* output,
21     size_t input_increment,
22     size_t output_increment,
23     const union xnn_f32_output_params params[restrict static 1])
24 {
25   assert(n != 0);
26   assert(ks != 0);
27   assert(ks <= 9);
28   assert(kc != 0);
29 
30   const __m128 voutput_min = _mm_load_ps(params->sse.min);
31   const __m128 voutput_max = _mm_load_ps(params->sse.max);
32 
33   do {
34     const float* i0 = input[0];
35     const float* i1 = input[1];
36     const float* i2 = input[2];
37     const float* i3 = input[3];
38     const float* i4 = input[4];
39     const float* i5 = input[5];
40     const float* i6 = input[6];
41     const float* i7 = input[7];
42     const float* i8 = input[8];
43     input = (const float**) ((uintptr_t) input + input_increment);
44     if (ks < 2) {
45       i1 = zero;
46     }
47     if (ks <= 2) {
48       i2 = zero;
49     }
50     if (ks < 4) {
51       i3 = zero;
52     }
53     if (ks <= 4) {
54       i4 = zero;
55     }
56     if (ks < 6) {
57       i5 = zero;
58     }
59     if (ks <= 6) {
60       i6 = zero;
61     }
62     if (ks < 8) {
63       i7 = zero;
64     }
65     if (ks <= 8) {
66       i8 = zero;
67     }
68 
69     const __m128 vmultiplier = _mm_load1_ps(multiplier);
70     multiplier += 1;
71 
72     size_t k = kc;
73     while (k >= 4) {
74       const __m128 vi0 = _mm_loadu_ps(i0);
75       i0 += 4;
76       const __m128 vi1 = _mm_loadu_ps(i1);
77       i1 += 4;
78       const __m128 vi2 = _mm_loadu_ps(i2);
79       i2 += 4;
80       const __m128 vi3 = _mm_loadu_ps(i3);
81       i3 += 4;
82       const __m128 vi4 = _mm_loadu_ps(i4);
83       i4 += 4;
84       const __m128 vi5 = _mm_loadu_ps(i5);
85       i5 += 4;
86       const __m128 vi6 = _mm_loadu_ps(i6);
87       i6 += 4;
88       const __m128 vi7 = _mm_loadu_ps(i7);
89       i7 += 4;
90       const __m128 vi8 = _mm_loadu_ps(i8);
91       i8 += 4;
92 
93       const __m128 vsum018 = _mm_add_ps(_mm_add_ps(vi0, vi1), vi8);
94       const __m128 vsum23 = _mm_add_ps(vi2, vi3);
95       const __m128 vsum45 = _mm_add_ps(vi4, vi5);
96       const __m128 vsum67 = _mm_add_ps(vi6, vi7);
97 
98       const __m128 vsum2345 = _mm_add_ps(vsum23, vsum45);
99       const __m128 vsum01678 = _mm_add_ps(vsum018, vsum67);
100       const __m128 vsum = _mm_add_ps(vsum2345, vsum01678);
101 
102       __m128 vout = _mm_mul_ps(vsum, vmultiplier);
103       vout = _mm_max_ps(vout, voutput_min);
104       vout = _mm_min_ps(vout, voutput_max);
105 
106       _mm_storeu_ps(output, vout); output += 4;
107 
108       k -= 4;
109     }
110     if (k != 0) {
111       const __m128 vi0 = _mm_loadu_ps(i0);
112       const __m128 vi1 = _mm_loadu_ps(i1);
113       const __m128 vi2 = _mm_loadu_ps(i2);
114       const __m128 vi3 = _mm_loadu_ps(i3);
115       const __m128 vi4 = _mm_loadu_ps(i4);
116       const __m128 vi5 = _mm_loadu_ps(i5);
117       const __m128 vi6 = _mm_loadu_ps(i6);
118       const __m128 vi7 = _mm_loadu_ps(i7);
119       const __m128 vi8 = _mm_loadu_ps(i8);
120 
121       const __m128 vsum01 = _mm_add_ps(vi0, vi1);
122       const __m128 vsum23 = _mm_add_ps(vi2, vi3);
123       const __m128 vsum45 = _mm_add_ps(vi4, vi5);
124       const __m128 vsum67 = _mm_add_ps(vi6, vi7);
125       const __m128 vsum018 = _mm_add_ps(vsum01, vi8);
126       const __m128 vsum2345 = _mm_add_ps(vsum23, vsum45);
127       const __m128 vsum01678 = _mm_add_ps(vsum018, vsum67);
128       const __m128 vsum = _mm_add_ps(vsum2345, vsum01678);
129 
130       __m128 vout = _mm_mul_ps(vsum, vmultiplier);
131       vout = _mm_max_ps(vout, voutput_min);
132       vout = _mm_min_ps(vout, voutput_max);
133 
134       if (k & 2) {
135         _mm_storel_pi((__m64*) output, vout);
136         vout = _mm_movehl_ps(vout, vout);
137         output += 2;
138       }
139       if (k & 1) {
140         _mm_store_ss(output, vout);
141         output += 1;
142       }
143     }
144     output = (float*) ((uintptr_t) output + output_increment);
145   } while (--n != 0);
146 }
147