author | llornkcor <llornkcor> | 2005-11-08 23:16:03 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-11-08 23:16:03 (UTC) |
commit | 6bd52d3658f01c966d690b12235592a5473a4d57 (patch) (unidiff) | |
tree | 76e25003b738fde6ebbea5d338b7cf76b82f47fa /core/multimedia/opieplayer/libmad/fixed.h | |
parent | a8063e0797d6edf2ead22fc8c5346ddf187f0b5d (diff) | |
download | opie-6bd52d3658f01c966d690b12235592a5473a4d57.zip opie-6bd52d3658f01c966d690b12235592a5473a4d57.tar.gz opie-6bd52d3658f01c966d690b12235592a5473a4d57.tar.bz2 |
update libmad and add 64bit define
Diffstat (limited to 'core/multimedia/opieplayer/libmad/fixed.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/fixed.h | 111 |
1 files changed, 67 insertions, 44 deletions
diff --git a/core/multimedia/opieplayer/libmad/fixed.h b/core/multimedia/opieplayer/libmad/fixed.h index c9b98ca..baa7dc5 100644 --- a/core/multimedia/opieplayer/libmad/fixed.h +++ b/core/multimedia/opieplayer/libmad/fixed.h | |||
@@ -1,15 +1,15 @@ | |||
1 | /* | 1 | /* |
2 | * libmad - MPEG audio decoder library | 2 | * libmad - MPEG audio decoder library |
3 | * Copyright (C) 2000-2001 Robert Leslie | 3 | * Copyright (C) 2000-2004 Underbit Technologies, Inc. |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 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 | 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 | 7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. | 8 | * (at your option) any later version. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License |
@@ -199,54 +199,65 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y) | |||
199 | asm ("addl %4,%2\n\t" \ | 199 | asm ("addl %4,%2\n\t" \ |
200 | "adcl %5,%3" \ | 200 | "adcl %5,%3" \ |
201 | : "=rm" (__lo_), "=rm" (__hi_) \ | 201 | : "=rm" (__lo_), "=rm" (__hi_) \ |
202 | : "0" (lo), "1" (hi), \ | 202 | : "0" (lo), "1" (hi), \ |
203 | "ir" (1L << (MAD_F_SCALEBITS - 1)), "ir" (0) \ | 203 | "ir" (1L << (MAD_F_SCALEBITS - 1)), "ir" (0) \ |
204 | : "cc"); \ | 204 | : "cc"); \ |
205 | asm ("shrdl %3,%2,%1" \ | 205 | asm ("shrdl %3,%2,%1" \ |
206 | : "=rm" (__result) \ | 206 | : "=rm" (__result) \ |
207 | : "0" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS) \ | 207 | : "0" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS) \ |
208 | : "cc"); \ | 208 | : "cc"); \ |
209 | __result; \ | 209 | __result; \ |
210 | }) | 210 | }) |
211 | # elif defined(OPT_INTEL) | ||
212 | /* | ||
213 | * Alternate Intel scaling that may or may not perform better. | ||
214 | */ | ||
215 | # define mad_f_scale64(hi, lo) \ | ||
216 | ({ mad_fixed_t __result; \ | ||
217 | asm ("shrl %3,%1\n\t" \ | ||
218 | "shll %4,%2\n\t" \ | ||
219 | "orl %2,%1" \ | ||
220 | : "=rm" (__result) \ | ||
221 | : "0" (lo), "r" (hi), \ | ||
222 | "I" (MAD_F_SCALEBITS), "I" (32 - MAD_F_SCALEBITS) \ | ||
223 | : "cc"); \ | ||
224 | __result; \ | ||
225 | }) | ||
211 | # else | 226 | # else |
212 | # define mad_f_scale64(hi, lo) \ | 227 | # define mad_f_scale64(hi, lo) \ |
213 | ({ mad_fixed_t __result; \ | 228 | ({ mad_fixed_t __result; \ |
214 | asm ("shrdl %3,%2,%1" \ | 229 | asm ("shrdl %3,%2,%1" \ |
215 | : "=rm" (__result) \ | 230 | : "=rm" (__result) \ |
216 | : "0" (lo), "r" (hi), "I" (MAD_F_SCALEBITS) \ | 231 | : "0" (lo), "r" (hi), "I" (MAD_F_SCALEBITS) \ |
217 | : "cc"); \ | 232 | : "cc"); \ |
218 | __result; \ | 233 | __result; \ |
219 | }) | 234 | }) |
220 | # endif /* OPT_ACCURACY */ | 235 | # endif /* OPT_ACCURACY */ |
221 | 236 | ||
222 | # define MAD_F_SCALEBITS MAD_F_FRACBITS | 237 | # define MAD_F_SCALEBITS MAD_F_FRACBITS |
223 | # endif | 238 | # endif |
224 | 239 | ||
225 | /* --- ARM ----------------------------------------------------------------- */ | 240 | /* --- ARM ----------------------------------------------------------------- */ |
226 | 241 | ||
227 | # elif defined(FPM_ARM) | 242 | # elif defined(FPM_ARM) |
228 | 243 | ||
229 | /* | 244 | /* |
230 | * This ARM V4 version is as accurate as FPM_64BIT but much faster. The | 245 | * This ARM V4 version is as accurate as FPM_64BIT but much faster. The |
231 | * least significant bit is properly rounded at no CPU cycle cost! | 246 | * least significant bit is properly rounded at no CPU cycle cost! |
232 | */ | 247 | */ |
233 | # if 1 | 248 | # if 1 |
234 | /* | 249 | /* |
235 | * There's a bug somewhere, possibly in the compiler, that sometimes makes | 250 | * This is faster than the default implementation via MAD_F_MLX() and |
236 | * this necessary instead of the default implementation via MAD_F_MLX and | 251 | * mad_f_scale64(). |
237 | * mad_f_scale64. It may be related to the use (or lack) of | ||
238 | * -finline-functions and/or -fstrength-reduce. | ||
239 | * | ||
240 | * This is also apparently faster than MAD_F_MLX/mad_f_scale64. | ||
241 | */ | 252 | */ |
242 | # define mad_f_mul(x, y) \ | 253 | # define mad_f_mul(x, y) \ |
243 | ({ mad_fixed64hi_t __hi; \ | 254 | ({ mad_fixed64hi_t __hi; \ |
244 | mad_fixed64lo_t __lo; \ | 255 | mad_fixed64lo_t __lo; \ |
245 | mad_fixed_t __result; \ | 256 | mad_fixed_t __result; \ |
246 | asm ("smull%0, %1, %3, %4\n\t" \ | 257 | asm ("smull%0, %1, %3, %4\n\t" \ |
247 | "movs%0, %0, lsr %5\n\t" \ | 258 | "movs%0, %0, lsr %5\n\t" \ |
248 | "adc%2, %0, %1, lsl %6" \ | 259 | "adc%2, %0, %1, lsl %6" \ |
249 | : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \ | 260 | : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \ |
250 | : "%r" (x), "r" (y), \ | 261 | : "%r" (x), "r" (y), \ |
251 | "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \ | 262 | "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \ |
252 | : "cc"); \ | 263 | : "cc"); \ |
@@ -266,25 +277,25 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y) | |||
266 | 277 | ||
267 | # define MAD_F_MLN(hi, lo) \ | 278 | # define MAD_F_MLN(hi, lo) \ |
268 | asm ("rsbs%0, %2, #0\n\t" \ | 279 | asm ("rsbs%0, %2, #0\n\t" \ |
269 | "rsc%1, %3, #0" \ | 280 | "rsc%1, %3, #0" \ |
270 | : "=r" (lo), "=r" (hi) \ | 281 | : "=r" (lo), "=r" (hi) \ |
271 | : "0" (lo), "1" (hi) \ | 282 | : "0" (lo), "1" (hi) \ |
272 | : "cc") | 283 | : "cc") |
273 | 284 | ||
274 | # define mad_f_scale64(hi, lo) \ | 285 | # define mad_f_scale64(hi, lo) \ |
275 | ({ mad_fixed_t __result; \ | 286 | ({ mad_fixed_t __result; \ |
276 | asm ("movs%0, %1, lsr %3\n\t" \ | 287 | asm ("movs%0, %1, lsr %3\n\t" \ |
277 | "adc%0, %0, %2, lsl %4" \ | 288 | "adc%0, %0, %2, lsl %4" \ |
278 | : "=r" (__result) \ | 289 | : "=&r" (__result) \ |
279 | : "r" (lo), "r" (hi), \ | 290 | : "r" (lo), "r" (hi), \ |
280 | "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \ | 291 | "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \ |
281 | : "cc"); \ | 292 | : "cc"); \ |
282 | __result; \ | 293 | __result; \ |
283 | }) | 294 | }) |
284 | 295 | ||
285 | # define MAD_F_SCALEBITS MAD_F_FRACBITS | 296 | # define MAD_F_SCALEBITS MAD_F_FRACBITS |
286 | 297 | ||
287 | /* --- MIPS ---------------------------------------------------------------- */ | 298 | /* --- MIPS ---------------------------------------------------------------- */ |
288 | 299 | ||
289 | # elif defined(FPM_MIPS) | 300 | # elif defined(FPM_MIPS) |
290 | 301 | ||
@@ -334,76 +345,87 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y) | |||
334 | */ | 345 | */ |
335 | # define MAD_F_MLX(hi, lo, x, y) \ | 346 | # define MAD_F_MLX(hi, lo, x, y) \ |
336 | asm ("smul %2, %3, %0\n\t" \ | 347 | asm ("smul %2, %3, %0\n\t" \ |
337 | "rd %%y, %1" \ | 348 | "rd %%y, %1" \ |
338 | : "=r" (lo), "=r" (hi) \ | 349 | : "=r" (lo), "=r" (hi) \ |
339 | : "%r" (x), "rI" (y)) | 350 | : "%r" (x), "rI" (y)) |
340 | 351 | ||
341 | /* --- PowerPC ------------------------------------------------------------- */ | 352 | /* --- PowerPC ------------------------------------------------------------- */ |
342 | 353 | ||
343 | # elif defined(FPM_PPC) | 354 | # elif defined(FPM_PPC) |
344 | 355 | ||
345 | /* | 356 | /* |
346 | * This PowerPC version is tuned for the 4xx embedded processors. It is | 357 | * This PowerPC version is fast and accurate; the disposition of the least |
347 | * effectively a tuned version of FPM_64BIT. It is a little faster and just | 358 | * significant bit depends on OPT_ACCURACY via mad_f_scale64(). |
348 | * as accurate. The disposition of the least significant bit depends on | ||
349 | * OPT_ACCURACY via mad_f_scale64(). | ||
350 | */ | 359 | */ |
351 | # define MAD_F_MLX(hi, lo, x, y) \ | 360 | # define MAD_F_MLX(hi, lo, x, y) \ |
352 | asm ("mulhw %1, %2, %3\n\t" \ | 361 | do { \ |
353 | "mullw %0, %2, %3" \ | 362 | asm ("mullw %0,%1,%2" \ |
354 | : "=&r" (lo), "=&r" (hi) \ | 363 | : "=r" (lo) \ |
355 | : "%r" (x), "r" (y)) | 364 | : "%r" (x), "r" (y)); \ |
365 | asm ("mulhw %0,%1,%2" \ | ||
366 | : "=r" (hi) \ | ||
367 | : "%r" (x), "r" (y)); \ | ||
368 | } \ | ||
369 | while (0) | ||
356 | 370 | ||
357 | # define MAD_F_MLA(hi, lo, x, y) \ | 371 | # if defined(OPT_ACCURACY) |
372 | /* | ||
373 | * This gives best accuracy but is not very fast. | ||
374 | */ | ||
375 | # define MAD_F_MLA(hi, lo, x, y) \ | ||
358 | ({ mad_fixed64hi_t __hi; \ | 376 | ({ mad_fixed64hi_t __hi; \ |
359 | mad_fixed64lo_t __lo; \ | 377 | mad_fixed64lo_t __lo; \ |
360 | MAD_F_MLX(__hi, __lo, (x), (y)); \ | 378 | MAD_F_MLX(__hi, __lo, (x), (y)); \ |
361 | asm ("addc %0, %2, %3\n\t" \ | 379 | asm ("addc %0,%2,%3\n\t" \ |
362 | "adde %1, %4, %5" \ | 380 | "adde %1,%4,%5" \ |
363 | : "=r" (lo), "=r" (hi) \ | 381 | : "=r" (lo), "=r" (hi) \ |
364 | : "%r" (__lo), "0" (lo), "%r" (__hi), "1" (hi)); \ | 382 | : "%r" (lo), "r" (__lo), \ |
383 | "%r" (hi), "r" (__hi) \ | ||
384 | : "xer"); \ | ||
365 | }) | 385 | }) |
386 | # endif | ||
366 | 387 | ||
367 | # if defined(OPT_ACCURACY) | 388 | # if defined(OPT_ACCURACY) |
368 | /* | 389 | /* |
369 | * This is accurate and ~2 - 2.5 times slower than the unrounded version. | 390 | * This is slower than the truncating version below it. |
370 | * | ||
371 | * The __volatile__ improves the generated code by another 5% (fewer spills | ||
372 | * to memory); eventually they should be removed. | ||
373 | */ | 391 | */ |
374 | # define mad_f_scale64(hi, lo) \ | 392 | # define mad_f_scale64(hi, lo) \ |
375 | ({ mad_fixed_t __result; \ | 393 | ({ mad_fixed_t __result, __round; \ |
376 | mad_fixed64hi_t __hi_; \ | 394 | asm ("rotrwi %0,%1,%2" \ |
377 | mad_fixed64lo_t __lo_; \ | 395 | : "=r" (__result) \ |
378 | asm __volatile__ ("addc %0, %2, %4\n\t" \ | 396 | : "r" (lo), "i" (MAD_F_SCALEBITS)); \ |
379 | "addze %1, %3" \ | 397 | asm ("extrwi %0,%1,1,0" \ |
380 | : "=r" (__lo_), "=r" (__hi_) \ | 398 | : "=r" (__round) \ |
381 | : "r" (lo), "r" (hi), "r" (1 << (MAD_F_SCALEBITS - 1))); \ | 399 | : "r" (__result)); \ |
382 | asm __volatile__ ("rlwinm %0, %2,32-%3,0,%3-1\n\t" \ | 400 | asm ("insrwi %0,%1,%2,0" \ |
383 | "rlwimi %0, %1,32-%3,%3,31" \ | 401 | : "+r" (__result) \ |
384 | : "=&r" (__result) \ | 402 | : "r" (hi), "i" (MAD_F_SCALEBITS)); \ |
385 | : "r" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS)); \ | 403 | asm ("add %0,%1,%2" \ |
386 | __result; \ | 404 | : "=r" (__result) \ |
405 | : "%r" (__result), "r" (__round)); \ | ||
406 | __result; \ | ||
387 | }) | 407 | }) |
388 | # else | 408 | # else |
389 | # define mad_f_scale64(hi, lo) \ | 409 | # define mad_f_scale64(hi, lo) \ |
390 | ({ mad_fixed_t __result; \ | 410 | ({ mad_fixed_t __result; \ |
391 | asm ("rlwinm %0, %2,32-%3,0,%3-1\n\t" \ | 411 | asm ("rotrwi %0,%1,%2" \ |
392 | "rlwimi %0, %1,32-%3,%3,31" \ | ||
393 | : "=r" (__result) \ | 412 | : "=r" (__result) \ |
394 | : "r" (lo), "r" (hi), "I" (MAD_F_SCALEBITS)); \ | 413 | : "r" (lo), "i" (MAD_F_SCALEBITS)); \ |
395 | __result; \ | 414 | asm ("insrwi %0,%1,%2,0" \ |
415 | : "+r" (__result) \ | ||
416 | : "r" (hi), "i" (MAD_F_SCALEBITS)); \ | ||
417 | __result; \ | ||
396 | }) | 418 | }) |
397 | # endif /* OPT_ACCURACY */ | 419 | # endif |
398 | 420 | ||
399 | # define MAD_F_SCALEBITS MAD_F_FRACBITS | 421 | # define MAD_F_SCALEBITS MAD_F_FRACBITS |
400 | 422 | ||
401 | /* --- Default ------------------------------------------------------------- */ | 423 | /* --- Default ------------------------------------------------------------- */ |
402 | 424 | ||
403 | # elif defined(FPM_DEFAULT) | 425 | # elif defined(FPM_DEFAULT) |
404 | 426 | ||
405 | /* | 427 | /* |
406 | * This version is the most portable but it loses significant accuracy. | 428 | * This version is the most portable but it loses significant accuracy. |
407 | * Furthermore, accuracy is biased against the second argument, so care | 429 | * Furthermore, accuracy is biased against the second argument, so care |
408 | * should be taken when ordering operands. | 430 | * should be taken when ordering operands. |
409 | * | 431 | * |
@@ -419,26 +441,26 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y) | |||
419 | # endif | 441 | # endif |
420 | 442 | ||
421 | /* ------------------------------------------------------------------------- */ | 443 | /* ------------------------------------------------------------------------- */ |
422 | 444 | ||
423 | # else | 445 | # else |
424 | # error "no FPM selected" | 446 | # error "no FPM selected" |
425 | # endif | 447 | # endif |
426 | 448 | ||
427 | /* default implementations */ | 449 | /* default implementations */ |
428 | 450 | ||
429 | # if !defined(mad_f_mul) | 451 | # if !defined(mad_f_mul) |
430 | # define mad_f_mul(x, y) \ | 452 | # define mad_f_mul(x, y) \ |
431 | ({ mad_fixed64hi_t __hi; \ | 453 | ({ register mad_fixed64hi_t __hi; \ |
432 | mad_fixed64lo_t __lo; \ | 454 | register mad_fixed64lo_t __lo; \ |
433 | MAD_F_MLX(__hi, __lo, (x), (y)); \ | 455 | MAD_F_MLX(__hi, __lo, (x), (y)); \ |
434 | mad_f_scale64(__hi, __lo); \ | 456 | mad_f_scale64(__hi, __lo); \ |
435 | }) | 457 | }) |
436 | # endif | 458 | # endif |
437 | 459 | ||
438 | # if !defined(MAD_F_MLA) | 460 | # if !defined(MAD_F_MLA) |
439 | # define MAD_F_ML0(hi, lo, x, y)((lo) = mad_f_mul((x), (y))) | 461 | # define MAD_F_ML0(hi, lo, x, y)((lo) = mad_f_mul((x), (y))) |
440 | # define MAD_F_MLA(hi, lo, x, y)((lo) += mad_f_mul((x), (y))) | 462 | # define MAD_F_MLA(hi, lo, x, y)((lo) += mad_f_mul((x), (y))) |
441 | # define MAD_F_MLN(hi, lo) ((lo) = -(lo)) | 463 | # define MAD_F_MLN(hi, lo) ((lo) = -(lo)) |
442 | # define MAD_F_MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo)) | 464 | # define MAD_F_MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo)) |
443 | # endif | 465 | # endif |
444 | 466 | ||
@@ -460,17 +482,18 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y) | |||
460 | ((((mad_fixed_t) \ | 482 | ((((mad_fixed_t) \ |
461 | (((hi) << (32 - (MAD_F_SCALEBITS - 1))) | \ | 483 | (((hi) << (32 - (MAD_F_SCALEBITS - 1))) | \ |
462 | ((lo) >> (MAD_F_SCALEBITS - 1)))) + 1) >> 1) | 484 | ((lo) >> (MAD_F_SCALEBITS - 1)))) + 1) >> 1) |
463 | # else | 485 | # else |
464 | # define mad_f_scale64(hi, lo) \ | 486 | # define mad_f_scale64(hi, lo) \ |
465 | ((mad_fixed_t) \ | 487 | ((mad_fixed_t) \ |
466 | (((hi) << (32 - MAD_F_SCALEBITS)) | \ | 488 | (((hi) << (32 - MAD_F_SCALEBITS)) | \ |
467 | ((lo) >> MAD_F_SCALEBITS))) | 489 | ((lo) >> MAD_F_SCALEBITS))) |
468 | # endif | 490 | # endif |
469 | # define MAD_F_SCALEBITS MAD_F_FRACBITS | 491 | # define MAD_F_SCALEBITS MAD_F_FRACBITS |
470 | # endif | 492 | # endif |
471 | 493 | ||
472 | /* miscellaneous C routines */ | 494 | /* C routines */ |
473 | 495 | ||
474 | mad_fixed_t mad_f_abs(mad_fixed_t); | 496 | mad_fixed_t mad_f_abs(mad_fixed_t); |
497 | mad_fixed_t mad_f_div(mad_fixed_t, mad_fixed_t); | ||
475 | 498 | ||
476 | # endif | 499 | # endif |