summaryrefslogtreecommitdiff
path: root/apps/codecs/libatrac/fixp_math.h
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2009-08-16 12:41:04 +0000
committerJens Arnold <amiconn@rockbox.org>2009-08-16 12:41:04 +0000
commit3d6f86eb2ff21f12d9f884a8271aa783f5046ae0 (patch)
tree445686f4dbced712a4c9687e525b54145491d2ed /apps/codecs/libatrac/fixp_math.h
parent90ea3e97163fc2c34c7d114af8e36e48f4c680f2 (diff)
downloadrockbox-3d6f86eb2ff21f12d9f884a8271aa783f5046ae0.tar.gz
rockbox-3d6f86eb2ff21f12d9f884a8271aa783f5046ae0.zip
Make those functions actually inline. Around 20% speedup on coldfire, 10% speedup on arm.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22344 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libatrac/fixp_math.h')
-rw-r--r--apps/codecs/libatrac/fixp_math.h69
1 files changed, 65 insertions, 4 deletions
diff --git a/apps/codecs/libatrac/fixp_math.h b/apps/codecs/libatrac/fixp_math.h
index b6621b6f1a..8a734f6b68 100644
--- a/apps/codecs/libatrac/fixp_math.h
+++ b/apps/codecs/libatrac/fixp_math.h
@@ -9,7 +9,68 @@
9#define fix31tof64(x) (float)((float)(x) / (float)(1 << 31)) 9#define fix31tof64(x) (float)((float)(x) / (float)(1 << 31))
10 10
11/* Fixed point math routines for use in atrac3.c */ 11/* Fixed point math routines for use in atrac3.c */
12inline int32_t fixmul16(int32_t x, int32_t y); 12
13inline int32_t fixmul31(int32_t x, int32_t y); 13static inline int32_t fixmul16(int32_t x, int32_t y)
14inline int32_t fixdiv16(int32_t x, int32_t y); 14{
15inline int32_t fastSqrt(int32_t n); 15 int64_t temp;
16 temp = x;
17 temp *= y;
18
19 temp >>= 16;
20
21 return (int32_t)temp;
22}
23
24static inline int32_t fixmul31(int32_t x, int32_t y)
25{
26 int64_t temp;
27 temp = x;
28 temp *= y;
29
30 temp >>= 31; //16+31-16 = 31 bits
31
32 return (int32_t)temp;
33}
34
35static inline int32_t fixdiv16(int32_t x, int32_t y)
36{
37 int64_t temp;
38 temp = x << 16;
39 temp /= y;
40
41 return (int32_t)temp;
42}
43
44/*
45 * Fast integer square root adapted from algorithm,
46 * Martin Guy @ UKC, June 1985.
47 * Originally from a book on programming abaci by Mr C. Woo.
48 * This is taken from :
49 * http://wiki.forum.nokia.com/index.php/How_to_use_fixed_point_maths#How_to_get_square_root_for_integers
50 * with a added shift up of the result by 8 bits to return result in 16.16 fixed-point representation.
51 */
52static inline int32_t fastSqrt(int32_t n)
53{
54 /*
55 * Logically, these are unsigned.
56 * We need the sign bit to test
57 * whether (op - res - one) underflowed.
58 */
59 int32_t op, res, one;
60 op = n;
61 res = 0;
62 /* "one" starts at the highest power of four <= than the argument. */
63 one = 1 << 30; /* second-to-top bit set */
64 while (one > op) one >>= 2;
65 while (one != 0)
66 {
67 if (op >= res + one)
68 {
69 op = op - (res + one);
70 res = res + (one<<1);
71 }
72 res >>= 1;
73 one >>= 2;
74 }
75 return(res << 8);
76}