[Mplayer-cvslog] CVS: main/liba52 resample.c,1.8,1.9 a52.h,1.1,1.2
Michael Niedermayer
michael at mplayer.dev.hu
Wed Dec 19 21:20:16 CET 2001
Update of /cvsroot/mplayer/main/liba52
In directory mplayer:/var/tmp.root/cvs-serv17956
Modified Files:
resample.c a52.h
Log Message:
runtime cpu detection for the resample stuff
Index: resample.c
===================================================================
RCS file: /cvsroot/mplayer/main/liba52/resample.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- resample.c 18 Dec 2001 03:00:04 -0000 1.8
+++ resample.c 19 Dec 2001 20:20:06 -0000 1.9
@@ -16,10 +16,14 @@
*/
#include <inttypes.h>
+#include <stdio.h>
#include "a52.h"
#include "../config.h"
+#include "../cpudetect.h"
-#ifdef HAVE_MMX
+int (* a52_resample) (float * _f, int16_t * s16)=NULL;
+
+#ifdef ARCH_X86
static uint64_t __attribute__((aligned(8))) magicF2W= 0x43c0000043c00000LL;
static uint64_t __attribute__((aligned(8))) wm1010= 0xFFFF0000FFFF0000LL;
static uint64_t __attribute__((aligned(8))) wm0101= 0x0000FFFF0000FFFFLL;
@@ -39,19 +43,109 @@
static int chans=2;
static int flags=0;
-void a52_resample_init(int _flags,int _chans){
- chans=_chans;
- flags=_flags;
+int a52_resample_C(float * _f, int16_t * s16)
+{
+ int i;
+ int32_t * f = (int32_t *) _f;
+
+ switch (flags) {
+ case A52_MONO:
+ for (i = 0; i < 256; i++) {
+ s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
+ s16[5*i+4] = convert (f[i]);
+ }
+ break;
+ case A52_CHANNEL:
+ case A52_STEREO:
+ case A52_DOLBY:
+ for (i = 0; i < 256; i++) {
+ s16[2*i] = convert (f[i]);
+ s16[2*i+1] = convert (f[i+256]);
+ }
+ break;
+ case A52_3F:
+ for (i = 0; i < 256; i++) {
+ s16[5*i] = convert (f[i]);
+ s16[5*i+1] = convert (f[i+512]);
+ s16[5*i+2] = s16[5*i+3] = 0;
+ s16[5*i+4] = convert (f[i+256]);
+ }
+ break;
+ case A52_2F2R:
+ for (i = 0; i < 256; i++) {
+ s16[4*i] = convert (f[i]);
+ s16[4*i+1] = convert (f[i+256]);
+ s16[4*i+2] = convert (f[i+512]);
+ s16[4*i+3] = convert (f[i+768]);
+ }
+ break;
+ case A52_3F2R:
+ for (i = 0; i < 256; i++) {
+ s16[5*i] = convert (f[i]);
+ s16[5*i+1] = convert (f[i+512]);
+ s16[5*i+2] = convert (f[i+768]);
+ s16[5*i+3] = convert (f[i+1024]);
+ s16[5*i+4] = convert (f[i+256]);
+ }
+ break;
+ case A52_MONO | A52_LFE:
+ for (i = 0; i < 256; i++) {
+ s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
+ s16[6*i+4] = convert (f[i+256]);
+ s16[6*i+5] = convert (f[i]);
+ }
+ break;
+ case A52_CHANNEL | A52_LFE:
+ case A52_STEREO | A52_LFE:
+ case A52_DOLBY | A52_LFE:
+ for (i = 0; i < 256; i++) {
+ s16[6*i] = convert (f[i+256]);
+ s16[6*i+1] = convert (f[i+512]);
+ s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
+ s16[6*i+5] = convert (f[i]);
+ }
+ break;
+ case A52_3F | A52_LFE:
+ for (i = 0; i < 256; i++) {
+ s16[6*i] = convert (f[i+256]);
+ s16[6*i+1] = convert (f[i+768]);
+ s16[6*i+2] = s16[6*i+3] = 0;
+ s16[6*i+4] = convert (f[i+512]);
+ s16[6*i+5] = convert (f[i]);
+ }
+ break;
+ case A52_2F2R | A52_LFE:
+ for (i = 0; i < 256; i++) {
+ s16[6*i] = convert (f[i+256]);
+ s16[6*i+1] = convert (f[i+512]);
+ s16[6*i+2] = convert (f[i+768]);
+ s16[6*i+3] = convert (f[i+1024]);
+ s16[6*i+4] = 0;
+ s16[6*i+5] = convert (f[i]);
+ }
+ break;
+ case A52_3F2R | A52_LFE:
+ for (i = 0; i < 256; i++) {
+ s16[6*i] = convert (f[i+256]);
+ s16[6*i+1] = convert (f[i+768]);
+ s16[6*i+2] = convert (f[i+1024]);
+ s16[6*i+3] = convert (f[i+1280]);
+ s16[6*i+4] = convert (f[i+512]);
+ s16[6*i+5] = convert (f[i]);
+ }
+ break;
+ }
+ return chans*256;
}
-int a52_resample(float * _f, int16_t * s16)
+#ifdef ARCH_X86
+int a52_resample_MMX(float * _f, int16_t * s16)
{
int i;
int32_t * f = (int32_t *) _f;
switch (flags) {
case A52_MONO:
-#ifdef HAVE_MMX
asm volatile(
"movl $-512, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -84,12 +178,6 @@
:: "r" (s16+1280), "r" (f+256)
:"%esi", "%edi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
- s16[5*i+4] = convert (f[i]);
- }
-#endif
break;
case A52_CHANNEL:
case A52_STEREO:
@@ -112,7 +200,6 @@
:: "r" (s16+512), "r" (f+256)
:"%esi", "memory"
);*/
-#ifdef HAVE_MMX
asm volatile(
"movl $-1024, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -138,14 +225,8 @@
:: "r" (s16+512), "r" (f+256)
:"%esi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[2*i] = convert (f[i]);
- s16[2*i+1] = convert (f[i+256]);
- }
-#endif
break;
- case A52_3F:
+ case A52_3F: //FIXME Optimize
for (i = 0; i < 256; i++) {
s16[5*i] = convert (f[i]);
s16[5*i+1] = convert (f[i+512]);
@@ -154,7 +235,6 @@
}
break;
case A52_2F2R:
-#ifdef HAVE_MMX
asm volatile(
"movl $-1024, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -201,16 +281,8 @@
:: "r" (s16+1024), "r" (f+256)
:"%esi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[4*i] = convert (f[i]);
- s16[4*i+1] = convert (f[i+256]);
- s16[4*i+2] = convert (f[i+512]);
- s16[4*i+3] = convert (f[i+768]);
- }
-#endif
break;
- case A52_3F2R:
+ case A52_3F2R: //FIXME optimitze
for (i = 0; i < 256; i++) {
s16[5*i] = convert (f[i]);
s16[5*i+1] = convert (f[i+512]);
@@ -220,7 +292,6 @@
}
break;
case A52_MONO | A52_LFE:
-#ifdef HAVE_MMX
asm volatile(
"movl $-1024, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -256,18 +327,10 @@
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
- s16[6*i+4] = convert (f[i+256]);
- s16[6*i+5] = convert (f[i]);
- }
-#endif
break;
case A52_CHANNEL | A52_LFE:
case A52_STEREO | A52_LFE:
case A52_DOLBY | A52_LFE:
-#ifdef HAVE_MMX
asm volatile(
"movl $-1024, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -301,17 +364,8 @@
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+512]);
- s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
- s16[6*i+5] = convert (f[i]);
- }
-#endif
break;
case A52_3F | A52_LFE:
-#ifdef HAVE_MMX
asm volatile(
"movl $-1024, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -347,18 +401,8 @@
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+768]);
- s16[6*i+2] = s16[6*i+3] = 0;
- s16[6*i+4] = convert (f[i+512]);
- s16[6*i+5] = convert (f[i]);
- }
-#endif
break;
case A52_2F2R | A52_LFE:
-#ifdef HAVE_MMX
asm volatile(
"movl $-1024, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -400,19 +444,8 @@
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+512]);
- s16[6*i+2] = convert (f[i+768]);
- s16[6*i+3] = convert (f[i+1024]);
- s16[6*i+4] = 0;
- s16[6*i+5] = convert (f[i]);
- }
-#endif
break;
case A52_3F2R | A52_LFE:
-#ifdef HAVE_MMX
asm volatile(
"movl $-1024, %%esi \n\t"
"movq magicF2W, %%mm7 \n\t"
@@ -456,18 +489,27 @@
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
-#else
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+768]);
- s16[6*i+2] = convert (f[i+1024]);
- s16[6*i+3] = convert (f[i+1280]);
- s16[6*i+4] = convert (f[i+512]);
- s16[6*i+5] = convert (f[i]);
- }
-#endif
break;
}
return chans*256;
+}
+#endif //arch_x86
+
+void a52_resample_init(int _flags,int _chans){
+ chans=_chans;
+ flags=_flags;
+
+ if(a52_resample==NULL) // only once please ;)
+ {
+ if(gCpuCaps.hasMMX) fprintf(stderr, "Using MMX optimized resampler\n");
+ else fprintf(stderr, "No accelerated resampler found\n");
+ }
+
+#ifdef ARCH_X86
+ if(gCpuCaps.hasMMX) a52_resample= a52_resample_MMX;
+#else
+ if(0);
+#endif
+ else a52_resample= a52_resample_C;
}
Index: a52.h
===================================================================
RCS file: /cvsroot/mplayer/main/liba52/a52.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- a52.h 9 Dec 2001 15:28:44 -0000 1.1
+++ a52.h 19 Dec 2001 20:20:06 -0000 1.2
@@ -118,5 +118,6 @@
void a52_dynrng (a52_state_t * state,
sample_t (* call) (sample_t, void *), void * data);
int a52_block (a52_state_t * state, sample_t * samples);
+extern int (* a52_resample) (float * _f, int16_t * s16);
#endif /* A52_H */
More information about the MPlayer-cvslog
mailing list