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_cw_ukernel__scalar_x1(size_t elements,size_t channels,const float * input,float * output,const union xnn_f32_gavgpool_params params[restrict XNN_MIN_ELEMENTS (1)])12 void xnn_f32_gavgpool_cw_ukernel__scalar_x1(
13 size_t elements,
14 size_t channels,
15 const float* input,
16 float* output,
17 const union xnn_f32_gavgpool_params params[restrict XNN_MIN_ELEMENTS(1)])
18 {
19 assert(elements != 0);
20 assert(elements % sizeof(float) == 0);
21 assert(channels != 0);
22
23 const float* i0 = input;
24
25 const float vmultiplier = params->scalar.multiplier;
26 const float voutput_max = params->scalar.output_max;
27 const float voutput_min = params->scalar.output_min;
28
29 while (channels != 0) {
30 float vsum0 = 0.f;
31 float vsum1 = 0.f;
32 float vsum2 = 0.f;
33 float vsum3 = 0.f;
34 size_t n = elements;
35 while (n >= 4 * sizeof(float)) {
36 vsum0 += i0[0];
37 vsum1 += i0[1];
38 vsum2 += i0[2];
39 vsum3 += i0[3];
40
41 i0 += 4;
42 n -= 4 * sizeof(float);
43 }
44
45 while (n != 0) {
46 vsum0 += *i0++;
47 n -= sizeof(float);
48 }
49
50 float vout = ( (vsum0 + vsum1) + (vsum2 + vsum3) ) * vmultiplier;
51
52 vout = math_min_f32(vout, voutput_max);
53 vout = math_max_f32(vout, voutput_min);
54
55 *output++ = vout;
56 channels -= 1;
57 }
58 }
59