📄 basic_op.c
字号:
if (dSum != (double) L_Sum)
{
/* overflow occurred */
L_Sum = L_saturate(dSum); // OP_COUNT(-4);
#ifdef WMOPS_FX
counter_fx.L_saturate--;
#endif
}
#ifdef WMOPS_FX
counter_fx.L_add++;
#endif
return (L_Sum);
}
/***************************************************************************
*
* FUNCTION NAME: L_deposit_h
*
* PURPOSE:
*
* Put the 16 bit input into the 16 MSB's of the output Word32. The
* LS 16 bits are zeroed.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff 0000.
*
*
* KEYWORDS: deposit, assign, fractional assign
*
*************************************************************************/
Word32 L_deposit_h(Word16 var1)
{
Word32 L_var2;
L_var2 = (Word32) var1 << 16;
#ifdef WMOPS_FX
counter_fx.L_deposit_h++;
#endif
return (L_var2);
}
/***************************************************************************
*
* FUNCTION NAME: L_deposit_l
*
* PURPOSE:
*
* Put the 16 bit input into the 16 LSB's of the output Word32 with
* sign extension i.e. the top 16 bits are set to either 0 or 0xffff.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0xffff 8000 <= L_var1 <= 0x0000 7fff.
*
* KEYWORDS: deposit, assign
*
*************************************************************************/
Word32 L_deposit_l(Word16 var1)
{
Word32 L_Out;
L_Out = var1;
#ifdef WMOPS_FX
counter_fx.L_deposit_l++;
#endif
return (L_Out);
}
/***************************************************************************
*
* FUNCTION NAME: L_mac
*
* PURPOSE:
*
* Multiply accumulate. Fractionally multiply two 16 bit
* numbers together with saturation. Add that result to the
* 32 bit input with saturation. Return the 32 bit result.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
* var2
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
* L_var3
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var2 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Fractionally multiply two 16 bit numbers together with
* saturation. The only numbers which will cause saturation on
* the multiply are 0x8000 * 0x8000.
*
* Add that result to the 32 bit input with saturation.
* Return the 32 bit result.
*
* Please note that this is not a true multiply accumulate as
* most processors would implement it. The 0x8000*0x8000
* causes and overflow for this instruction. On most
* processors this would cause an overflow only if the 32 bit
* input added to it were positive or zero.
*
* KEYWORDS: mac, multiply accumulate
*
*************************************************************************/
Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2)
{
Word32 L_product;
L_product = (Word32) var1 *var2; /* integer multiply */
if (L_product == (Word32) 0x40000000)
{
/* the event 0x8000 * 0x8000, the only possible saturation
* in the multiply */
L_product = L_saturate(2147483648.0 + (double) L_var3);
#ifdef WMOPS_FX
counter_fx.L_saturate--;
#endif
}
else
{
/* no overflow possible in mult */
L_product = L_product << 1;
L_product = L_add(L_var3, L_product); // OP_COUNT(-2);
#ifdef WMOPS_FX
counter_fx.L_add--;
#endif
}
#ifdef WMOPS_FX
counter_fx.L_mac++;
#endif
return (L_product);
}
/***************************************************************************
*
* FUNCTION NAME: L_msu
*
* PURPOSE:
*
* Multiply and subtract. Fractionally multiply two 16 bit
* numbers together with saturation. Subtract that result from
* the 32 bit input with saturation. Return the 32 bit result.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
* var2
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
* L_var3
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var2 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Fractionally multiply two 16 bit numbers together with
* saturation. The only numbers which will cause saturation on
* the multiply are 0x8000 * 0x8000.
*
* Subtract that result from the 32 bit input with saturation.
* Return the 32 bit result.
*
* Please note that this is not a true multiply accumulate as
* most processors would implement it. The 0x8000*0x8000
* causes and overflow for this instruction. On most
* processors this would cause an overflow only if the 32 bit
* input added to it were negative or zero.
*
* KEYWORDS: mac, multiply accumulate, msu
*
*************************************************************************/
Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2)
{
Word32 L_product;
L_product = (Word32) var1 *var2; /* integer multiply */
if (L_product == (Word32) 0x40000000)
{
/* the event 0x8000 * 0x8000, the only possible saturation
* in the multiply */
L_product = L_saturate((double) L_var3 - 2147483648.0); // OP_COUNT(-4);
#ifdef WMOPS_FX
counter_fx.L_saturate--;
#endif
}
else
{
/* no overflow possible in mult */
L_product <<= 1;
L_product = L_sub(L_var3, L_product); // OP_COUNT(-2); /* LT 6/96 */
#ifdef WMOPS_FX
counter_fx.L_sub--;
#endif
}
#ifdef WMOPS_FX
counter_fx.L_msu++;
#endif
return (L_product);
}
/***************************************************************************
*
* FUNCTION NAME: L_mult
*
* PURPOSE:
*
* Perform a fractional multipy of the two 16 bit input numbers
* with saturation. Output a 32 bit number.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
* var2
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Multiply the two the two 16 bit input numbers. If the
* result is within this range, left shift the result by one
* and output the 32 bit number. The only possible overflow
* occurs when var1==var2==-0x8000. In this case output
* 0x7fff ffff.
*
* KEYWORDS: multiply, mult, mpy
*
*************************************************************************/
Word32 L_mult(Word16 var1, Word16 var2)
{
Word32 L_product;
if (var1 == SW_MIN && var2 == SW_MIN)
{
L_product = LW_MAX; /* overflow */
giOverflow = 1;
}
else
{
L_product = (Word32) var1 *var2; /* integer multiply */
L_product = L_product << 1;
}
#ifdef WMOPS_FX
counter_fx.L_mult++;
#endif
return (L_product);
}
/***************************************************************************
*
* FUNCTION NAME: L_negate
*
* PURPOSE:
*
* Negate the 32 bit input. 0x8000 0000's negated value is
* 0x7fff ffff.
*
* INPUTS:
*
* L_var1
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0001 <= L_var1 <= 0x7fff ffff.
*
* KEYWORDS: negate, negative
*
*************************************************************************/
Word32 L_negate(Word32 L_var1)
{
Word32 L_Out;
if (L_var1 == LW_MIN)
{
L_Out = LW_MAX;
giOverflow = 1;
}
else
L_Out = -L_var1;
#ifdef WMOPS_FX
counter_fx.L_negate++;
#endif
return (L_Out);
}
/***************************************************************************
*
* FUNCTION NAME: L_shift_r
*
* PURPOSE:
*
* Shift and round. Perform a shift right. After shifting, use
* the last bit shifted out of the LSB to round the result up
* or down.
*
* INPUTS:
*
* L_var1
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
* var2
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_var1
* 32 bit long signed integer (Word32) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
*
* IMPLEMENTATION:
*
* Shift and round. Perform a shift right. After shifting, use
* the last bit shifted out of the LSB to round the result up
* or down. This is just like shift_r above except that the
* input/output is 32 bits as opposed to 16.
*
* if var2 is positve perform a arithmetic left shift
* with saturation (see L_shl() above).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -