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 <xnnpack/gavgpool.h>
9 #include <xnnpack/math.h>
10
11
xnn_f32_gavgpool_ukernel_up7__scalar(size_t m,size_t n,const float * input,size_t input_stride,const float * zero,float * output,const union xnn_f32_avgpool_params params[restrict static1])12 void xnn_f32_gavgpool_ukernel_up7__scalar(
13 size_t m,
14 size_t n,
15 const float* input,
16 size_t input_stride,
17 const float* zero,
18 float* output,
19 const union xnn_f32_avgpool_params params[restrict static 1])
20 {
21 assert(m != 0);
22 assert(m <= 7);
23 assert(n != 0);
24
25 const float* i0 = input;
26 const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
27 if (m < 2) {
28 i1 = zero;
29 }
30 const float* i2 = (const float*) ((uintptr_t) i1 + input_stride);
31 if (m <= 2) {
32 i2 = zero;
33 }
34 const float* i3 = (const float*) ((uintptr_t) i2 + input_stride);
35 if (m < 4) {
36 i3 = zero;
37 }
38 const float* i4 = (const float*) ((uintptr_t) i3 + input_stride);
39 if (m <= 4) {
40 i4 = zero;
41 }
42 const float* i5 = (const float*) ((uintptr_t) i4 + input_stride);
43 if (m < 6) {
44 i5 = zero;
45 }
46 const float* i6 = (const float*) ((uintptr_t) i5 + input_stride);
47 if (m <= 6) {
48 i6 = zero;
49 }
50
51 const float vmultiplier = params->scalar.multiplier;
52 const float voutput_min = params->scalar.output_min;
53 const float voutput_max = params->scalar.output_max;
54 do {
55 const float vi0 = *i0++;
56 const float vi1 = *i1++;
57 const float vi2 = *i2++;
58 const float vi3 = *i3++;
59 const float vi4 = *i4++;
60 const float vi5 = *i5++;
61 const float vi6 = *i6++;
62
63 const float vsum01 = vi0 + vi1;
64 const float vsum23 = vi2 + vi3;
65 const float vsum45 = vi4 + vi5;
66
67 const float vsum016 = vsum01 + vi6;
68 const float vsum2345 = vsum23 + vsum45;
69
70 const float vsum = vsum016 + vsum2345;
71
72 float vout = vsum * vmultiplier;
73 vout = math_max_f32(vout, voutput_min);
74 vout = math_min_f32(vout, voutput_max);
75
76 *output++ = vout;
77 } while (--n != 0);
78 }
79