[Mplayer-cvslog] CVS: main/libac3/mmx rematrix_3dnow.c,NONE,1.1 imdct_3dnow.c,1.8,1.9

Nick Kurshev nickols_k at users.sourceforge.net
Fri Jun 22 10:57:54 CEST 2001


Update of /cvsroot/mplayer/main/libac3/mmx
In directory usw-pr-cvs1:/tmp/cvs-serv23102/main/libac3/mmx

Modified Files:
	imdct_3dnow.c 
Added Files:
	rematrix_3dnow.c 
Log Message:
More 3dnow! optimization

--- NEW FILE ---
/* 
 *    rematrix.c
 *
 *	Copyright (C) Aaron Holtzman - July 1999
 *
 *  This file is part of ac3dec, a free Dolby AC-3 stream decoder.
 *	
 *  ac3dec 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, or (at your option)
 *  any later version.
 *   
 *  ac3dec 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 GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *
 *  Modified for using AMD's 3DNow! - 3DNowEx(DSP)! SIMD operations 
 *  by Nick Kurshev <nickols_k at mail.ru>
 *
 */

void rematrix (audblk_t *audblk, stream_samples_t samples)
{
	uint32_t num_bands;
	uint32_t start;
	uint32_t end;
	uint32_t end_3dnow;
	int i,j;

	if (!audblk->cplinu || audblk->cplbegf > 2)
		num_bands = 4;
	else if (audblk->cplbegf > 0)
		num_bands = 3;
	else
		num_bands = 2;

	for (i=0; i < num_bands; i++) {
		if (!audblk->rematflg[i])
			continue;

		start = rematrix_band[i].start;
		end = min (rematrix_band[i].end ,12 * audblk->cplbegf + 36);
		/* 8-byte alignment */
		j = start;
		if(((unsigned long)(&(samples[0][j]))&7)!=0)
		{
			float left,right;
			left  = samples[0][j] + samples[1][j];
			right = samples[0][j] - samples[1][j];
			samples[0][j] = left;
			samples[1][j] = right;
			j++;
		}
		end_3dnow = end & 0xFFFFFFFEUL;
		__asm __volatile("femms":::"memory");
		for (;j < end_3dnow; j+=2) {
			__asm __volatile(
				"movq	%2,	%%mm0\n\t"
				"movq	%3,	%%mm1\n\t"
				"movq	%%mm0,	%%mm2\n\t"
				"pfadd	%%mm1,	%%mm0\n\t"
				"pfsub	%%mm1,	%%mm2\n\t"
				"movq	%%mm0,	%0\n\t"
				"movq	%%mm2,	%1"
				:"=m"(samples[0][j]), "=m"(samples[1][j])
				:"m"(samples[0][j]), "m"(samples[1][j])
				:"memory");
		}
		__asm __volatile("femms":::"memory");
		/* do tail */
		if (j < end) {
			float left,right;
			left  = samples[0][j] + samples[1][j];
			right = samples[0][j] - samples[1][j];
			samples[0][j] = left;
			samples[1][j] = right;
		}
	}
}

Index: imdct_3dnow.c
===================================================================
RCS file: /cvsroot/mplayer/main/libac3/mmx/imdct_3dnow.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** imdct_3dnow.c	2001/06/20 07:53:55	1.8
--- imdct_3dnow.c	2001/06/22 08:57:52	1.9
***************
*** 192,267 ****
  static void imdct_do_512_nol (float data[], float delay[])
  {
!        int i, j;
! 	float tmp_a_r, tmp_a_i;
  	float *data_ptr;
  	float *delay_ptr;
  	float *window_ptr;
  
-         //
-         // 512 IMDCT with source and dest data in 'data'
-         //
- 
-        // Pre IFFT complex multiply plus IFFT cmplx conjugate
-         for( i=0; i < 128; i++)
-         {
-          /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) */
-          j = pm128[i];
-          //a = (data[256-2*j-1] - data[2*j]) * (xcos1[j] + xsin1[j]);
-          //c = data[2*j] * xcos1[j];
-          //b = data[256-2*j-1] * xsin1[j];
-           //buf1[i].re = a - b + c;
-          //buf1[i].im = b + c;
-          buf[i].re = (data[256-2*j-1] * xcos1[j]) - (data[2*j] * xsin1[j]);
-          buf[i].im = -1.0 * (data[2*j] * xcos1[j] + data[256-2*j-1] * xsin1[j]);
-         }
- 
    __asm__ __volatile__ ("femms":::"memory");
!        fft_128p(&buf[0]);
!   __asm__ __volatile__ ("femms":::"memory");
! 
!         /* Post IFFT complex multiply  plus IFFT complex conjugate*/
!         for( i=0; i < 128; i++)
!         {
!                 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
!                /* int j1 = i; */
!                tmp_a_r = buf[i].re;
!                tmp_a_i = buf[i].im;
!                //a = (tmp_a_r - tmp_a_i) * (xcos1[j] + xsin1[j]);
!                //b = tmp_a_r * xsin1[j];
!                //c = tmp_a_i * xcos1[j];
!                //buf[j].re = a - b + c;
!                //buf[j].im = b + c;
!                buf[i].re =(tmp_a_r * xcos1[i])  +  (tmp_a_i  * xsin1[i]);
!                buf[i].im =(tmp_a_r * xsin1[i])  -  (tmp_a_i  * xcos1[i]);
!         }
  
!         data_ptr = data;
!         delay_ptr = delay;
!         window_ptr = window;
  
!        /* Window and convert to real valued signal, no overlap here*/
!         for(i=0; i< 64; i++) {
! 		*data_ptr++   = -buf[64+i].im   * *window_ptr++;
! 		*data_ptr++   =  buf[64-i-1].re * *window_ptr++;
!         }
  
! 	for(i=0; i< 64; i++) {
! 		*data_ptr++  = -buf[i].re       * *window_ptr++;
! 		*data_ptr++  =  buf[128-i-1].im * *window_ptr++;
  	}
- 
-         /* The trailing edge of the window goes into the delay line */
  
  	delay_ptr = delay;
! 
!         for(i=0; i< 64; i++) {
! 		*delay_ptr++  = -buf[64+i].re   * *--window_ptr;
! 		*delay_ptr++  =  buf[64-i-1].im * *--window_ptr;
!         }
! 
!         for(i=0; i<64; i++) {
! 		*delay_ptr++  =  buf[i].im       * *--window_ptr;
! 		*delay_ptr++  = -buf[128-i-1].re * *--window_ptr;
!         }
  }
  
--- 192,341 ----
  static void imdct_do_512_nol (float data[], float delay[])
  {
! 	int i, j;
  	float *data_ptr;
  	float *delay_ptr;
  	float *window_ptr;
  
    __asm__ __volatile__ ("femms":::"memory");
! // 512 IMDCT with source and dest data in 'data'
! // Pre IFFT complex multiply plus IFFT complex conjugate
  
!   __asm__ __volatile__ (
! 	"movq %0, %%mm7\n\t"
! 	::"m"(x_plus_minus_3dnow)
! 	:"memory");
! 	for( i=0; i < 128; i++) {
! 		j = pm128[i];
! 	__asm__ __volatile__ (
! 		"movd	%1, %%mm0\n\t"
! 		"movd	%3, %%mm1\n\t"
! 		"punpckldq %2, %%mm0\n\t" /* mm0 = data[256-2*j-1] | data[2*j]*/
! 		"punpckldq %4, %%mm1\n\t" /* mm1 = xcos[j] | xsin[j] */
! 		"movq	%%mm0, %%mm2\n\t"
! 		"pfmul	%%mm1, %%mm0\n\t"
! #ifdef HAVE_3DNOWEX
! 		"pswapd	%%mm1, %%mm1\n\t"
! #else
! 		"movq %%mm1, %%mm5\n\t"
! 		"psrlq $32, %%mm1\n\t"
! 		"punpckldq %%mm5, %%mm1\n\t"
! #endif
! 		"pfmul	%%mm1, %%mm2\n\t"
! #ifdef HAVE_3DNOWEX
! 		"pfpnacc %%mm2, %%mm0\n\t"
! #else
! 		"pxor	%%mm7, %%mm0\n\t"
! 		"pfacc	%%mm2, %%mm0\n\t"
! #endif
! 		"pxor	%%mm7, %%mm0\n\t"
! 		"movq	%%mm0, %0"
! 		:"=m"(buf[i])
! 		:"m"(data[256-2*j-1]), "m"(data[2*j]), "m"(xcos1[j]), "m"(xsin1[j])
! 		:"memory"
! 	);
! /*		buf[i].re = (data[256-2*j-1] * xcos1[j] - data[2*j] * xsin1[j]);
! 		buf[i].im = (data[256-2*j-1] * xsin1[j] + data[2*j] * xcos1[j])*(-1.0);*/
! 	}
  
! 	fft_128p (&buf[0]);
  
! // Post IFFT complex multiply  plus IFFT complex conjugate
!   __asm__ __volatile__ (
! 	"movq %0, %%mm7\n\t"
! 	"movq %1, %%mm6\n\t"
! 	::"m"(x_plus_minus_3dnow),
! 	"m"(x_minus_plus_3dnow)
! 	:"eax","memory");
! 	for (i=0; i < 128; i++) {
! 	    __asm__ __volatile__ (
! 		"movq %1, %%mm0\n\t" /* ac3_buf[i].re | ac3_buf[i].im */
! 		"movq %%mm0, %%mm1\n\t" /* ac3_buf[i].re | ac3_buf[i].im */
! #ifndef HAVE_3DNOWEX
! 		"movq %%mm1, %%mm2\n\t"
! 		"psrlq $32, %%mm1\n\t"
! 		"punpckldq %%mm2, %%mm1\n\t"
! #else			 
! 		"pswapd %%mm1, %%mm1\n\t" /* ac3_buf[i].re | ac3_buf[i].im */
! #endif			 
! 		"movd %3, %%mm3\n\t" /* ac3_xsin[i] */
! 		"punpckldq %2, %%mm3\n\t" /* ac3_xsin[i] | ac3_xcos[i] */
! 		"pfmul %%mm3, %%mm0\n\t"
! 		"pfmul %%mm3, %%mm1\n\t"
! #ifndef HAVE_3DNOWEX
! 		"pxor  %%mm7, %%mm0\n\t"
! 		"pfacc %%mm1, %%mm0\n\t"
! 		"movd %%mm0, 4%0\n\t"
! 		"psrlq $32, %%mm0\n\t"
! 		"movd %%mm0, %0\n\t"
! #else
! 		"pfpnacc %%mm1, %%mm0\n\t" /* mm0 = mm0[0] - mm0[1] | mm1[0] + mm1[1] */
! 		"pswapd %%mm0, %%mm0\n\t"
! 		"movq %%mm0, %0"
! #endif
! 		:"=m"(buf[i])
! 		:"m"(buf[i]),"m"(xcos1[i]),"m"(xsin1[i])
! 		:"memory");
! /*		ac3_buf[i].re =(tmp_a_r * ac3_xcos1[i])  +  (tmp_a_i  * ac3_xsin1[i]);
! 		ac3_buf[i].im =(tmp_a_r * ac3_xsin1[i])  -  (tmp_a_i  * ac3_xcos1[i]);*/
  	}
  
+ 	data_ptr = data;
  	delay_ptr = delay;
! 	window_ptr = window;
! // Window and convert to real valued signal
! 	for (i=0; i< 64; i++) {
! /* merge two loops in one to enable working of 2 decoders */
! 	__asm__ __volatile__ (
! 		"movd	516(%1), %%mm0\n\t"
! 		"movd	(%1), %%mm1\n\t" /**data_ptr++=-buf[64+i].im**window_ptr;*/
! 		"punpckldq (%2), %%mm0\n\t"/*data_ptr[128]=-buf[i].re*window_ptr[128];*/
! 		"punpckldq 516(%2), %%mm1\n\t"
! 		"pfmul	(%3), %%mm0\n\t"/**data_ptr++=buf[64-i-1].re**window_ptr;*/
! 		"pfmul	512(%3), %%mm1\n\t"
! 		"pxor	%%mm6, %%mm0\n\t"/*data_ptr[128]=buf[128-i-1].im*window_ptr[128];*/
! 		"pxor	%%mm6, %%mm1\n\t"
! 		"movq	%%mm0, (%0)\n\t"
! 		"movq	%%mm1, 512(%0)"
! 		:"=r"(data_ptr)
! 		:"r"(&buf[i].re), "r"(&buf[64-i-1].re), "r"(window_ptr), "0"(data_ptr)
! 		:"memory");
! 		data_ptr += 2;
! 		window_ptr += 2;
! 		delay_ptr += 2;
! 	}
! 	window_ptr += 128;
! // The trailing edge of the window goes into the delay line
! 	delay_ptr = delay;
! 	for(i=0; i< 64; i++) {
! /* merge two loops in one to enable working of 2 decoders */
! 	    window_ptr -=2;
! 	    __asm__ __volatile__(
! 		"movd	508(%1), %%mm0\n\t"
! 		"movd	(%1), %%mm1\n\t"
! 		"punpckldq (%2), %%mm0\n\t"
! 		"punpckldq 508(%2), %%mm1\n\t"
! #ifdef HAVE_3DNOWEX
! 		"pswapd	(%3), %%mm3\n\t"
! 		"pswapd	-512(%3), %%mm4\n\t"
! #else
! 		"movq	(%3), %%mm3\n\t"/**delay_ptr++=-buf[64+i].re**--window_ptr;*/
! 		"movq	-512(%3), %%mm4\n\t"
! 		"psrlq	$32, %%mm3\n\t"/*delay_ptr[128]=buf[i].im**window_ptr[-512];*/
! 		"psrlq	$32, %%mm4\n\t"/**delay_ptr++=buf[64-i-1].im**--window_ptr;*/
! 		"punpckldq (%3), %%mm3\n\t"/*delay_ptr[128]=-buf[128-i-1].re**window_ptr[-512];*/
! 		"punpckldq -512(%3), %%mm4\n\t"
! #endif
! 		"pfmul	%%mm3, %%mm0\n\t"
! 		"pfmul	%%mm4, %%mm1\n\t"
! 		"pxor	%%mm6, %%mm0\n\t"
! 		"pxor	%%mm7, %%mm1\n\t"
! 		"movq	%%mm0, (%0)\n\t"
! 		"movq	%%mm1, 512(%0)"
! 		:"=r"(delay_ptr)
! 		:"r"(&buf[i].im), "r"(&buf[64-i-1].im), "r"(window_ptr), "0"(delay_ptr)
! 		:"memory");
! 		delay_ptr += 2;
! 	}
!   __asm__ __volatile__ ("femms":::"memory");
  }
  


_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog



More information about the MPlayer-cvslog mailing list