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 <psimd.h>
9
10 #include <xnnpack/pavgpool.h>
11
12
xnn_f32_pavgpool_ukernel_up9__psimd(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__psimd(
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 psimd_f32 voutput_min = psimd_load_splat_f32(¶ms->scalar.min);
31 const psimd_f32 voutput_max = psimd_load_splat_f32(¶ms->scalar.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 psimd_f32 vmultiplier = psimd_load_splat_f32(multiplier);
70 multiplier += 1;
71
72 size_t k = kc;
73 while (k >= 4) {
74 const psimd_f32 vi0 = psimd_load_f32(i0);
75 i0 += 4;
76 const psimd_f32 vi1 = psimd_load_f32(i1);
77 i1 += 4;
78 const psimd_f32 vi2 = psimd_load_f32(i2);
79 i2 += 4;
80 const psimd_f32 vi3 = psimd_load_f32(i3);
81 i3 += 4;
82 const psimd_f32 vi4 = psimd_load_f32(i4);
83 i4 += 4;
84 const psimd_f32 vi5 = psimd_load_f32(i5);
85 i5 += 4;
86 const psimd_f32 vi6 = psimd_load_f32(i6);
87 i6 += 4;
88 const psimd_f32 vi7 = psimd_load_f32(i7);
89 i7 += 4;
90 const psimd_f32 vi8 = psimd_load_f32(i8);
91 i8 += 4;
92
93 const psimd_f32 vsum018 = psimd_add_f32(psimd_add_f32(vi0, vi1), vi8);
94 const psimd_f32 vsum23 = psimd_add_f32(vi2, vi3);
95 const psimd_f32 vsum45 = psimd_add_f32(vi4, vi5);
96 const psimd_f32 vsum67 = psimd_add_f32(vi6, vi7);
97
98 const psimd_f32 vsum2345 = psimd_add_f32(vsum23, vsum45);
99 const psimd_f32 vsum01678 = psimd_add_f32(vsum018, vsum67);
100 const psimd_f32 vsum = psimd_add_f32(vsum2345, vsum01678);
101
102 psimd_f32 vout = psimd_mul_f32(vsum, vmultiplier);
103 vout = psimd_max_f32(vout, voutput_min);
104 vout = psimd_min_f32(vout, voutput_max);
105
106 psimd_store_f32(output, vout);
107 output += 4;
108
109 k -= 4;
110 }
111 if (k != 0) {
112 const psimd_f32 vi0 = psimd_load_f32(i0);
113 const psimd_f32 vi1 = psimd_load_f32(i1);
114 const psimd_f32 vi2 = psimd_load_f32(i2);
115 const psimd_f32 vi3 = psimd_load_f32(i3);
116 const psimd_f32 vi4 = psimd_load_f32(i4);
117 const psimd_f32 vi5 = psimd_load_f32(i5);
118 const psimd_f32 vi6 = psimd_load_f32(i6);
119 const psimd_f32 vi7 = psimd_load_f32(i7);
120 const psimd_f32 vi8 = psimd_load_f32(i8);
121
122 const psimd_f32 vsum01 = psimd_add_f32(vi0, vi1);
123 const psimd_f32 vsum23 = psimd_add_f32(vi2, vi3);
124 const psimd_f32 vsum45 = psimd_add_f32(vi4, vi5);
125 const psimd_f32 vsum67 = psimd_add_f32(vi6, vi7);
126 const psimd_f32 vsum018 = psimd_add_f32(vsum01, vi8);
127 const psimd_f32 vsum2345 = psimd_add_f32(vsum23, vsum45);
128 const psimd_f32 vsum01678 = psimd_add_f32(vsum018, vsum67);
129 const psimd_f32 vsum = psimd_add_f32(vsum2345, vsum01678);
130
131 psimd_f32 vout = psimd_mul_f32(vsum, vmultiplier);
132 vout = psimd_max_f32(vout, voutput_min);
133 vout = psimd_min_f32(vout, voutput_max);
134
135 if (k & 2) {
136 psimd_store2_f32(output, vout);
137 output += 2;
138 vout = psimd_concat_hi_f32(vout, vout);
139 }
140 if (k & 1) {
141 psimd_store1_f32(output, vout);
142 output += 1;
143 }
144 }
145 output = (float*) ((uintptr_t) output + output_increment);
146 } while (--n != 0);
147 }
148