blob: 3a5d54737ffe73486f523a82ccaf3ec9c061836c [file] [log] [blame]
Marat Dukhan80fc9322019-09-29 21:06:36 -07001// 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.
XNNPACK Teamb455b122019-09-27 18:10:33 -07005
6#include <assert.h>
7
8#include <arm_neon.h>
9
10#include <xnnpack/pavgpool.h>
11
12
Marat Dukhan99936602020-04-11 16:47:01 -070013void xnn_f32_pavgpool_minmax_ukernel_9x__neon_c4(
Marat Dukhan6ee435a2020-02-26 22:33:38 -080014 size_t output_pixels,
15 size_t kernel_elements,
16 size_t channels,
XNNPACK Teamb455b122019-09-27 18:10:33 -070017 const float** input,
Marat Dukhanee1f63e2020-02-27 15:43:52 -080018 size_t input_offset,
XNNPACK Teamb455b122019-09-27 18:10:33 -070019 const float* zero,
20 const float* multiplier,
21 float* output,
22 size_t input_increment,
23 size_t output_increment,
Marat Dukhan7be427a2021-12-13 23:38:20 -080024 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
XNNPACK Teamb455b122019-09-27 18:10:33 -070025{
Marat Dukhan6ee435a2020-02-26 22:33:38 -080026 assert(output_pixels != 0);
27 assert(kernel_elements != 0);
28 assert(kernel_elements <= 9);
29 assert(channels != 0);
XNNPACK Teamb455b122019-09-27 18:10:33 -070030
Frank Barchardfcfdc0e2019-10-21 15:58:42 -070031 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
32 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
33
XNNPACK Teamb455b122019-09-27 18:10:33 -070034 do {
35 const float* i0 = input[0];
Marat Dukhanee1f63e2020-02-27 15:43:52 -080036 assert(i0 != NULL);
XNNPACK Teamb455b122019-09-27 18:10:33 -070037 const float* i1 = input[1];
38 const float* i2 = input[2];
39 const float* i3 = input[3];
40 const float* i4 = input[4];
41 const float* i5 = input[5];
42 const float* i6 = input[6];
43 const float* i7 = input[7];
44 const float* i8 = input[8];
45 input = (const float**) ((uintptr_t) input + input_increment);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080046 if (kernel_elements < 2) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070047 i1 = zero;
48 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080049 assert(i1 != NULL);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080050 if (kernel_elements <= 2) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070051 i2 = zero;
52 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080053 assert(i2 != NULL);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080054 if (kernel_elements < 4) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070055 i3 = zero;
56 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080057 assert(i3 != NULL);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080058 if (kernel_elements <= 4) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070059 i4 = zero;
60 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080061 assert(i4 != NULL);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080062 if (kernel_elements < 6) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070063 i5 = zero;
64 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080065 assert(i5 != NULL);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080066 if (kernel_elements <= 6) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070067 i6 = zero;
68 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080069 assert(i6 != NULL);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080070 if (kernel_elements < 8) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070071 i7 = zero;
72 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080073 assert(i7 != NULL);
Marat Dukhan6ee435a2020-02-26 22:33:38 -080074 if (kernel_elements <= 8) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070075 i8 = zero;
76 }
Marat Dukhanee1f63e2020-02-27 15:43:52 -080077 assert(i8 != NULL);
78 if XNN_UNPREDICTABLE(i0 != zero) {
79 i0 = (const float*) ((uintptr_t) i0 + input_offset);
80 }
81 if XNN_UNPREDICTABLE(i1 != zero) {
82 i1 = (const float*) ((uintptr_t) i1 + input_offset);
83 }
84 if XNN_UNPREDICTABLE(i2 != zero) {
85 i2 = (const float*) ((uintptr_t) i2 + input_offset);
86 }
87 if XNN_UNPREDICTABLE(i3 != zero) {
88 i3 = (const float*) ((uintptr_t) i3 + input_offset);
89 }
90 if XNN_UNPREDICTABLE(i4 != zero) {
91 i4 = (const float*) ((uintptr_t) i4 + input_offset);
92 }
93 if XNN_UNPREDICTABLE(i5 != zero) {
94 i5 = (const float*) ((uintptr_t) i5 + input_offset);
95 }
96 if XNN_UNPREDICTABLE(i6 != zero) {
97 i6 = (const float*) ((uintptr_t) i6 + input_offset);
98 }
99 if XNN_UNPREDICTABLE(i7 != zero) {
100 i7 = (const float*) ((uintptr_t) i7 + input_offset);
101 }
102 if XNN_UNPREDICTABLE(i8 != zero) {
103 i8 = (const float*) ((uintptr_t) i8 + input_offset);
104 }
XNNPACK Teamb455b122019-09-27 18:10:33 -0700105
106 const float32x4_t vmultiplier = vld1q_dup_f32(multiplier); multiplier += 1;
107
Marat Dukhan6ee435a2020-02-26 22:33:38 -0800108 size_t c = channels;
109 while (c >= 4) {
XNNPACK Teamb455b122019-09-27 18:10:33 -0700110 const float32x4_t vi0 = vld1q_f32(i0); i0 += 4;
111 const float32x4_t vi1 = vld1q_f32(i1); i1 += 4;
112 const float32x4_t vi2 = vld1q_f32(i2); i2 += 4;
113 const float32x4_t vi3 = vld1q_f32(i3); i3 += 4;
114 const float32x4_t vi4 = vld1q_f32(i4); i4 += 4;
115 const float32x4_t vi5 = vld1q_f32(i5); i5 += 4;
116 const float32x4_t vi6 = vld1q_f32(i6); i6 += 4;
117 const float32x4_t vi7 = vld1q_f32(i7); i7 += 4;
118 const float32x4_t vi8 = vld1q_f32(i8); i8 += 4;
119
120 const float32x4_t vsum01 = vaddq_f32(vi0, vi1);
121 const float32x4_t vsum23 = vaddq_f32(vi2, vi3);
122 const float32x4_t vsum45 = vaddq_f32(vi4, vi5);
123 const float32x4_t vsum67 = vaddq_f32(vi6, vi7);
124 const float32x4_t vsum018 = vaddq_f32(vsum01, vi8);
125 const float32x4_t vsum2345 = vaddq_f32(vsum23, vsum45);
126 const float32x4_t vsum01678 = vaddq_f32(vsum018, vsum67);
127 const float32x4_t vsum = vaddq_f32(vsum2345, vsum01678);
128
129 float32x4_t vout = vmulq_f32(vsum, vmultiplier);
Frank Barchardfcfdc0e2019-10-21 15:58:42 -0700130 vout = vmaxq_f32(vout, voutput_min);
131 vout = vminq_f32(vout, voutput_max);
XNNPACK Teamb455b122019-09-27 18:10:33 -0700132
133 vst1q_f32(output, vout); output += 4;
134
Marat Dukhan6ee435a2020-02-26 22:33:38 -0800135 c -= 4;
XNNPACK Teamb455b122019-09-27 18:10:33 -0700136 }
Marat Dukhan6ee435a2020-02-26 22:33:38 -0800137 if (c != 0) {
XNNPACK Teamb455b122019-09-27 18:10:33 -0700138 const float32x4_t vi0 = vld1q_f32(i0);
139 const float32x4_t vi1 = vld1q_f32(i1);
140 const float32x4_t vi2 = vld1q_f32(i2);
141 const float32x4_t vi3 = vld1q_f32(i3);
142 const float32x4_t vi4 = vld1q_f32(i4);
143 const float32x4_t vi5 = vld1q_f32(i5);
144 const float32x4_t vi6 = vld1q_f32(i6);
145 const float32x4_t vi7 = vld1q_f32(i7);
146 const float32x4_t vi8 = vld1q_f32(i8);
147
148 const float32x4_t vsum01 = vaddq_f32(vi0, vi1);
149 const float32x4_t vsum23 = vaddq_f32(vi2, vi3);
150 const float32x4_t vsum45 = vaddq_f32(vi4, vi5);
151 const float32x4_t vsum67 = vaddq_f32(vi6, vi7);
152 const float32x4_t vsum018 = vaddq_f32(vsum01, vi8);
153 const float32x4_t vsum2345 = vaddq_f32(vsum23, vsum45);
154 const float32x4_t vsum01678 = vaddq_f32(vsum018, vsum67);
155 const float32x4_t vsum = vaddq_f32(vsum2345, vsum01678);
156
157 float32x4_t vout = vmulq_f32(vsum, vmultiplier);
Frank Barchardfcfdc0e2019-10-21 15:58:42 -0700158 vout = vmaxq_f32(vout, voutput_min);
159 vout = vminq_f32(vout, voutput_max);
XNNPACK Teamb455b122019-09-27 18:10:33 -0700160
161 float32x2_t vout_lo = vget_low_f32(vout);
Marat Dukhan6ee435a2020-02-26 22:33:38 -0800162 if (c & 2) {
XNNPACK Teamb455b122019-09-27 18:10:33 -0700163 vst1_f32(output, vout_lo); output += 2;
164 vout_lo = vget_high_f32(vout);
165 }
Marat Dukhan6ee435a2020-02-26 22:33:38 -0800166 if (c & 1) {
XNNPACK Teamb455b122019-09-27 18:10:33 -0700167 vst1_lane_f32(output, vout_lo, 0); output += 1;
168 }
169 }
170 output = (float*) ((uintptr_t) output + output_increment);
Marat Dukhan6ee435a2020-02-26 22:33:38 -0800171 } while (--output_pixels != 0);
XNNPACK Teamb455b122019-09-27 18:10:33 -0700172}