1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: fixedpoint.h -1 $
10 * Copyright (C) 2006 Jens Arnold
12 * Fixed point library for plugins
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
29 /** TAKEN FROM apps/dsp.h */
30 /* A bunch of fixed point assembler helper macros */
31 #if defined(CPU_COLDFIRE)
32 /* These macros use the Coldfire EMAC extension and need the MACSR flags set
33 * to fractional mode with no rounding.
36 /* Multiply two S.31 fractional integers and return the sign bit and the
37 * 31 most significant bits of the result.
39 #define FRACMUL(x, y) \
42 asm ("mac.l %[a], %[b], %%acc0\n\t" \
43 "movclr.l %%acc0, %[t]\n\t" \
44 : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
48 /* Multiply two S.31 fractional integers, and return the 32 most significant
49 * bits after a shift left by the constant z. NOTE: Only works for shifts of
52 #define FRACMUL_SHL(x, y, z) \
55 asm ("mac.l %[a], %[b], %%acc0\n\t" \
56 "moveq.l %[d], %[t]\n\t" \
57 "move.l %%accext01, %[t2]\n\t" \
58 "and.l %[mask], %[t2]\n\t" \
59 "lsr.l %[t], %[t2]\n\t" \
60 "movclr.l %%acc0, %[t]\n\t" \
61 "asl.l %[c], %[t]\n\t" \
62 "or.l %[t2], %[t]\n\t" \
63 : [t] "=&d" (t), [t2] "=&d" (t2) \
64 : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \
65 [c] "i" ((z)), [d] "i" (8 - (z))); \
69 #elif defined(CPU_ARM)
71 /* Multiply two S.31 fractional integers and return the sign bit and the
72 * 31 most significant bits of the result.
74 #define FRACMUL(x, y) \
77 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
78 "mov %[t2], %[t2], asl #1\n\t" \
79 "orr %[t], %[t2], %[t], lsr #31\n\t" \
80 : [t] "=&r" (t), [t2] "=&r" (t2) \
81 : [a] "r" (x), [b] "r" (y)); \
85 /* Multiply two S.31 fractional integers, and return the 32 most significant
86 * bits after a shift left by the constant z.
88 #define FRACMUL_SHL(x, y, z) \
91 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
92 "mov %[t2], %[t2], asl %[c]\n\t" \
93 "orr %[t], %[t2], %[t], lsr %[d]\n\t" \
94 : [t] "=&r" (t), [t2] "=&r" (t2) \
95 : [a] "r" (x), [b] "r" (y), \
96 [c] "M" ((z) + 1), [d] "M" (31 - (z))); \
102 #define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31))
103 #define FRACMUL_SHL(x, y, z) \
104 ((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z)))))
108 #define DIV64(x, y, z) (long)(((long long)(x) << (z))/(y))
111 /** TAKEN FROM ORIGINAL fixedpoint.h */
112 /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
113 * whichever is faster for the architecture) */
115 #define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
116 #else /* SH1, coldfire */
117 #define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
120 long fsincos(unsigned long phase
, long *cos
);
121 long fsqrt(long a
, unsigned int fracbits
);
122 long cos_int(int val
);
123 long sin_int(int val
);