abs int 宏定义_ccs宏定义与调用问题

这篇博客主要介绍了在C语言中如何使用位操作宏定义,包括MULSHIFT32、FASTABS和CLZ等函数的实现,涉及了不同平台下的汇编优化。这些宏定义用于进行高效的乘法、取绝对值和计数前导零操作,适用于Symbian、Windows CE等平台的开发。
摘要由CSDN通过智能技术生成

#if (defined _WIN32 && !defined _WIN32_WCE) || (defined __WINS__ && defined _SYMBIAN) || defined(_OPENWAVE_SIMULATOR) || defined(WINCE_EMULATOR) /* Symbian emulator for Ix86 */

#pragma warning( disable : 4035 )        /* complains about inline asm not returning a value */

static __inline int MULSHIFT32(int x, int y)

{

__asm {

mov         eax, x

imul        y

mov         eax, edx

}

}

static __inline int FASTABS(int x)

{

int sign;

sign = x >> (sizeof(int) * 8 - 1);

x ^= sign;

x -= sign;

return x;

}

static __inline int CLZ(int x)

{

int numZeros;

if (!x)

return (sizeof(int) * 8);

numZeros = 0;

while (!(x & 0x80000000)) {

numZeros++;

x <<= 1;

}

return numZeros;

}

/* MADD64, SHL64, SAR64:

* write in assembly to avoid dependency on run-time lib for 64-bit shifts, muls

* (sometimes compiler thunks to function calls instead of code generating)

* required for Symbian emulator

*/

#ifdef __CW32__

typedef long long Word64;

#else

typedef __int64 Word64;

#endif

static __inline Word64 MADD64(Word64 sum, int x, int y)

{

unsigned int sumLo = ((unsigned int *)&sum)[0];

int sumHi = ((int *)&sum)[1];

__asm {

mov         eax, x

imul        y

add         eax, sumLo

adc         edx, sumHi

}

/* equivalent to return (sum + ((__int64)x * y)); */

}

static __inline Word64 SHL64(Word64 x, int n)

{

unsigned int xLo = ((unsigned int *)&x)[0];

int xHi = ((int *)&x)[1];

unsigned char nb = (unsigned char)n;

if (n < 32) {

__asm {

mov         edx, xHi

mov         eax, xLo

mov         cl, nb

shld edx, eax, cl

shl eax, cl

}

} else if (n < 64) {

/* shl masks cl to 0x1f */

__asm {

mov         edx, xLo

mov         cl, nb

xor eax, eax

shl edx, cl

}

} else {

__asm {

xor         edx, edx

xor         eax, eax

}

}

}

static __inline Word64 SAR64(Word64 x, int n)

{

unsigned int xLo = ((unsigned int *)&x)[0];

int xHi = ((int *)&x)[1];

unsigned char nb = (unsigned char)n;

if (n < 32) {

__asm {

mov         edx, xHi

mov         eax, xLo

mov         cl, nb

shrd        eax, edx, cl

sar         edx, cl

}

} else if (n < 64) {

/* sar masks cl to 0x1f */

__asm {

mov         edx, xHi

mov         eax, xHi

mov         cl, nb

sar         edx, 31

sar         eax, cl

}

} else {

__asm {

sar         xHi, 31

mov         eax, xHi

mov         edx, xHi

}

}

}

#elif (defined _WIN32) && (defined _WIN32_WCE)

/* use asm function for now (EVC++ 3.0 does horrible job compiling __int64 version) */

#define MULSHIFT32        xmp3_MULSHIFT32

int MULSHIFT32(int x, int y);

static __inline int FASTABS(int x)

{

int sign;

sign = x >> (sizeof(int) * 8 - 1);

x ^= sign;

x -= sign;

return x;

}

static __inline int CLZ(int x)

{

int numZeros;

if (!x)

return (sizeof(int) * 8);

numZeros = 0;

while (!(x & 0x80000000)) {

numZeros++;

x <<= 1;

}

return numZeros;

}

#elif defined ARM_ADS

static __inline int MULSHIFT32(int x, int y)

{

int zlow;

__asm {

smull zlow,y,x,y

}

return y;

}

static __inline int FASTABS(int x)

{

int t=0; /*Really is not necessary to initialiaze only to avoid warning*/

__asm {

eor        t, x, x, asr #31 // T:=X XOR (X>>31)

sub        t, t, x, asr #31 // T:=T-(X>>31)

}

return t;

}

static __inline int CLZ(int x)

{

int numZeros;

if (!x)

return (sizeof(int) * 8);

numZeros = 0;

while (!(x & 0x80000000)) {

numZeros++;

x <<= 1;

}

return numZeros;

}

#elif defined(__GNUC__) && defined(ARM)

typedef long long Word64;

#define MULSHIFT32        xmp3_MULSHIFT32

extern int MULSHIFT32(int x, int y);

#define FASTABS        xmp3_FASTABS

int FASTABS(int x);

static __inline int CLZ(int x)

{

int numZeros;

if (!x)

return (sizeof(int) * 8);

numZeros = 0;

while (!(x & 0x80000000)) {

numZeros++;

x <<= 1;

}

return numZeros;

}

#else

#error Unsupported platform in assembly.h

#endif        /* platforms */

#endif /* _ASSEMBLY_H */

Fixed-point HE-AAC decoder Developed by RealNetworks, 2005===============================Overview--------This module contains a high-performance HE-AAC decoder for 32-bit fixed-point processors. The following is a summary of what is and is not supported:Supported: - MPEG2, MPEG4 low complexity decoding (intensity stereo, M-S, TNS, PNS) - spectral band replication (SBR), high-quality mode - mono, stereo, and multichannel modes - ADTS, ADIF, and raw data block file formatsNot currently supported: - main or SSR profile, LTP - coupling channel elements (CCE) - 960/1920-sample frame size - low-power mode SBR - downsampled (single-rate) SBR - parametric stereoHighlights - highly optimized for ARM processors (details in docs/ subdirectory) - reference x86 implementation - C and assembly code only (C++ not required for codec library) - reentrant, statically linkable - low memory (details in docs/ subdirectory) - option to use Intel Integrated Performance Primitives (details below)Supported platforms and toolchainsThis codec should run on any 32-bit fixed-point processor which can perform a full 32x32-bit multiply (providing a 64-bit result). The following processors and toolchains are supported: - x86, Microsoft Visual C++ - x86, GNU toolchain (gcc) - ARM, ARM Developer Suite (ADS) - ARM, Microsoft Embedded Visual C++ - ARM, GNU toolchain (gcc)ARM refers to any processor supporting ARM architecture v.4 or above. Thumb is not required.Generally ADS produces the fastest code. EVC 3 does not support inline assembly code for ARM targets, so calls to MULSHIFT32 (smull on ARM) are left as function calls. This incurs a significant performance penalty. For the fastest code on targets which do not normally use ADS consider compiling with ADS, using the -S option to output assembly code, and feeding this assembly code to the assem
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值