diff options
Diffstat (limited to 'apps/codecs/libatrac/fixp_math.h')
-rw-r--r-- | apps/codecs/libatrac/fixp_math.h | 92 |
1 files changed, 71 insertions, 21 deletions
diff --git a/apps/codecs/libatrac/fixp_math.h b/apps/codecs/libatrac/fixp_math.h index 8a734f6b68..88cb5e4b66 100644 --- a/apps/codecs/libatrac/fixp_math.h +++ b/apps/codecs/libatrac/fixp_math.h | |||
@@ -10,27 +10,77 @@ | |||
10 | 10 | ||
11 | /* Fixed point math routines for use in atrac3.c */ | 11 | /* Fixed point math routines for use in atrac3.c */ |
12 | 12 | ||
13 | static inline int32_t fixmul16(int32_t x, int32_t y) | 13 | #if defined(CPU_ARM) |
14 | { | 14 | #define fixmul16(X,Y) \ |
15 | int64_t temp; | 15 | ({ \ |
16 | temp = x; | 16 | int32_t low; \ |
17 | temp *= y; | 17 | int32_t high; \ |
18 | 18 | asm volatile ( /* calculates: result = (X*Y)>>16 */ \ | |
19 | temp >>= 16; | 19 | "smull %0,%1,%2,%3 \n\t" /* 64 = 32x32 multiply */ \ |
20 | 20 | "mov %0, %0, lsr #16 \n\t" /* %0 = %0 >> 16 */ \ | |
21 | return (int32_t)temp; | 21 | "orr %0, %0, %1, lsl #16 \n\t"/* result = %0 OR (%1 << 16) */ \ |
22 | } | 22 | : "=&r"(low), "=&r" (high) \ |
23 | 23 | : "r"(X),"r"(Y)); \ | |
24 | static inline int32_t fixmul31(int32_t x, int32_t y) | 24 | low; \ |
25 | { | 25 | }) |
26 | int64_t temp; | 26 | |
27 | temp = x; | 27 | #define fixmul31(X,Y) \ |
28 | temp *= y; | 28 | ({ \ |
29 | 29 | int32_t low; \ | |
30 | temp >>= 31; //16+31-16 = 31 bits | 30 | int32_t high; \ |
31 | 31 | asm volatile ( /* calculates: result = (X*Y)>>31 */ \ | |
32 | return (int32_t)temp; | 32 | "smull %0,%1,%2,%3 \n\t" /* 64 = 32x32 multiply */ \ |
33 | } | 33 | "mov %0, %0, lsr #31 \n\t" /* %0 = %0 >> 31 */ \ |
34 | "orr %0, %0, %1, lsl #1 \n\t" /* result = %0 OR (%1 << 1) */ \ | ||
35 | : "=&r"(low), "=&r" (high) \ | ||
36 | : "r"(X),"r"(Y)); \ | ||
37 | low; \ | ||
38 | }) | ||
39 | |||
40 | #define fixmul32(X,Y) \ | ||
41 | ({ \ | ||
42 | int32_t low; \ | ||
43 | int32_t high; \ | ||
44 | asm volatile ( /* calculates: result = (X*Y)>>32 */ \ | ||
45 | "smull %0,%1,%2,%3 \n\t" /* 64 = 32x32 multiply */ \ | ||
46 | : "=&r"(low), "=&r" (high) \ | ||
47 | : "r"(X),"r"(Y)); \ | ||
48 | high; \ | ||
49 | }) | ||
50 | #else | ||
51 | static inline int32_t fixmul16(int32_t x, int32_t y) | ||
52 | { | ||
53 | int64_t temp; | ||
54 | temp = x; | ||
55 | temp *= y; | ||
56 | |||
57 | temp >>= 16; | ||
58 | |||
59 | return (int32_t)temp; | ||
60 | } | ||
61 | |||
62 | static inline int32_t fixmul31(int32_t x, int32_t y) | ||
63 | { | ||
64 | int64_t temp; | ||
65 | temp = x; | ||
66 | temp *= y; | ||
67 | |||
68 | temp >>= 31; //16+31-16 = 31 bits | ||
69 | |||
70 | return (int32_t)temp; | ||
71 | } | ||
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 | ||
34 | 84 | ||
35 | static inline int32_t fixdiv16(int32_t x, int32_t y) | 85 | static inline int32_t fixdiv16(int32_t x, int32_t y) |
36 | { | 86 | { |