summaryrefslogtreecommitdiff
path: root/apps/codecs/libatrac/fixp_math.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libatrac/fixp_math.h')
-rw-r--r--apps/codecs/libatrac/fixp_math.h58
1 files changed, 34 insertions, 24 deletions
diff --git a/apps/codecs/libatrac/fixp_math.h b/apps/codecs/libatrac/fixp_math.h
index 88cb5e4b66..5174cc7cc6 100644
--- a/apps/codecs/libatrac/fixp_math.h
+++ b/apps/codecs/libatrac/fixp_math.h
@@ -36,17 +36,38 @@
36 : "r"(X),"r"(Y)); \ 36 : "r"(X),"r"(Y)); \
37 low; \ 37 low; \
38 }) 38 })
39 39#elif defined(CPU_COLDFIRE)
40 #define fixmul32(X,Y) \ 40 #define fixmul16(X,Y) \
41 ({ \ 41 ({ \
42 int32_t low; \ 42 int32_t t1, t2; \
43 int32_t high; \ 43 asm volatile ( \
44 asm volatile ( /* calculates: result = (X*Y)>>32 */ \ 44 "mac.l %[x],%[y],%%acc0\n\t" /* multiply */ \
45 "smull %0,%1,%2,%3 \n\t" /* 64 = 32x32 multiply */ \ 45 "mulu.l %[y],%[x] \n\t" /* get lower half, avoid emac stall */ \
46 : "=&r"(low), "=&r" (high) \ 46 "movclr.l %%acc0,%[t1] \n\t" /* get higher half */ \
47 : "r"(X),"r"(Y)); \ 47 "moveq.l #15,%[t2] \n\t" \
48 high; \ 48 "asl.l %[t2],%[t1] \n\t" /* hi <<= 15, plus one free */ \
49 }) 49 "moveq.l #16,%[t2] \n\t" \
50 "lsr.l %[t2],%[x] \n\t" /* (unsigned)lo >>= 16 */ \
51 "or.l %[x],%[t1] \n\t" /* combine result */ \
52 : /* outputs */ \
53 [t1]"=&d"(t1), \
54 [t2]"=&d"(t2) \
55 : /* inputs */ \
56 [x] "d" ((X)), \
57 [y] "d" ((Y))); \
58 t1; \
59 })
60
61 #define fixmul31(X,Y) \
62 ({ \
63 int32_t t; \
64 asm volatile ( \
65 "mac.l %[x], %[y], %%acc0\n\t" /* multiply */ \
66 "movclr.l %%acc0, %[t]\n\t" /* get higher half as result */ \
67 : [t] "=d" (t) \
68 : [x] "r" ((X)), [y] "r" ((Y))); \
69 t; \
70 })
50#else 71#else
51 static inline int32_t fixmul16(int32_t x, int32_t y) 72 static inline int32_t fixmul16(int32_t x, int32_t y)
52 { 73 {
@@ -69,17 +90,6 @@
69 90
70 return (int32_t)temp; 91 return (int32_t)temp;
71 } 92 }
72
73 static inline int32_t fixmul32(int32_t x, int32_t y)
74 {
75 int64_t temp;
76 temp = x;
77 temp *= y;
78
79 temp >>= 32; //16+31-16 = 31 bits
80
81 return (int32_t)temp;
82 }
83#endif 93#endif
84 94
85static inline int32_t fixdiv16(int32_t x, int32_t y) 95static inline int32_t fixdiv16(int32_t x, int32_t y)
@@ -104,13 +114,13 @@ static inline int32_t fastSqrt(int32_t n)
104 /* 114 /*
105 * Logically, these are unsigned. 115 * Logically, these are unsigned.
106 * We need the sign bit to test 116 * We need the sign bit to test
107 * whether (op - res - one) underflowed. 117 * whether (op - res - one) underflowed.
108 */ 118 */
109 int32_t op, res, one; 119 int32_t op, res, one;
110 op = n; 120 op = n;
111 res = 0; 121 res = 0;
112 /* "one" starts at the highest power of four <= than the argument. */ 122 /* "one" starts at the highest power of four <= than the argument. */
113 one = 1 << 30; /* second-to-top bit set */ 123 one = 1 << 30; /* second-to-top bit set */
114 while (one > op) one >>= 2; 124 while (one > op) one >>= 2;
115 while (one != 0) 125 while (one != 0)
116 { 126 {