diff --git a/src/common_audio/signal_processing/include/spl_inl_armv7.h b/src/common_audio/signal_processing/include/spl_inl_armv7.h index 2eff496b8..8461474fb 100644 --- a/src/common_audio/signal_processing/include/spl_inl_armv7.h +++ b/src/common_audio/signal_processing/include/spl_inl_armv7.h @@ -64,6 +64,7 @@ static __inline WebRtc_Word32 WEBRTC_SPL_MUL_16_16(WebRtc_Word16 a, return tmp; } +// TODO(kma): add unit test. static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { @@ -124,7 +125,12 @@ static __inline WebRtc_Word16 WebRtcSpl_GetSizeInBits(WebRtc_UWord32 n) { static __inline int WebRtcSpl_NormW32(WebRtc_Word32 a) { WebRtc_Word32 tmp = 0; - if (a <= 0) a ^= 0xFFFFFFFF; + if (a == 0) { + return 0; + } + else if (a < 0) { + a ^= 0xFFFFFFFF; + } __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a)); @@ -144,13 +150,19 @@ static __inline int WebRtcSpl_NormU32(WebRtc_UWord32 a) { static __inline int WebRtcSpl_NormW16(WebRtc_Word16 a) { WebRtc_Word32 tmp = 0; - if (a <= 0) a ^= 0xFFFFFFFF; + if (a == 0) { + return 0; + } + else if (a < 0) { + a ^= 0xFFFFFFFF; + } __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a)); return tmp - 17; } +// TODO(kma): add unit test. static __inline WebRtc_Word16 WebRtcSpl_SatW32ToW16(WebRtc_Word32 value32) { WebRtc_Word16 out16 = 0; @@ -158,4 +170,5 @@ static __inline WebRtc_Word16 WebRtcSpl_SatW32ToW16(WebRtc_Word32 value32) { return out16; } + #endif // WEBRTC_SPL_SPL_INL_ARMV7_H_ diff --git a/src/common_audio/signal_processing/signal_processing_unittest.cc b/src/common_audio/signal_processing/signal_processing_unittest.cc index e20ed74e8..d5026fb88 100644 --- a/src/common_audio/signal_processing/signal_processing_unittest.cc +++ b/src/common_audio/signal_processing/signal_processing_unittest.cc @@ -138,8 +138,20 @@ TEST_F(SplTest, InlineTest) { char bVersion[8]; EXPECT_EQ(17, WebRtcSpl_GetSizeInBits(a32)); + + EXPECT_EQ(0, WebRtcSpl_NormW32(0)); + EXPECT_EQ(31, WebRtcSpl_NormW32(-1)); + EXPECT_EQ(0, WebRtcSpl_NormW32(WEBRTC_SPL_WORD32_MIN)); EXPECT_EQ(14, WebRtcSpl_NormW32(a32)); + + EXPECT_EQ(0, WebRtcSpl_NormW16(0)); + EXPECT_EQ(15, WebRtcSpl_NormW16(-1)); + EXPECT_EQ(0, WebRtcSpl_NormW16(WEBRTC_SPL_WORD16_MIN)); EXPECT_EQ(4, WebRtcSpl_NormW16(b32)); + + EXPECT_EQ(0, WebRtcSpl_NormU32(0)); + EXPECT_EQ(0, WebRtcSpl_NormU32(-1)); + EXPECT_EQ(0, WebRtcSpl_NormU32(WEBRTC_SPL_WORD32_MIN)); EXPECT_EQ(15, WebRtcSpl_NormU32(a32)); EXPECT_EQ(104, WebRtcSpl_AddSatW16(a16, b16)); @@ -147,6 +159,7 @@ TEST_F(SplTest, InlineTest) { EXPECT_EQ(109410, WebRtcSpl_AddSatW32(a32, b32)); EXPECT_EQ(112832, WebRtcSpl_SubSatW32(a32, b32)); + a32 = 0x80000000; b32 = 0x80000000; // Cast to signed int to avoid compiler complaint on gtest.h.