• 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 <arm_neon.h>
9 
10 #include <xnnpack/gavgpool.h>
11 
12 
xnn_f32_gavgpool_minmax_ukernel_7x__neon_c4(size_t rows,size_t channels,const float * input,size_t input_stride,const float * zero,float * output,const union xnn_f32_scaleminmax_params params[restrict XNN_MIN_ELEMENTS (1)])13 void xnn_f32_gavgpool_minmax_ukernel_7x__neon_c4(
14     size_t rows,
15     size_t channels,
16     const float* input,
17     size_t input_stride,
18     const float* zero,
19     float* output,
20     const union xnn_f32_scaleminmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
21 {
22   assert(rows != 0);
23   assert(rows <= 7);
24   assert(channels != 0);
25 
26   const float* i0 = input;
27   const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
28   if (rows < 2) {
29     i1 = zero;
30   }
31   const float* i2 = (const float*) ((uintptr_t) i1 + input_stride);
32   if (rows <= 2) {
33     i2 = zero;
34   }
35   const float* i3 = (const float*) ((uintptr_t) i2 + input_stride);
36   if (rows < 4) {
37     i3 = zero;
38   }
39   const float* i4 = (const float*) ((uintptr_t) i3 + input_stride);
40   if (rows <= 4) {
41     i4 = zero;
42   }
43   const float* i5 = (const float*) ((uintptr_t) i4 + input_stride);
44   if (rows < 6) {
45     i5 = zero;
46   }
47   const float* i6 = (const float*) ((uintptr_t) i5 + input_stride);
48   if (rows <= 6) {
49     i6 = zero;
50   }
51   const float32x4_t vscale = vld1q_dup_f32(&params->scalar.scale);
52   const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
53   const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
54 
55   while (channels >= 4) {
56     const float32x4_t vi0 = vld1q_f32(i0); i0 += 4;
57     const float32x4_t vi1 = vld1q_f32(i1); i1 += 4;
58     const float32x4_t vi2 = vld1q_f32(i2); i2 += 4;
59     const float32x4_t vi3 = vld1q_f32(i3); i3 += 4;
60     const float32x4_t vi4 = vld1q_f32(i4); i4 += 4;
61     const float32x4_t vi5 = vld1q_f32(i5); i5 += 4;
62     const float32x4_t vi6 = vld1q_f32(i6); i6 += 4;
63 
64     const float32x4_t vsum01 = vaddq_f32(vi0, vi1);
65     const float32x4_t vsum23 = vaddq_f32(vi2, vi3);
66     const float32x4_t vsum45 = vaddq_f32(vi4, vi5);
67 
68     const float32x4_t vsum016 = vaddq_f32(vsum01, vi6);
69     const float32x4_t vsum2345 = vaddq_f32(vsum23, vsum45);
70 
71     const float32x4_t vsum = vaddq_f32(vsum016, vsum2345);
72 
73     float32x4_t vout = vmulq_f32(vsum, vscale);
74     vout = vmaxq_f32(vout, vmin);
75     vout = vminq_f32(vout, vmax);
76 
77     vst1q_f32(output, vout); output += 4;
78 
79     channels -= 4;
80   }
81   if (channels != 0) {
82     const float32x4_t vi0 = vld1q_f32(i0);
83     const float32x4_t vi1 = vld1q_f32(i1);
84     const float32x4_t vi2 = vld1q_f32(i2);
85     const float32x4_t vi3 = vld1q_f32(i3);
86     const float32x4_t vi4 = vld1q_f32(i4);
87     const float32x4_t vi5 = vld1q_f32(i5);
88     const float32x4_t vi6 = vld1q_f32(i6);
89 
90     const float32x4_t vsum01 = vaddq_f32(vi0, vi1);
91     const float32x4_t vsum23 = vaddq_f32(vi2, vi3);
92     const float32x4_t vsum45 = vaddq_f32(vi4, vi5);
93 
94     const float32x4_t vsum016 = vaddq_f32(vsum01, vi6);
95     const float32x4_t vsum2345 = vaddq_f32(vsum23, vsum45);
96 
97     const float32x4_t vsum = vaddq_f32(vsum016, vsum2345);
98 
99     float32x4_t vout = vmulq_f32(vsum, vscale);
100     vout = vmaxq_f32(vout, vmin);
101     vout = vminq_f32(vout, vmax);
102 
103     float32x2_t vout_lo = vget_low_f32(vout);
104     if (channels & 2) {
105       vst1_f32(output, vout_lo); output += 2;
106       vout_lo = vget_high_f32(vout);
107     }
108     if (channels & 1) {
109       vst1_lane_f32(output, vout_lo, 0);
110     }
111   }
112 }
113