Mercurial > mplayer.hg
annotate libfaad2/fixed.h @ 13327:a614fe71ad74
small fixes
author | diego |
---|---|
date | Sun, 12 Sep 2004 16:42:26 +0000 |
parents | d81145997036 |
children | 6d50ef45a058 |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
12527 | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
10725 | 4 ** |
5 ** This program is free software; you can redistribute it and/or modify | |
6 ** it under the terms of the GNU General Public License as published by | |
7 ** the Free Software Foundation; either version 2 of the License, or | |
8 ** (at your option) any later version. | |
9 ** | |
10 ** This program is distributed in the hope that it will be useful, | |
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ** GNU General Public License for more details. | |
14 ** | |
15 ** You should have received a copy of the GNU General Public License | |
16 ** along with this program; if not, write to the Free Software | |
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 ** | |
19 ** Any non-GPL usage of this software or parts of this software is strictly | |
20 ** forbidden. | |
21 ** | |
22 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 |
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
26 ** $Id: fixed.h,v 1.3 2004/06/02 22:59:03 diego Exp $ |
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
10725 | 28 **/ |
29 | |
30 #ifndef __FIXED_H__ | |
31 #define __FIXED_H__ | |
32 | |
33 #ifdef __cplusplus | |
34 extern "C" { | |
35 #endif | |
36 | |
12527 | 37 #ifdef _WIN32_WCE |
38 #include <cmnintrin.h> | |
39 #endif | |
10725 | 40 |
41 #define COEF_BITS 28 | |
42 #define COEF_PRECISION (1 << COEF_BITS) | |
10989 | 43 #define REAL_BITS 14 // MAXIMUM OF 14 FOR FIXED POINT SBR |
10725 | 44 #define REAL_PRECISION (1 << REAL_BITS) |
45 | |
12527 | 46 /* FRAC is the fractional only part of the fixed point number [0.0..1.0) */ |
47 #define FRAC_SIZE 32 /* frac is a 32 bit integer */ | |
48 #define FRAC_BITS 31 | |
49 #define FRAC_PRECISION ((uint32_t)(1 << FRAC_BITS)) | |
50 #define FRAC_MAX 0x7FFFFFFF | |
10725 | 51 |
52 typedef int32_t real_t; | |
53 | |
54 | |
12527 | 55 #define REAL_CONST(A) (((A) >= 0) ? ((real_t)((A)*(REAL_PRECISION)+0.5)) : ((real_t)((A)*(REAL_PRECISION)-0.5))) |
56 #define COEF_CONST(A) (((A) >= 0) ? ((real_t)((A)*(COEF_PRECISION)+0.5)) : ((real_t)((A)*(COEF_PRECISION)-0.5))) | |
57 #define FRAC_CONST(A) (((A) == 1.00) ? ((real_t)FRAC_MAX) : (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5)))) | |
10725 | 58 |
59 #if defined(_WIN32) && !defined(_WIN32_WCE) | |
60 | |
12527 | 61 /* multiply with real shift */ |
62 static INLINE real_t MUL_R(real_t A, real_t B) | |
10725 | 63 { |
64 _asm { | |
65 mov eax,A | |
66 imul B | |
67 shrd eax,edx,REAL_BITS | |
68 } | |
69 } | |
70 | |
12527 | 71 /* multiply with coef shift */ |
72 static INLINE real_t MUL_C(real_t A, real_t B) | |
10725 | 73 { |
74 _asm { | |
75 mov eax,A | |
76 imul B | |
77 shrd eax,edx,COEF_BITS | |
78 } | |
79 } | |
80 | |
12527 | 81 static INLINE real_t _MulHigh(real_t A, real_t B) |
10725 | 82 { |
83 _asm { | |
84 mov eax,A | |
85 imul B | |
12527 | 86 mov eax,edx |
10725 | 87 } |
88 } | |
89 | |
12527 | 90 /* multiply with fractional shift */ |
91 static INLINE real_t MUL_F(real_t A, real_t B) | |
92 { | |
93 return _MulHigh(A,B) << (FRAC_SIZE-FRAC_BITS); | |
94 } | |
95 | |
96 /* Complex multiplication */ | |
97 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
98 real_t x1, real_t x2, real_t c1, real_t c2) | |
99 { | |
100 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS); | |
101 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS); | |
102 } | |
103 | |
10725 | 104 #elif defined(__GNUC__) && defined (__arm__) |
105 | |
106 /* taken from MAD */ | |
107 #define arm_mul(x, y, SCALEBITS) \ | |
12527 | 108 ({ \ |
109 uint32_t __hi; \ | |
110 uint32_t __lo; \ | |
111 uint32_t __result; \ | |
112 asm("smull %0, %1, %3, %4\n\t" \ | |
113 "movs %0, %0, lsr %5\n\t" \ | |
114 "adc %2, %0, %1, lsl %6" \ | |
115 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \ | |
116 : "%r" (x), "r" (y), \ | |
117 "M" (SCALEBITS), "M" (32 - (SCALEBITS)) \ | |
118 : "cc"); \ | |
119 __result; \ | |
120 }) | |
10725 | 121 |
12527 | 122 static INLINE real_t MUL_R(real_t A, real_t B) |
10725 | 123 { |
12527 | 124 return arm_mul(A, B, REAL_BITS); |
125 } | |
126 | |
127 static INLINE real_t MUL_C(real_t A, real_t B) | |
128 { | |
129 return arm_mul(A, B, COEF_BITS); | |
10725 | 130 } |
131 | |
12527 | 132 static INLINE real_t _MulHigh(real_t x, real_t y) |
10725 | 133 { |
12527 | 134 uint32_t __lo; |
135 uint32_t __hi; | |
136 asm("smull\t%0, %1, %2, %3" | |
137 : "=&r"(__lo),"=&r"(__hi) | |
138 : "%r"(x),"r"(y) | |
139 : "cc"); | |
140 return __hi; | |
141 } | |
142 | |
143 static INLINE real_t MUL_F(real_t A, real_t B) | |
144 { | |
145 return _MulHigh(A, B) << (FRAC_SIZE-FRAC_BITS); | |
10725 | 146 } |
147 | |
12527 | 148 /* Complex multiplication */ |
149 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
150 real_t x1, real_t x2, real_t c1, real_t c2) | |
10725 | 151 { |
12527 | 152 int32_t tmp, yt1, yt2; |
153 asm("smull %0, %1, %4, %6\n\t" | |
154 "smlal %0, %1, %5, %7\n\t" | |
155 "rsb %3, %4, #0\n\t" | |
156 "smull %0, %2, %5, %6\n\t" | |
157 "smlal %0, %2, %3, %7" | |
158 : "=&r" (tmp), "=&r" (yt1), "=&r" (yt2), "=r" (x1) | |
159 : "3" (x1), "r" (x2), "r" (c1), "r" (c2) | |
160 : "cc" ); | |
161 *y1 = yt1 << (FRAC_SIZE-FRAC_BITS); | |
162 *y2 = yt2 << (FRAC_SIZE-FRAC_BITS); | |
10725 | 163 } |
164 | |
165 #else | |
166 | |
12527 | 167 /* multiply with real shift */ |
168 #define MUL_R(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (REAL_BITS-1))) >> REAL_BITS) | |
169 /* multiply with coef shift */ | |
170 #define MUL_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS) | |
171 /* multiply with fractional shift */ | |
172 #ifndef _WIN32_WCE | |
173 #define _MulHigh(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_SIZE-1))) >> FRAC_SIZE) | |
174 #define MUL_F(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_BITS-1))) >> FRAC_BITS) | |
175 #else | |
176 /* eVC for PocketPC has an intrinsic function that returns only the high 32 bits of a 32x32 bit multiply */ | |
177 static INLINE real_t MUL_F(real_t A, real_t B) | |
178 { | |
179 return _MulHigh(A,B) << (32-FRAC_BITS); | |
180 } | |
181 #endif | |
182 | |
183 /* Complex multiplication */ | |
184 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
185 real_t x1, real_t x2, real_t c1, real_t c2) | |
186 { | |
187 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS); | |
188 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS); | |
189 } | |
10725 | 190 |
191 #endif | |
192 | |
193 | |
12527 | 194 |
10725 | 195 #ifdef __cplusplus |
196 } | |
197 #endif | |
198 #endif |