📄 basic_op40.c
字号:
| |
| Perform an integer arithmetic shift on the double format value. |
| If nbits > 0, arithmetically shift the value left nbits positions. |
| Zero fill the nbits LSB of the value. |
| If nbits < 0, arithmetically shift the value right by -nbits positions |
| with sign extension. |
| No overflow control and saturation. |
|___________________________________________________________________________|
*/
static Word40 L_shift_left40(Word40 value, Word16 nbits)
{
if (nbits > 40) nbits = 40; /* to avoid needless loop after overflow */
if (nbits < -40) nbits = -40;
if (nbits < 0)
{
for(; nbits<0; nbits++)
{
value = value * 0.5; /* remove fraction bits */
}
value = floor(value);
}
else
{
value = floor(value); /* remove fraction bits */
for(; nbits>0; nbits--)
{
value = value * 2;
}
}
return(value);
}
/*___________________________________________________________________________
| |
| Function Name : L_saturate40 |
| |
| Purpose : |
| |
| Limit the value to the range of a 40 bit word. |
| |
| Return Value : |
| |
| var_out 40 bit short signed integer (Word40) whose value falls in the |
| range : MIN_40 <= var_out <= MAX_40. |
|___________________________________________________________________________|
*/
static Word40 L_saturate40(Word40 value)
{
Word40 L_var_out;
L_var_out = value;
if (L_var_out > MAX_40)
{
L_var_out = MAX_40;
giOverflow = 1;
}
else if (L_var_out < MIN_40)
{
L_var_out = MIN_40;
giOverflow = 1;
}
return(L_var_out);
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
//***************************************************************************
// public functions for 40 bit accumulator
//
// J. Klein, Conexant Systems 12/01/00
/*___________________________________________________________________________
| |
| Function Name : L_add40 |
| |
| Purpose : |
| |
| Add L_var1 by L_var2. Return a 40 bit result without saturation: |
| L_add40 (L_var1, L_var2). |
| |
| Complexity weight : 1 |
| |
| Inputs : |
| |
| L_var1 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var1 <= MAX_40. |
| |
| |
| L_var2 32 bit long signed integer (Word32) whose value falls in |
| the : MIN_32 <= L_var2 <= MAX_32. |
| |
| Return Value : |
| |
| L_var_out |
| 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var_out <= MAX_40. |
|___________________________________________________________________________|
*/
Word40 L_add40(Word40 L_var1, Word32 L_var2)
{
Word40 L_var_out;
L_var_out = L_var1 + (Word40)L_var2;
L_var_out = L_saturate40(L_var_out);
#ifdef WMOPS_FX
counter_fx.L_add40++;
#endif
return(L_var_out);
}
/*___________________________________________________________________________
| |
| Function Name : L_sub40 |
| |
| Purpose : |
| |
| Substract L_var1 by L_var2. Return a 40 bit result without saturation: |
| L_sub40 (L_var1, L_var2). |
| |
| Complexity weight : 1 |
| |
| Inputs : |
| |
| L_var1 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var1 <= MAX_40. |
| |
| |
| L_var2 32 bit long signed integer (Word32) whose value falls in |
| the : MIN_32 <= L_var2 <= MAX_32. |
| |
| Return Value : |
| |
| L_var_out |
| 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var_out <= MAX_40. |
|___________________________________________________________________________|
*/
Word40 L_sub40(Word40 L_var1, Word32 L_var2)
{
Word40 L_var_out;
L_var_out = L_var1 - (Word40)L_var2;
L_var_out = L_saturate40(L_var_out);
#ifdef WMOPS_FX
counter_fx.L_sub40++;
#endif
return(L_var_out);
}
/*___________________________________________________________________________
| |
| Function Name : L_mac40 |
| |
| Purpose : |
| |
| Multiply var1 by var2 and shift the result left by 1. Add the 40 bit |
| result to L_var3 with saturation, return a 40 bit result: |
| L_mac(L_var3,var1,var2) = L_add(L_var3,(L_mult(var1,var2)). |
| |
| Complexity weight : 1 |
| |
| Inputs : |
| |
| L_var3 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var3 <= MAX_40. |
| |
| var1 16 bit short signed integer (Word16) whose value falls in |
| the : MIN_16 <= var1 <= MAX_16. |
| |
| var2 16 bit short signed integer (Word16) whose value falls in |
| the : MIN_16 <= var1 <= MAX_16. |
| |
| Return Value : |
| |
| L_var_out |
| 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var_out <= MAX_40. |
|___________________________________________________________________________|
*/
Word40 L_mac40(Word40 L_var3, Word16 var1, Word16 var2)
{
Word40 L_var_out;
L_var_out = L_var3 + ((Word40)var1 * (Word40)var2 * 2.0);
L_var_out = L_saturate40(L_var_out);
#ifdef WMOPS_FX
counter_fx.L_mac40++;
#endif
return(L_var_out);
}
/*___________________________________________________________________________
| |
| Function Name : L_msu40 |
| |
| Purpose : |
| |
| Multiply var1 by var2 and shift the result left by 1. Subtract the 40 |
| bit result to L_var3 with saturation, return a 40 bit result: |
| L_msu(L_var3,var1,var2) = L_sub(L_var3,(L_mult(var1,var2)). |
| |
| Complexity weight : 1 |
| |
| Inputs : |
| |
| L_var3 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var3 <= MAX_40. |
| |
| var1 16 bit short signed integer (Word16) whose value falls in |
| the range : MIN_16 <= var1 <= MAX_16. |
| |
| var2 16 bit short signed integer (Word16) whose value falls in |
| therange : MIN_16 <= var1 <= MAX_16. |
| |
| Return Value : |
| |
| L_var_out |
| 40 bit long signed integer (Word40) whose value falls in the |
| range : MIN_40 <= L_var_out <= MAX_40. |
|___________________________________________________________________________|
*/
Word40 L_msu40(Word40 L_var3, Word16 var1, Word16 var2)
{
Word40 L_var_out;
L_var_out = L_var3 - ((Word40)var1 * (Word40)var2 * 2.0);
L_var_out = L_saturate40(L_var_out);
#ifdef WMOPS_FX
counter_fx.L_msu40++;
#endif
return(L_var_out);
}
/*___________________________________________________________________________
| |
| Function Name : L_shr40 |
| |
| Purpose : |
| |
| Arithmetically shift the 40 bit input L_var1 right var2 positions with |
| sign extension. If var2 is negative, arithmetically shift L_var1 left |
| by -var2 and zero fill the var2 LSB of the result. Saturate the result |
| in case of underflows or overflows. |
| |
| Complexity weight : 2 |
| |
| Inputs : |
| |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -