summaryrefslogtreecommitdiff
path: root/apps/codecs/lib/fixedpoint.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/lib/fixedpoint.h')
-rw-r--r--apps/codecs/lib/fixedpoint.h126
1 files changed, 126 insertions, 0 deletions
diff --git a/apps/codecs/lib/fixedpoint.h b/apps/codecs/lib/fixedpoint.h
new file mode 100644
index 0000000000..54ece27080
--- /dev/null
+++ b/apps/codecs/lib/fixedpoint.h
@@ -0,0 +1,126 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: fixedpoint.h -1 $
9 *
10 * Copyright (C) 2006 Jens Arnold
11 *
12 * Fixed point library for plugins
13 *
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.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#ifndef _FIXEDPOINT_H
25#define _FIXEDPOINT_H
26
27#include <inttypes.h>
28
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.
34 */
35
36/* Multiply two S.31 fractional integers and return the sign bit and the
37 * 31 most significant bits of the result.
38 */
39#define FRACMUL(x, y) \
40({ \
41 long t; \
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)); \
45 t; \
46})
47
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
50 * 1 to 8 on Coldfire!
51 */
52#define FRACMUL_SHL(x, y, z) \
53({ \
54 long t, t2; \
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))); \
66 t; \
67})
68
69#elif defined(CPU_ARM)
70
71/* Multiply two S.31 fractional integers and return the sign bit and the
72 * 31 most significant bits of the result.
73 */
74#define FRACMUL(x, y) \
75({ \
76 long t, t2; \
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)); \
82 t; \
83})
84
85/* Multiply two S.31 fractional integers, and return the 32 most significant
86 * bits after a shift left by the constant z.
87 */
88#define FRACMUL_SHL(x, y, z) \
89({ \
90 long t, t2; \
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))); \
97 t; \
98})
99
100#else
101
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)))))
105
106#endif
107
108#define DIV64(x, y, z) (long)(((long long)(x) << (z))/(y))
109
110
111/** TAKEN FROM ORIGINAL fixedpoint.h */
112/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
113 * whichever is faster for the architecture) */
114#ifdef CPU_ARM
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))))
118#endif
119
120long fsincos(unsigned long phase, long *cos);
121long fsqrt(long a, unsigned int fracbits);
122long cos_int(int val);
123long sin_int(int val);
124long flog(int x);
125
126#endif