From 94c7c908b3713d1e2046e7d0047754cd045ddd03 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Thu, 16 Jan 2025 11:58:54 +0000 Subject: [PATCH] libmusepack: add ARMv7-M version of MPC_MULTIPLY_EX We can't use Operand2 with register based shifts on ARMv7-M as it isn't supported in the Thumb encoding. Instead, perform the shift separately. Change-Id: Ie96aa0a565e98bbca724dffc2ffc6d64fdb5d7c3 --- lib/rbcodec/codecs/libmusepack/mpcdec_math.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/rbcodec/codecs/libmusepack/mpcdec_math.h b/lib/rbcodec/codecs/libmusepack/mpcdec_math.h index 955681f4e5..6b998a50c0 100644 --- a/lib/rbcodec/codecs/libmusepack/mpcdec_math.h +++ b/lib/rbcodec/codecs/libmusepack/mpcdec_math.h @@ -128,7 +128,23 @@ : [x]"r"(X), [y]"r"(Y)); \ lo; \ }) - + + #if defined (CPU_ARM_MICRO) + /* Calculate: result = (X*Y)>>Z */ + #define MPC_MULTIPLY_EX(X,Y,Z) \ + ({ \ + MPC_SAMPLE_FORMAT lo; \ + MPC_SAMPLE_FORMAT hi; \ + asm volatile ( \ + "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \ + "mov %[lo], %[lo], lsr %[shr] \n\t" /* lo >>= Z */ \ + "lsl %[hi], %[hi], %[shl] \n\t" /* hi <<= 32 - Z */ \ + "orr %[lo], %[lo], %[hi] \n\t" /* lo |= hi */ \ + : [lo]"=&r"(lo), [hi]"=&r"(hi) \ + : [x]"r"(X), [y]"r"(Y), [shr]"r"(Z), [shl]"r"(32-Z)); \ + lo; \ + }) + #else /* Calculate: result = (X*Y)>>Z */ #define MPC_MULTIPLY_EX(X,Y,Z) \ ({ \ @@ -142,6 +158,7 @@ : [x]"r"(X), [y]"r"(Y), [shr]"r"(Z), [shl]"r"(32-Z)); \ lo; \ }) + #endif #else /* libmusepack standard */ #define MPC_MULTIPLY_NOTRUNCATE(X,Y) \