Small changes to asm for better readability.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26375 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andree Buschmann 2010-05-29 14:56:25 +00:00
parent 56220785c1
commit 9ab57e510e
2 changed files with 49 additions and 46 deletions

View file

@ -31,30 +31,33 @@
/* Fixed point math routines for use in atrac3.c */ /* Fixed point math routines for use in atrac3.c */
#if defined(CPU_ARM) #if defined(CPU_ARM)
/* Calculates: result = (X*Y)>>16 */
#define fixmul16(X,Y) \ #define fixmul16(X,Y) \
({ \ ({ \
int32_t low; \ int32_t lo; \
int32_t high; \ int32_t hi; \
asm volatile ( /* calculates: result = (X*Y)>>16 */ \ asm volatile ( \
"smull %0,%1,%2,%3 \n\t" /* 64 = 32x32 multiply */ \ "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \
"mov %0, %0, lsr #16 \n\t" /* %0 = %0 >> 16 */ \ "mov %[lo], %[lo], lsr #16 \n\t" /* lo >>= 16 */ \
"orr %0, %0, %1, lsl #16 \n\t"/* result = %0 OR (%1 << 16) */ \ "orr %[lo], %[lo], %[hi], lsl #16" /* lo |= (hi << 16) */ \
: "=&r"(low), "=&r" (high) \ : [lo]"=&r"(lo), [hi]"=&r"(hi) \
: "r"(X),"r"(Y)); \ : [x]"r"(X), [y]"r"(Y)); \
low; \ lo; \
}) })
/* Calculates: result = (X*Y)>>31 */
/* Use scratch register r12 */
#define fixmul31(X,Y) \ #define fixmul31(X,Y) \
({ \ ({ \
int32_t low; \ int32_t lo; \
int32_t high; \ int32_t hi; \
asm volatile ( /* calculates: result = (X*Y)>>31 */ \ asm volatile ( \
"smull %0,%1,%2,%3 \n\t" /* 64 = 32x32 multiply */ \ "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \
"mov %0, %0, lsr #31 \n\t" /* %0 = %0 >> 31 */ \ "mov %[lo], %[lo], lsr #31 \n\t" /* lo >>= 31 */ \
"orr %0, %0, %1, lsl #1 \n\t" /* result = %0 OR (%1 << 1) */ \ "orr %[lo], %[lo], %[hi], lsl #1" /* lo |= (hi << 1) */ \
: "=&r"(low), "=&r" (high) \ : [lo]"=&r"(lo), [hi]"=&r"(hi) \
: "r"(X),"r"(Y)); \ : [x]"r"(X), [y]"r"(Y)); \
low; \ lo; \
}) })
#elif defined(CPU_COLDFIRE) #elif defined(CPU_COLDFIRE)
#define fixmul16(X,Y) \ #define fixmul16(X,Y) \

View file

@ -115,32 +115,32 @@
return t1; return t1;
} }
#elif defined(CPU_ARM) #elif defined(CPU_ARM)
// borrowed and adapted from libMAD /* Calculate: result = (X*Y)>>14 */
#define MPC_MULTIPLY(X,Y) \ #define MPC_MULTIPLY(X,Y) \
({ \ ({ \
MPC_SAMPLE_FORMAT low; \ MPC_SAMPLE_FORMAT lo; \
MPC_SAMPLE_FORMAT high; \ MPC_SAMPLE_FORMAT hi; \
asm volatile ( /* will calculate: result = (X*Y)>>14 */ \ asm volatile ( \
"smull %0,%1,%2,%3 \n\t" /* multiply with result %0 [0..31], %1 [32..63] */ \ "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \
"mov %0, %0, lsr #14 \n\t" /* %0 = %0 >> 14 */ \ "mov %[lo], %[lo], lsr #14 \n\t" /* lo >>= 14 */ \
"orr %0, %0, %1, lsl #18 \n\t"/* result = %0 OR (%1 << 18) */ \ "orr %[lo], %[lo], %[hi], lsl #18" /* lo |= (hi << 18) */ \
: "=&r"(low), "=&r" (high) \ : [lo]"=&r"(lo), [hi]"=&r"(hi) \
: "r"(X),"r"(Y)); \ : [x]"r"(X), [y]"r"(Y)); \
low; \ lo; \
}) })
// borrowed and adapted from libMAD /* Calculate: result = (X*Y)>>Z */
#define MPC_MULTIPLY_EX(X,Y,Z) \ #define MPC_MULTIPLY_EX(X,Y,Z) \
({ \ ({ \
MPC_SAMPLE_FORMAT low; \ MPC_SAMPLE_FORMAT lo; \
MPC_SAMPLE_FORMAT high; \ MPC_SAMPLE_FORMAT hi; \
asm volatile ( /* will calculate: result = (X*Y)>>Z */ \ asm volatile ( \
"smull %0,%1,%2,%3 \n\t" /* multiply with result %0 [0..31], %1 [32..63] */ \ "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \
"mov %0, %0, lsr %4 \n\t" /* %0 = %0 >> Z */ \ "mov %[lo], %[lo], lsr %[shr] \n\t" /* lo >>= Z */ \
"orr %0, %0, %1, lsl %5 \n\t" /* result = %0 OR (%1 << (32-Z)) */ \ "orr %[lo], %[lo], %[hi], lsl %[shl]" /* lo |= (hi << (32-Z)) */ \
: "=&r"(low), "=&r" (high) \ : [lo]"=&r"(lo), [hi]"=&r"(hi) \
: "r"(X),"r"(Y),"r"(Z),"r"(32-Z)); \ : [x]"r"(X), [y]"r"(Y), [shr]"r"(Z), [shl]"r"(32-Z)); \
low; \ lo; \
}) })
#else /* libmusepack standard */ #else /* libmusepack standard */
@ -188,16 +188,16 @@
t; \ t; \
}) })
#elif defined(CPU_ARM) #elif defined(CPU_ARM)
// borrowed and adapted from libMAD /* Calculate: result = (X*Y)>>32, without need for >>32 */
#define MPC_MULTIPLY_FRACT(X,Y) \ #define MPC_MULTIPLY_FRACT(X,Y) \
({ \ ({ \
MPC_SAMPLE_FORMAT low; \ MPC_SAMPLE_FORMAT lo; \
MPC_SAMPLE_FORMAT high; \ MPC_SAMPLE_FORMAT hi; \
asm volatile ( /* will calculate: result = (X*Y)>>32 */ \ asm volatile ( \
"smull %0,%1,%2,%3 \n\t" /* multiply with result %0 [0..31], %1 [32..63] */ \ "smull %[lo], %[hi], %[x], %[y]" /* hi = result */ \
: "=&r"(low), "=&r" (high) /* result = %1 [32..63], saves the >>32 */ \ : [lo]"=&r"(lo), [hi]"=&r"(hi) \
: "r"(X),"r"(Y)); \ : [x]"r"(X), [y]"r"(Y)); \
high; \ hi; \
}) })
#else #else
#define MPC_MULTIPLY_FRACT(X,Y) MPC_MULTIPLY_EX(X,Y,32) #define MPC_MULTIPLY_FRACT(X,Y) MPC_MULTIPLY_EX(X,Y,32)