• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-gavgpool/unipass-neon.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9 
10 #include <assert.h>
11 
12 #include <arm_neon.h>
13 
14 #include <xnnpack/gavgpool.h>
15 
16 
xnn_qu8_gavgpool_minmax_rndnu_ukernel_7x__neon_c16(size_t rows,size_t channels,const uint8_t * input,size_t input_stride,const uint8_t * zero,uint8_t * output,const union xnn_qu8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qu8_gavgpool_minmax_rndnu_ukernel_7x__neon_c16(
18     size_t rows,
19     size_t channels,
20     const uint8_t* input,
21     size_t input_stride,
22     const uint8_t* zero,
23     uint8_t* output,
24     const union xnn_qu8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
25 {
26   assert(rows != 0);
27   assert(rows <= 7);
28   assert(channels != 0);
29 
30   const uint8_t* i0 = input;
31   const uint8_t* i1 = (const uint8_t*) ((uintptr_t) i0 + input_stride);
32   if XNN_UNPREDICTABLE(rows < 2) {
33     i1 = zero;
34   }
35   const uint8_t* i2 = (const uint8_t*) ((uintptr_t) i1 + input_stride);
36   if XNN_UNPREDICTABLE(rows <= 2) {
37     i2 = zero;
38   }
39   const uint8_t* i3 = (const uint8_t*) ((uintptr_t) i2 + input_stride);
40   if XNN_UNPREDICTABLE(rows < 4) {
41     i3 = zero;
42   }
43   const uint8_t* i4 = (const uint8_t*) ((uintptr_t) i3 + input_stride);
44   if XNN_UNPREDICTABLE(rows <= 4) {
45     i4 = zero;
46   }
47   const uint8_t* i5 = (const uint8_t*) ((uintptr_t) i4 + input_stride);
48   if XNN_UNPREDICTABLE(rows < 6) {
49     i5 = zero;
50   }
51   const uint8_t* i6 = (const uint8_t*) ((uintptr_t) i5 + input_stride);
52   if XNN_UNPREDICTABLE(rows <= 6) {
53     i6 = zero;
54   }
55 
56   const int32x4_t vinit_bias = vld1q_dup_s32(&params->rndnu_neon.init_bias);
57   const int32x4_t vleft_pre_shift = vld1q_dup_s32(&params->rndnu_neon.left_pre_shift);
58   const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
59   const int32x4_t vleft_post_shift = vld1q_dup_s32(&params->rndnu_neon.left_post_shift);
60   const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
61   const uint8x16_t voutput_min = vld1q_dup_u8(&params->rndnu_neon.output_min);
62   const uint8x16_t voutput_max = vld1q_dup_u8(&params->rndnu_neon.output_max);
63   for (; channels >= 16; channels -= 16) {
64     const uint8x8_t vi0x01234567 = vld1_u8(i0); i0 += 8;
65     const uint8x8_t vi0x89ABCDEF = vld1_u8(i0); i0 += 8;
66     const uint8x8_t vi1x01234567 = vld1_u8(i1); i1 += 8;
67     const uint8x8_t vi1x89ABCDEF = vld1_u8(i1); i1 += 8;
68 
69     const uint8x8_t vi2x01234567 = vld1_u8(i2); i2 += 8;
70     uint16x8_t vsum01234567 = vaddl_u8(vi0x01234567, vi1x01234567);
71     const uint8x8_t vi2x89ABCDEF = vld1_u8(i2); i2 += 8;
72     uint16x8_t vsum89ABCDEF = vaddl_u8(vi0x89ABCDEF, vi1x89ABCDEF);
73 
74     const uint8x8_t vi3x01234567 = vld1_u8(i3); i3 += 8;
75     vsum01234567 = vaddw_u8(vsum01234567, vi2x01234567);
76     const uint8x8_t vi3x89ABCDEF = vld1_u8(i3); i3 += 8;
77     vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi2x89ABCDEF);
78     const uint8x8_t vi4x01234567 = vld1_u8(i4); i4 += 8;
79     vsum01234567 = vaddw_u8(vsum01234567, vi3x01234567);
80     const uint8x8_t vi4x89ABCDEF = vld1_u8(i4); i4 += 8;
81     vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi3x89ABCDEF);
82     const uint8x8_t vi5x01234567 = vld1_u8(i5); i5 += 8;
83     vsum01234567 = vaddw_u8(vsum01234567, vi4x01234567);
84     const uint8x8_t vi5x89ABCDEF = vld1_u8(i5); i5 += 8;
85     vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi4x89ABCDEF);
86     const uint8x8_t vi6x01234567 = vld1_u8(i6); i6 += 8;
87     vsum01234567 = vaddw_u8(vsum01234567, vi5x01234567);
88     const uint8x8_t vi6x89ABCDEF = vld1_u8(i6); i6 += 8;
89     vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi5x89ABCDEF);
90     vsum01234567 = vaddw_u8(vsum01234567, vi6x01234567);
91     vsum89ABCDEF = vaddw_u8(vsum89ABCDEF, vi6x89ABCDEF);
92 
93     int32x4_t vacc0123 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsum01234567)));
94     int32x4_t vacc4567 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsum01234567)));
95     int32x4_t vacc89AB = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsum89ABCDEF)));
96     int32x4_t vaccCDEF = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsum89ABCDEF)));
97 
98     vacc0123 = vqshlq_s32(vacc0123, vleft_pre_shift);
99     vacc4567 = vqshlq_s32(vacc4567, vleft_pre_shift);
100     vacc89AB = vqshlq_s32(vacc89AB, vleft_pre_shift);
101     vaccCDEF = vqshlq_s32(vaccCDEF, vleft_pre_shift);
102 
103     vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
104     vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
105     vacc89AB = vqdmulhq_s32(vacc89AB, vmultiplier);
106     vaccCDEF = vqdmulhq_s32(vaccCDEF, vmultiplier);
107 
108     vacc0123 = vrshlq_s32(vacc0123, vleft_post_shift);
109     vacc4567 = vrshlq_s32(vacc4567, vleft_post_shift);
110     vacc89AB = vrshlq_s32(vacc89AB, vleft_post_shift);
111     vaccCDEF = vrshlq_s32(vaccCDEF, vleft_post_shift);
112 
113     #if XNN_ARCH_ARM64
114       int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
115       int16x8_t vacc89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc89AB), vaccCDEF);
116     #else  // !XNN_ARCH_ARM64
117       int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
118       int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
119     #endif  // !XNN_ARCH_ARM64
120 
121     vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
122     vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
123 
124     #if XNN_ARCH_ARM64
125       uint8x16_t vout0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc01234567), vacc89ABCDEF);
126     #else  // !XNN_ARCH_ARM64
127       uint8x16_t vout0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc01234567), vqmovun_s16(vacc89ABCDEF));
128     #endif  // !XNN_ARCH_ARM64
129 
130     vout0123456789ABCDEF = vmaxq_u8(vout0123456789ABCDEF, voutput_min);
131 
132     vout0123456789ABCDEF = vminq_u8(vout0123456789ABCDEF, voutput_max);
133 
134     vst1q_u8(output, vout0123456789ABCDEF); output += 16;
135   }
136   if XNN_UNLIKELY(channels != 0) {
137     do {
138       const uint8x8_t vi0x01234567 = vld1_u8(i0); i0 += 8;
139       const uint8x8_t vi1x01234567 = vld1_u8(i1); i1 += 8;
140       const uint8x8_t vi2x01234567 = vld1_u8(i2); i2 += 8;
141       uint16x8_t vsum01234567 = vaddl_u8(vi0x01234567, vi1x01234567);
142 
143       const uint8x8_t vi3x01234567 = vld1_u8(i3); i3 += 8;
144       vsum01234567 = vaddw_u8(vsum01234567, vi2x01234567);
145       const uint8x8_t vi4x01234567 = vld1_u8(i4); i4 += 8;
146       vsum01234567 = vaddw_u8(vsum01234567, vi3x01234567);
147       const uint8x8_t vi5x01234567 = vld1_u8(i5); i5 += 8;
148       vsum01234567 = vaddw_u8(vsum01234567, vi4x01234567);
149       const uint8x8_t vi6x01234567 = vld1_u8(i6); i6 += 8;
150       vsum01234567 = vaddw_u8(vsum01234567, vi5x01234567);
151       vsum01234567 = vaddw_u8(vsum01234567, vi6x01234567);
152 
153       int32x4_t vacc0123 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_low_u16(vsum01234567)));
154       int32x4_t vacc4567 = vreinterpretq_s32_u32(vaddw_u16(vreinterpretq_u32_s32(vinit_bias), vget_high_u16(vsum01234567)));
155 
156       vacc0123 = vqshlq_s32(vacc0123, vleft_pre_shift);
157       vacc4567 = vqshlq_s32(vacc4567, vleft_pre_shift);
158 
159       vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
160       vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
161 
162       vacc0123 = vrshlq_s32(vacc0123, vleft_post_shift);
163       vacc4567 = vrshlq_s32(vacc4567, vleft_post_shift);
164 
165       #if XNN_ARCH_ARM64
166         int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
167       #else
168         int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
169       #endif
170       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
171 
172       uint8x8_t vout01234567 = vqmovun_s16(vacc01234567);
173       vout01234567 = vmax_u8(vout01234567, vget_low_u8(voutput_min));
174       vout01234567 = vmin_u8(vout01234567, vget_low_u8(voutput_max));
175 
176       if XNN_LIKELY(channels >= 8) {
177         vst1_u8(output, vout01234567); output += 8;
178         channels -= 8;
179       } else {
180         if (channels & 4) {
181           vst1_lane_u32((void*) output, vreinterpret_u32_u8(vout01234567), 0); output += 4;
182           vout01234567 = vext_u8(vout01234567, vout01234567, 4);
183         }
184         if (channels & 2) {
185           vst1_lane_u16((void*) output, vreinterpret_u16_u8(vout01234567), 0); output += 2;
186           vout01234567 = vext_u8(vout01234567, vout01234567, 2);
187         }
188         if (channels & 1) {
189           vst1_lane_u8(output, vout01234567, 0); output += 1;
190         }
191         channels = 0;
192       }
193     } while (channels != 0);
194   }
195 }
196