Add tail to depthwise 5x5s2p2_chw kernels.
PiperOrigin-RevId: 280775136
diff --git a/src/f32-dwconv-spchw/5x5s2p2-neonfma.c b/src/f32-dwconv-spchw/5x5s2p2-neonfma.c
index 73d8abf..b955004 100644
--- a/src/f32-dwconv-spchw/5x5s2p2-neonfma.c
+++ b/src/f32-dwconv-spchw/5x5s2p2-neonfma.c
@@ -62,8 +62,145 @@
float32x4_t vi3x4567 = vld1q_f32(i3); i3 = (const float*) ((uintptr_t) i3 + input_tuple_stride);
float32x4_t vi4x4567 = vld1q_f32(i4); i4 = (const float*) ((uintptr_t) i4 + input_tuple_stride);
- long long k = n;
- for (; k > 0; k -= 8) {
+ size_t k = n;
+ for (; k > 8; k -= 8) {
+ float32x4_t vo468Ap00 = vdupq_laneq_f32(vw0123, 0);
+
+ float32x4_t vi0x89AB;
+ float32x4_t vi1x89AB;
+ float32x4_t vi2x89AB;
+ float32x4_t vi3x89AB;
+ float32x4_t vi4x89AB;
+
+ vi0x89AB = vld1q_f32(i0); i0 = (const float*) ((uintptr_t) i0 + input_tuple_stride);
+ vi1x89AB = vld1q_f32(i1); i1 = (const float*) ((uintptr_t) i1 + input_tuple_stride);
+ vi2x89AB = vld1q_f32(i2); i2 = (const float*) ((uintptr_t) i2 + input_tuple_stride);
+ vi3x89AB = vld1q_f32(i3); i3 = (const float*) ((uintptr_t) i3 + input_tuple_stride);
+ vi4x89AB = vld1q_f32(i4); i4 = (const float*) ((uintptr_t) i4 + input_tuple_stride);
+
+ float32x4_t vi0xCDEF;
+ float32x4_t vi1xCDEF;
+ float32x4_t vi2xCDEF;
+ float32x4_t vi3xCDEF;
+ float32x4_t vi4xCDEF;
+
+ vi0xCDEF = vld1q_f32(i0); i0 = (const float*) ((uintptr_t) i0 + input_tuple_stride);
+ vi1xCDEF = vld1q_f32(i1); i1 = (const float*) ((uintptr_t) i1 + input_tuple_stride);
+ vi2xCDEF = vld1q_f32(i2); i2 = (const float*) ((uintptr_t) i2 + input_tuple_stride);
+ vi3xCDEF = vld1q_f32(i3); i3 = (const float*) ((uintptr_t) i3 + input_tuple_stride);
+ vi4xCDEF = vld1q_f32(i4); i4 = (const float*) ((uintptr_t) i4 + input_tuple_stride);
+
+ float32x4_t vi0x468A = vuzp1q_f32(vi0x4567, vi0x89AB);
+ float32x4_t vi0x579B = vuzp2q_f32(vi0x4567, vi0x89AB);
+ float32x4_t vi1x468A = vuzp1q_f32(vi1x4567, vi1x89AB);
+ float32x4_t vi1x579B = vuzp2q_f32(vi1x4567, vi1x89AB);
+ float32x4_t vi2x468A = vuzp1q_f32(vi2x4567, vi2x89AB);
+ float32x4_t vi2x579B = vuzp2q_f32(vi2x4567, vi2x89AB);
+ float32x4_t vi3x468A = vuzp1q_f32(vi3x4567, vi3x89AB);
+ float32x4_t vi3x579B = vuzp2q_f32(vi3x4567, vi3x89AB);
+ float32x4_t vi4x468A = vuzp1q_f32(vi4x4567, vi4x89AB);
+ float32x4_t vi4x579B = vuzp2q_f32(vi4x4567, vi4x89AB);
+
+ // middle tap
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi0x468A, vw0123, 3);
+ float32x4_t vo468Ap01 = vmulq_laneq_f32(vi1x468A, vw89AB, 0);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi2x468A, vwCDEF, 1);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi3x468A, vwGHIJ, 2);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi4x468A, vwKLMN, 3);
+
+ // one left
+ const float32x4_t vi0x3579 = vextq_f32(vi0x0123, vi0x579B, 3);
+ const float32x4_t vi1x3579 = vextq_f32(vi1x0123, vi1x579B, 3);
+ const float32x4_t vi2x3579 = vextq_f32(vi2x0123, vi2x579B, 3);
+ const float32x4_t vi3x3579 = vextq_f32(vi3x0123, vi3x579B, 3);
+ const float32x4_t vi4x3579 = vextq_f32(vi4x0123, vi4x579B, 3);
+
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi0x3579, vw0123, 2);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi1x3579, vw4567, 3);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi2x3579, vwCDEF, 0);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi3x3579, vwGHIJ, 1);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi4x3579, vwKLMN, 2);
+
+ // two left
+ // getting the vector to use for the far left tap is annoying
+ // as we can't ext anything we currently have to get it.
+ // To do this, we get a bit ugly. Interpret the float 32x4
+ // vector as int 64x2. Then left shift by 32. Interpret
+ // again as float 32x4. Now the right most bits are what we
+ // want them to be for the following ext.
+ const float32x4_t vi0x0012 = vreinterpretq_f32_u64(vshlq_n_u64(vreinterpretq_u64_f32(vi0x0123), 32));
+ const float32x4_t vi1x0012 = vreinterpretq_f32_u64(vshlq_n_u64(vreinterpretq_u64_f32(vi1x0123), 32));
+ const float32x4_t vi2x0012 = vreinterpretq_f32_u64(vshlq_n_u64(vreinterpretq_u64_f32(vi2x0123), 32));
+ const float32x4_t vi3x0012 = vreinterpretq_f32_u64(vshlq_n_u64(vreinterpretq_u64_f32(vi3x0123), 32));
+ const float32x4_t vi4x0012 = vreinterpretq_f32_u64(vshlq_n_u64(vreinterpretq_u64_f32(vi4x0123), 32));
+
+ const float32x4_t vi0x2468 = vextq_f32(vi0x0012, vi0x468A, 3);
+ const float32x4_t vi1x2468 = vextq_f32(vi1x0012, vi1x468A, 3);
+ const float32x4_t vi2x2468 = vextq_f32(vi2x0012, vi2x468A, 3);
+ const float32x4_t vi3x2468 = vextq_f32(vi3x0012, vi3x468A, 3);
+ const float32x4_t vi4x2468 = vextq_f32(vi4x0012, vi4x468A, 3);
+
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi0x2468, vw0123, 1);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi1x2468, vw4567, 2);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi2x2468, vw89AB, 3);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi3x2468, vwGHIJ, 0);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi4x2468, vwKLMN, 1);
+
+ vi0x0123 = vi0x89AB;
+ vi1x0123 = vi1x89AB;
+ vi2x0123 = vi2x89AB;
+ vi3x0123 = vi3x89AB;
+ vi4x0123 = vi4x89AB;
+
+ // one right
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi0x579B, vw4567, 0);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi1x579B, vw89AB, 1);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi2x579B, vwCDEF, 2);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi3x579B, vwGHIJ, 3);
+ vo468Ap00 = vfmaq_lane_f32( vo468Ap00, vi4x579B, vwOP, 0);
+
+ // two right
+ const float32x4_t vi0x68AC = vextq_f32(vi0x468A, vi0xCDEF, 1);
+ const float32x4_t vi1x68AC = vextq_f32(vi1x468A, vi1xCDEF, 1);
+ const float32x4_t vi2x68AC = vextq_f32(vi2x468A, vi2xCDEF, 1);
+ const float32x4_t vi3x68AC = vextq_f32(vi3x468A, vi3xCDEF, 1);
+ const float32x4_t vi4x68AC = vextq_f32(vi4x468A, vi4xCDEF, 1);
+
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi0x68AC, vw4567, 1);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi1x68AC, vw89AB, 2);
+ vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi2x68AC, vwCDEF, 3);
+ vo468Ap01 = vfmaq_laneq_f32(vo468Ap01, vi3x68AC, vwKLMN, 0);
+ vo468Ap00 = vfmaq_lane_f32( vo468Ap00, vi4x68AC, vwOP, 1);
+
+ vi0x4567 = vi0xCDEF;
+ vi1x4567 = vi1xCDEF;
+ vi2x4567 = vi2xCDEF;
+ vi3x4567 = vi3xCDEF;
+ vi4x4567 = vi4xCDEF;
+
+ float32x4_t vo0 = vaddq_f32(vo468Ap00, vo468Ap01);
+
+ vo0 = vmaxq_f32(vo0, vmin);
+ vo0 = vminq_f32(vo0, vmax);
+
+ size_t k_tmp = (k + 1) / 2;
+ if XNN_LIKELY(k_tmp >= 4) {
+ vst1q_f32(output0, vo0);
+ output0 = (float*) ((uintptr_t) output0 + output_tuple_stride);
+ } else {
+ float* output0_lo = output0;
+ float32x2_t vo0_lo = vget_low_f32(vo0);
+ if (k_tmp & 2) {
+ vst1_f32(output0_lo, vo0_lo); output0_lo += 2;
+ vo0_lo = vget_high_f32(vo0);
+ }
+ if (k_tmp & 1) {
+ vst1_lane_f32(output0_lo, vo0_lo, 0);
+ }
+ }
+ }
+
+ {
float32x4_t vo468Ap00 = vdupq_laneq_f32(vw0123, 0);
float32x4_t vi0x89AB;
@@ -116,19 +253,17 @@
float32x4_t vi4x468A = vuzp1q_f32(vi4x4567, vi4x89AB);
float32x4_t vi4x579B = vuzp2q_f32(vi4x4567, vi4x89AB);
- if XNN_UNLIKELY(k <= 8) {
- vi0x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi0x468A)));
- vi1x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi1x468A)));
- vi2x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi2x468A)));
- vi3x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi3x468A)));
- vi4x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi4x468A)));
+ vi0x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi0x468A)));
+ vi1x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi1x468A)));
+ vi2x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi2x468A)));
+ vi3x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi3x468A)));
+ vi4x468A = vreinterpretq_u32_f32(vandq_u32(vmask_even, vreinterpretq_f32_u32(vi4x468A)));
- vi0x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi0x579B)));
- vi1x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi1x579B)));
- vi2x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi2x579B)));
- vi3x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi3x579B)));
- vi4x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi4x579B)));
- }
+ vi0x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi0x579B)));
+ vi1x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi1x579B)));
+ vi2x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi2x579B)));
+ vi3x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi3x579B)));
+ vi4x579B = vreinterpretq_u32_f32(vandq_u32(vmask_odd, vreinterpretq_f32_u32(vi4x579B)));
// middle tap
vo468Ap00 = vfmaq_laneq_f32(vo468Ap00, vi0x468A, vw0123, 3);