Skip to content

Commit 247aa22

Browse files
SiarheiVolkaujmvalin
authored andcommitted
MIPS: silk: optimize silk_SMULWB for MIPS32+
MIPS32 has 32x32=>64bit multiplication, although shifting 64-bit result isn't trivial so its worth to shift right 64-bit value to 32 it means just drop LSB register of the result. Since second argument of silk_SMULWB is 16-bit wide we can shift it left by 16 before multiplication to apply technique above to the result. Signed-off-by: Siarhei Volkau <[email protected]> Signed-off-by: Jean-Marc Valin <[email protected]>
1 parent 260679b commit 247aa22

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

silk/SigProc_FIX.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,13 @@ static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
600600
#define RAND_INCREMENT 907633515
601601
#define silk_RAND(seed) (silk_MLA_ovflw((RAND_INCREMENT), (seed), (RAND_MULTIPLIER)))
602602

603-
/* Add some multiplication functions that can be easily mapped to ARM. */
603+
/* Add some multiplication functions that can be easily mapped to ARM/MIPS32. */
604604

605605
/* silk_SMMUL: Signed top word multiply.
606606
ARMv6 2 instruction cycles.
607-
ARMv3M+ 3 instruction cycles. use SMULL and ignore LSB registers.(except xM)*/
607+
ARMv3M+ 3 instruction cycles. use SMULL and ignore LSB registers.(except xM)
608+
MIPS32 2 instructions mul+mfhi
609+
MIPS32r6 1 instruction muh */
608610
/*#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT(silk_SMLAL(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)), 16)*/
609611
/* the following seems faster on x86 */
610612
#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT64(silk_SMULL((a32), (b32)), 32)

silk/macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ POSSIBILITY OF SUCH DAMAGE.
104104
(( (a) & ((b)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a)-(b)) : \
105105
((((a)^0x80000000) & (b) & 0x80000000) ? silk_int32_MAX : (a)-(b)) )
106106

107-
#if defined(FIXED_POINT) && defined(__mips_dsp) && __mips == 32
107+
#if defined(FIXED_POINT) && defined(__mips)
108108
#include "mips/macros_mipsr1.h"
109109
#endif
110110

silk/mips/macros_mipsr1.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static inline int mips_clz(opus_uint32 x)
3434
return x ? __builtin_clz(x) : 32;
3535
}
3636

37+
#if defined (__mips_dsp) && __mips == 32
38+
3739
#undef silk_SMULWB
3840
static inline int silk_SMULWB(int a, int b)
3941
{
@@ -92,4 +94,17 @@ static inline opus_int32 silk_CLZ32(opus_int32 in32)
9294
return re32;
9395
}
9496

97+
98+
#elif defined (__mips_isa_rev) && __mips == 32
99+
100+
#undef silk_SMULWB
101+
static inline int silk_SMULWB(int a, int b)
102+
{
103+
long long ac = (long long)a * (int)(b << 16);
104+
105+
return ac >> 32;
106+
}
107+
108+
#endif
109+
95110
#endif /* SILK_MACROS_MIPSR1_H__ */

0 commit comments

Comments
 (0)