1 /****************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 Michael Giacomelli
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 /* fixed precision code. We use a combination of Sign 15.16 and Sign.31
24 The WMA decoder does not always follow this convention, and occasionally
25 renormalizes values to other formats in order to maximize precision.
26 However, only the two precisions above are provided in this file.
33 #define PRECISION64 16
36 #define fixtof64(x) (float)((float)(x) / (float)(1 << PRECISION64)) //does not work on int64_t!
37 #define ftofix32(x) ((fixed32)((x) * (float)(1 << PRECISION) + ((x) < 0 ? -0.5 : 0.5)))
38 #define itofix64(x) (IntTo64(x))
39 #define itofix32(x) ((x) << PRECISION)
40 #define fixtoi32(x) ((x) >> PRECISION)
41 #define fixtoi64(x) (IntFrom64(x))
46 fixed64
IntTo64(int x
);
47 int IntFrom64(fixed64 x
);
48 fixed32
Fixed32From64(fixed64 x
);
49 fixed64
Fixed32To64(fixed32 x
);
50 fixed32
fixdiv32(fixed32 x
, fixed32 y
);
51 fixed64
fixdiv64(fixed64 x
, fixed64 y
);
52 fixed32
fixsqrt32(fixed32 x
);
53 long fsincos(unsigned long phase
, fixed32
*cos
);
58 /*Sign-15.16 format */
59 #define fixmul32(x, y) \
63 asm ("smull %0, %1, %3, %4\n\t" \
64 "movs %0, %0, lsr %5\n\t" \
65 "adc %2, %0, %1, lsl %6" \
66 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
67 : "%r" (x), "r" (y), \
68 "M" (PRECISION), "M" (32 - PRECISION) \
73 #elif defined(CPU_COLDFIRE)
75 static inline int32_t fixmul32(int32_t x
, int32_t y
)
78 #warning Coldfire fixmul32() only works for PRECISION == 16
82 "mac.l %[x], %[y], %%acc0 \n" // multiply
83 "mulu.l %[y], %[x] \n" // get lower half, avoid emac stall
84 "movclr.l %%acc0, %[t1] \n" // get higher half
86 "move.w %[t1], %[x] \n"
88 : [t1
] "=&d" (t1
), [x
] "+d" (x
)
96 static inline fixed32
fixmul32(fixed32 x
, fixed32 y
)
104 return (fixed32
)temp
;
110 /* Inverse gain of circular cordic rotation in s0.31 format. */
111 long fsincos(unsigned long phase
, fixed32
*cos
);