# 请教 这个函数完成什么功能 谢谢

darwinmarx 2010-10-17 11:13:07
void mul_wide_s32(int in0, int in1, unsigned int *ptrOutBitsHi, unsigned int *ptrOutBitsLo)
{
unsigned int absIn0;//输入In0的绝对值
unsigned int absIn1;//输入In1的绝对值
unsigned int in0Lo;//输入In0绝对值的低16位
unsigned int in0Hi;//输入In0绝对值的高16位
unsigned int in1Lo;//输入In1绝对值的低16位
unsigned int in1Hi;//输入In1绝对值的高16位
unsigned int productHiLo;//In0的高16位与In的低16位的乘积
unsigned int productLoHi;//In0的低16位与In的高16位的乘积
unsigned int productLoLo;//In0的低16位与In的低16位的乘积

absIn0 = (unsigned int)(in0 < 0 ? -in0 : in0);//对In0取绝对值
absIn1 = (unsigned int)(in1 < 0 ? -in1 : in1);//对In1取绝对值

in0Hi = absIn0>>16;
in0Lo = absIn0 &65535U;
in1Hi = absIn1>>16;
in1Lo = absIn1 &65535U;

productHiLo = in0Hi*in1Lo;
productLoHi = in0Lo*in1Hi;
productLoLo = in0Lo*in1Lo;

absIn1 = (unsigned int)0;
//以下语句不知如何理解 求高人指点 谢谢
in0Lo = (productLoHi << 16) + productLoLo;
if (in0Lo < productLoLo)
{
absIn1 = (unsigned int)1;
}

absIn0 = in0Lo;
in0Lo = (productHiLo << 16) + in0Lo;
if (in0Lo < absIn0)
{
absIn1 = absIn1+(unsigned int)1;
}

absIn0 = ((in0Hi * in1Hi + absIn1) + (productLoHi >> 16)) + (productHiLo >> 16);
if (!((in0 == 0) || (in1 == 0) || ((in0 > 0) == (in1 > 0)))) {
absIn0 = ~absIn0;
in0Lo = ~in0Lo;
in0Lo = in0Lo + (unsigned int)1;
if (in0Lo == (unsigned int)0) {
absIn0 = absIn0 + (unsigned int)1;
}
}

*ptrOutBitsHi = absIn0;
*ptrOutBitsLo = in0Lo;

}

...全文
48 点赞 收藏 3

3 条回复

Jerry_Lee01 2010-10-19

houyu123 2010-10-18

asideu 2010-10-18

in0Lo = (productLoHi << 16) + productLoLo;

in0lo=in0lo*in1hi<<16+in0lo*in1lo;

---------------
in0Lo < productLoLo 就是 加法溢出 后面也是加法溢出。

2.1w+

2010-10-17 11:13