📄 basic_op.c
字号:
* falls in the range
* 0x8000 0000 <= L_var2 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* swOut
* 16 bit short signed integer (Word16) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
* 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.
* Round the 32 bit result by adding 0x0000 8000 to the input.
* The result may overflow due to the add. If so, the result
* is saturated. The 32 bit rounded number is then shifted
* down 16 bits and returned as a Word16.
*
* 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, macr
*
*************************************************************************/
Word16 msu_r(Word32 L_var3, Word16 var1, Word16 var2)
{
return (round32(L_msu(L_var3, var1, var2)));
}
/***************************************************************************
*
* FUNCTION NAME: mult
*
* PURPOSE:
*
* Perform a fractional multipy of the two 16 bit input numbers
* with saturation and truncation.
*
* 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:
*
* swOut
* 16 bit short signed integer (Word16) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Perform a fractional multipy of the two 16 bit input
* numbers. If var1 == var2 == -0x8000, output 0x7fff.
* Otherwise output var1*var2 >> 15. The output is a
* 16 bit number.
*
* KEYWORDS: mult, mulitply, mpy
*
*************************************************************************/
Word16 mult(Word16 var1, Word16 var2)
{
Word32 L_product;
Word16 swOut;
L_product = L_mult(var1, var2);
swOut = extract_h(L_product);
#ifdef WMOPS_FX
counter_fx.mult++;
counter_fx.L_mult--;
counter_fx.extract_h--;
#endif
return (swOut);
}
/***************************************************************************
*
* FUNCTION NAME: mult_r
*
* PURPOSE:
*
* Perform a fractional multipy and round of the two 16 bit
* input numbers with saturation.
*
* 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:
*
* swOut
* 16 bit short signed integer (Word16) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* This routine is defined as the concatenation of the multiply
* operation and the round operation.
*
* The fractional multiply (L_mult) produces a saturated 32 bit
* output. This is followed by a an add of 0x0000 8000 to the
* 32 bit result. The result may overflow due to the add. If
* so, the result is saturated. The 32 bit rounded number is
* then shifted down 16 bits and returned as a Word16.
*
*
* KEYWORDS: multiply and round, round, mult_r, mpyr
*
*************************************************************************/
Word16 mult_r(Word16 var1, Word16 var2)
{
Word16 swOut;
swOut = round32(L_mult(var1, var2));
#ifdef WMOPS_FX
counter_fx.mult_r++;
counter_fx.L_mult--;
counter_fx.round--;
#endif
return (swOut);
}
/***************************************************************************
*
* FUNCTION NAME: negate
*
* PURPOSE:
*
* Negate the 16 bit input. 0x8000's negated value is 0x7fff.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* swOut
* 16 bit short signed integer (Word16) whose value
* falls in the range
* 0xffff 8001 <= swOut <= 0x0000 7fff.
*
* KEYWORDS: negate, negative, invert
*
*************************************************************************/
Word16 negate(Word16 var1)
{
Word16 swOut;
if (var1 == SW_MIN)
{
swOut = SW_MAX;
giOverflow = 1;
}
else
swOut = -var1;
#ifdef WMOPS_FX
counter_fx.negate++;
#endif
return (swOut);
}
/***************************************************************************
*
* FUNCTION NAME: norm_l
*
* PURPOSE:
*
* Get normalize shift count:
*
* A 32 bit number is input (possiblly unnormalized). Output
* the positive (or zero) shift count required to normalize the
* input.
*
* 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:
*
* swOut
* 16 bit short signed integer (Word16) whose value
* falls in the range
* 0 <= swOut <= 31
*
*
*
* IMPLEMENTATION:
*
* Get normalize shift count:
*
* A 32 bit number is input (possiblly unnormalized). Output
* the positive (or zero) shift count required to normalize the
* input.
*
* If zero in input, return 0 as the shift count.
*
* For non-zero numbers, count the number of left shift
* required to get the number to fall into the range:
*
* 0x4000 0000 >= normlzd number >= 0x7fff ffff (positive number)
* or
* 0x8000 0000 <= normlzd number < 0xc000 0000 (negative number)
*
* Return the number of shifts.
*
* This instruction corresponds exactly to the Full-Rate "norm"
* instruction.
*
* KEYWORDS: norm, normalization
*
*************************************************************************/
Word16 norm_l(Word32 L_var1)
{
Word16 swShiftCnt;
if (L_var1 != 0)
{
if (!(L_var1 & LW_SIGN))
{
/* positive input */
for (swShiftCnt = 0; !(L_var1 <= LW_MAX && L_var1 >= 0x40000000L);
swShiftCnt++)
{
L_var1 = L_var1 << 1;
}
}
else
{
/* negative input */
for (swShiftCnt = 0;
!(L_var1 >= LW_MIN && L_var1 < (Word32) 0xc0000000L);
swShiftCnt++)
{
L_var1 = L_var1 << 1;
}
}
}
else
{
swShiftCnt = 0;
}
#ifdef WMOPS_FX
counter_fx.norm_l++;
#endif
return (swShiftCnt);
}
/***************************************************************************
*
* FUNCTION NAME: norm_s
*
* PURPOSE:
*
* Get normalize shift count:
*
* A 16 bit number is input (possiblly unnormalized). Output
* the positive (or zero) shift count required to normalize the
* input.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Word16) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
* swOut
* 16 bit short signed integer (Word16) whose value
* falls in the range
* 0 <= swOut <= 15
*
*
*
* IMPLEMENTATION:
*
* Get normalize shift count:
*
* A 16 bit number is input (possiblly unnormalized). Output
* the positive (or zero) shift count required to normalize the
* input.
*
* If zero in input, return 0 as the shift count.
*
* For non-zero numbers, count the number of left shift
* required to get the number to fall into the range:
*
* 0x4000 >= normlzd number >= 0x7fff (positive number)
* or
* 0x8000 <= normlzd number < 0xc000 (negative number)
*
* Return the number of shifts.
*
* This instruction corresponds exactly to the Full-Rate "norm"
* instruction.
*
* KEYWORDS: norm, normalization
*
*************************************************************************/
Word16 norm_s(Word16 var1)
{
short swShiftCnt;
Word32 L_var1;
L_var1 = L_deposit_h(var1);
swShiftCnt = norm_l(L_var1);
#ifdef WMOPS_FX
counter_fx.norm_s++;
counter_fx.L_deposit_h--;
counter_fx.norm_l--;
#endif
return (swShiftCnt);
}
/****************************************************************************
*
* FUNCTION NAME: popOverflow
*
* PURPOSE:
*
* Pull the old overflow state from the "stack". Replace the current
* overflow status with its predecessor.
*
* INPUTS:
*
* none
*
*
* OUTPUTS: none
*
* RETURN VALUE: value of datum about the be lost (usually the
* temporary saturation state)
*
* KEYWORDS: saturation, limit, overflow
*
***************************************************************************/
int popOverflow(void)
{
int i;
i = giOverflow;
giOverflow = giOldOverflow;
return (i);
}
/***************************************************************************
*
* FUNCTION NAME: round
*
* PURPOSE:
*
* Round the 32 bit Word32 into a 16 bit shortword with saturation.
*
* 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:
*
* swOut
* 16 bit short signed integer (Word16) whose value
* falls in the range
* 0xffff 8000 <
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -