⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 math64.h

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

/* platform-specific routines and macros. */

///////////////////////////////////////////////////////////////////////////////////////
// MSVC / i386
///////////////////////////////////////////////////////////////////////////////////////

#if (defined(_M_IX86) && defined(_MSC_VER)) || (defined(__WINS__) && defined(_SYMBIAN)) || (defined(__WINS__) && defined(WINCE_EMULATOR)) || (defined(_OPENWAVE_SIMULATOR))

#define HAVE_PLATFORM_MACROS

#pragma warning(disable:4035)
/* Compute a * b / c, using 64-bit intermediate result */
static __inline int MulDiv64(int a, int b, int c)
{
	__asm mov	eax, a
	__asm imul	b
	__asm idiv	c
}

/* Compute (a * b) >> 32, using 64-bit intermediate result */
static __inline int MulShift32(int a, int b)
{
	__asm mov	eax, a
	__asm imul	b
  __asm mov eax, edx
}

/* Compute (a * b) >> 31, using 64-bit intermediate result */
static __inline int MulShift31(int a, int b)
{
	__asm mov	eax, a
	__asm imul	b
	__asm shrd	eax, edx, 31
}

/* Compute (a * b) >> 30, using 64-bit intermediate result */
static __inline int MulShift30(int a, int b)
{
	__asm mov	eax, a
	__asm imul	b
	__asm shrd	eax, edx, 30
}

/* Compute (a * b) >> n, using 64-bit intermediate result */
static __inline int MulShiftN(int a, int b, int n)
{
	__asm mov	eax, a
	__asm imul	b
	__asm mov	ecx, n
	__asm shrd	eax, edx, cl
}
#ifdef DEBUG
#ifdef ASSERT
#undef ASSERT
#endif
#define ASSERT(x) if (!(x)) __asm int 3;
#endif

#ifdef TIMING
__int64 _timestamp;
__inline __int64 rdtsc() {
//    __asm   rdtsc  /* timestamp in edx:eax */
    __asm _emit 0x0f __asm _emit 0x31 // MSVC5 does not know rdtsc
}

#define TICK() _timestamp = rdtsc();
#define TOCK(nsamples) (_timestamp = rdtsc() - _timestamp, \
	printf("cycles =%4.0f\n", _timestamp / (double)(nsamples)) , _timestamp)
#endif // TIMING

#pragma warning(default:4035)
#endif // (defined(_M_IX86) && defined(_MSC_VER)) || (defined(__WINS__) && defined(_SYMBIAN))

///////////////////////////////////////////////////////////////////////////////////////
// GCC / i386
///////////////////////////////////////////////////////////////////////////////////////

#if defined(__GNUC__) && defined(__i386__)

#define HAVE_PLATFORM_MACROS

/* Compute a * b / c, using 64-bit intermediate result */
static __inline__ int MulDiv64(register int x, register int y, register int z)
{
    int zhi ;
    /* we specify four alternatives here, one for each permutation of memory or
       register operand in the multiplier and the divisor. All are commutative in
       the multiplication arguments, one of which needs to be in eax when we
       start. */
    __asm__ volatile ("imull %3\n\t"
                      "idivl %4"
                      : "=&d,&d,&d,&d" (zhi), "+a,a,a,a" (x)
                      : "%1,%1,%1,%1" (x), "m,r,m,r" (y), "m,m,r,r" (z)) ;

    return x ;
}

/* Compute (a * b) >> 32, using 64-bit intermediate result */
static __inline__ int MulShift32(int x, int y)
{
    int z ;
    /* we specify two alternatives here. The first one can read the multiplier from
       memory, the second from from a register. Both return the result in eax,edx
       and are commutative in the arguments, one of which needs to be in eax when we
       start. */
    __asm__ volatile ("imull %3" : "=d,d" (z), "+a,a" (x): "%1,1" (x), "m,r" (y)) ;
    return z ;
}

/* Compute (a * b) >> 31, using 64-bit intermediate result */
static __inline__ int MulShift31(int x, int y)
{
    int zhi ;
    __asm__ volatile ("imull %3\n\t"
                      "shrdl $31,%1,%0": "+a,a" (x), "=d,d" (zhi) : "%0,%0" (x), "m,r" (y)) ;
    return x ;
}

/* Compute (a * b) >> 30, using 64-bit intermediate result */
static __inline__ int MulShift30(int x, int y)
{
    int zhi ;
    __asm__ volatile ("imull %3\n\t"
                      "shrdl $30,%1,%0" : "+a,a" (x), "=d,d" (zhi) : "%0,%0" (x), "m,r" (y)) ;
    return x ;
}

/* Compute (a * b) >> n, using 64-bit intermediate result */
static __inline__ int MulShiftN(register int x, register int y, register int n)
{
    int zhi ;
    __asm__ volatile ("imull %3\n\t"
                      "shrdl %%cl,%1,%0" : "+a,a" (x), "=d,d" (zhi) : "%0,%0" (x), "m,r" (y), "c,c" (n)) ;
    return x ;
}

#ifdef TIMING
long long _timestamp;
static __inline__ long long rdtsc() {
    long long r ;
    __asm__ __volatile ("rdtsc" : "=A" (r)) ;
    return r ;    
}

#define TICK() _timestamp = rdtsc();
#define TOCK(nsamples) (_timestamp = rdtsc() - _timestamp, \
	printf("cycles =%4.0f\n", _timestamp / (double)(nsamples)), _timestamp)
#endif

#ifdef DEBUG
#define ASSERT(x) if (!(x)) __asm__ __volatile ("int $3" :: )
#endif
#endif // defined(__GNUC__) && defined(__i386__)

///////////////////////////////////////////////////////////////////////////////////////
// Sun native compiler / Sparc
///////////////////////////////////////////////////////////////////////////////////////

#if defined(__sparc)

// the macros definitions come from an il file here.
#define HAVE_PLATFORM_MACROS

/* Compute a * b / c, using 64-bit intermediate result */
signed int MulDiv64(signed int a, signed int b, signed int c) ;

/* Compute (a * b) >> 31, using 64-bit intermediate result */
signed int MulShift31(signed int a, signed int b) ;

/* Compute (a * b) >> 32, using 64-bit intermediate result */
signed int MulShift32(signed int a, signed int b) ;

/* Compute (a * b) >> n, using 64-bit intermediate result */
signed int MulShiftN(signed int a, signed int b, signed int n) ;

#ifdef TIMING
int _t1 ;
int rdtsc() ;
#define TICK() _t1 = rdtsc()
#define TOCK(nsamples) (_t1 = rdtsc()-_t1 , printf("cycles = %4.1f\n", \
  _t1 / (double)(nsamples)), _t1 )
#endif


#define HAVE_FASTABS
static inline int FASTABS(int x) 
{
	int sign;

	sign = x >> 31;
	x ^= sign;
	x -= sign;

	return x;
}


#ifdef DEBUG
#include <assert.h>
#define ASSERT(x)  assert(x)
#endif
#endif // defined(__sparc)

///////////////////////////////////////////////////////////////////////////////////////
// Codewarrior / PowerPC
///////////////////////////////////////////////////////////////////////////////////////

#if defined(__MWERKS__) && defined(__POWERPC__)

/*if your compiler can compile 64-bit instructions, define this. CW 8 cannot */
/* #define USE_64BIT_INSNS */

#define HAVE_PLATFORM_MACROS

/* Compute a * b / c, using 64-bit intermediate result */
#ifdef USE_64BIT_INSNS
inline int MulDiv64(register int a, register int b, register int c)
{
	asm {
		mulhd r0,a,b
		divd r0,r0,c
	}
}
#else
inline int MulDiv64(double a, double b, double c)
{
	return (int)( (a/c) * b ) ;
}
#endif

/* Compute (a * b) >> 30, using 64-bit intermediate result */
inline int MulShift30(register int a, register int b)
{
	register int res ;
#ifdef USE_64BIT_INSNS
	asm {
		mulhd res,a,b
		srd res,30
	}
#else
	asm {
		mulhw res,a,b
		slwi res,res,2 // not exact; last two bits are wrong
	}
#endif	
	return res ;
}

/* Compute (a * b) >> 31, using 64-bit intermediate result */
inline int MulShift31(register int a, register int b)
{
	register int res ;
#ifdef USE_64BIT_INSNS
	asm {
		mulhd res,a,b
		srd res,31
	}
#else
	asm {
		mulhw res,a,b
		slwi res,res,1 // not exact; last bit is wrong half the time
	}
#endif	
	return res ;
}

/* Compute (a * b) >> 32, using 64-bit intermediate result */
inline int MulShift32(register int a, register int b)
{
	register int res ;
	asm {
		mulhw res,a,b
	}
	return res ;
}

/* Compute (a * b) >> n, using 64-bit intermediate result */
//inline int MulShiftN(register int a, register int b, register int n)
static int MulShiftN(register int a, register int b, int n)
{
#ifdef USE_64BIT_INSNS
	register int res ;
	asm {
		mulhd res,a,b
		srd res,n
	}
	return res ;
#else
	register unsigned int temp ;
	int result ;

	asm {
		mullw  temp,a,b
	}
	result = temp >> n ;

	asm {	
		mulhw  temp,a,b
	}
	result |= (temp << (32-n)) ;
	
	return result ;
#endif
}

#ifdef TIMING
static unsigned int tick,tock ;
inline void fTICK()
{ register int t ; asm { mftb t } ; tick = t ; }
inline void fTOCK()
{ register int t ; asm { mftb t } ; tock = t ;
  if (tock < tick) {
  	tock += 65536 ; tick -= 65536 ; 
  }
}

#define TICK() fTICK()
#define TOCK(nsamples) ( fTOCK() , printf("cycles = %4.1f\n",4.0f*(tock-tick)/(float)(nsamples)), \
	tock-tick )

#endif // TIMING

#endif //  defined(__MWERKS__) && defined(__POWERPC__)


///////////////////////////////////////////////////////////////////////////////////////
// GCC / PowerPC
///////////////////////////////////////////////////////////////////////////////////////

#if defined(__GNUC__) && (defined(__POWERPC__) || defined(__powerpc__))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -