1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*
** FAAD - Freeware Advanced Audio Decoder
** Copyright (C) 2002 M. Bakker
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** $Id: fixed.h,v 1.2 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __FIXED_H__
#define __FIXED_H__
#ifdef __cplusplus
extern "C" {
#endif
#define COEF_BITS 28
#define COEF_PRECISION (1 << COEF_BITS)
#define REAL_BITS 7
#define REAL_PRECISION (1 << REAL_BITS)
typedef int32_t real_t;
#define REAL_CONST(A) ((real_t)(A*(REAL_PRECISION)))
#define COEF_CONST(A) ((real_t)(A*(COEF_PRECISION)))
#if defined(_WIN32) && !defined(_WIN32_WCE)
/* multiply real with real */
static INLINE MUL(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,REAL_BITS
}
}
/* multiply coef with coef */
static INLINE MUL_C_C(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,COEF_BITS
}
}
/* multiply real with coef */
static INLINE MUL_R_C(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,COEF_BITS
}
}
#elif defined(__GNUC__) && defined (__arm__)
/* taken from MAD */
#define arm_mul(x, y, SCALEBITS) \
({ uint32_t __hi; \
uint32_t __lo; \
uint32_t __result; \
asm ("smull %0, %1, %3, %4\n\t" \
"movs %0, %0, lsr %5\n\t" \
"adc %2, %0, %1, lsl %6" \
: "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
: "%r" (x), "r" (y), \
"M" (SCALEBITS), "M" (32 - (SCALEBITS)) \
: "cc"); \
__result; \
})
static INLINE real_t MUL(real_t A, real_t B)
{
return arm_mul( A, B, REAL_BITS);
}
static INLINE real_t MUL_C_C(real_t A, real_t B)
{
return arm_mul( A, B, COEF_BITS);
}
static INLINE real_t MUL_R_C(real_t A, real_t B)
{
return arm_mul( A, B, COEF_BITS);
}
#else
/* multiply real with real */
#define MUL(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (REAL_BITS-1))) >> REAL_BITS)
/* multiply coef with coef */
#define MUL_C_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS)
/* multiply real with coef */
#define MUL_R_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS)
#endif
#ifdef __cplusplus
}
#endif
#endif
|