📄 basic_op.h
字号:
| |
| Complexity weight : 1 |
| |
| Inputs : |
| |
| var1 |
| 16 bit short signed integer (Word16) whose value falls in the |
| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
| |
| Outputs : |
| |
| none |
| |
| Return Value : |
| |
| var_out |
| 16 bit short signed integer (Word16) whose value falls in the |
| range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
|___________________________________________________________________________|
*/ __inline
Word16 abs_s (Word16 var1)
{
Word16 var_out;
if (var1 == (Word16) 0X8000)
{
var_out = MAX_16;
}
else
{
if (var1 < 0)
{
var_out = (Word16 )(-var1);
}
else
{
var_out = var1;
}
}
return (var_out);
}
/*___________________________________________________________________________
| |
| Function Name : shl |
| |
| Purpose : |
| |
| Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
| the var2 LSB of the result. If var2 is negative, arithmetically shift |
| var1 right by -var2 with sign extension. Saturate the result in case of |
| underflows or overflows. |
| |
| Complexity weight : 1 |
| |
| 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 <= var1 <= 0x0000 7fff. |
| |
| Outputs : |
| |
| none |
| |
| Return Value : |
| |
| var_out |
| 16 bit short signed integer (Word16) whose value falls in the |
| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
|___________________________________________________________________________|
*/ __inline
Word16 shl (Word16 var1, Word16 var2)
{
Word16 var_out;
Word16 neg_var2;
Word32 result;
if (var2 < 0)
{
neg_var2 = negate(var2);
var_out = shr (var1, neg_var2);
}
else
{
result = (Word32) var1 *((Word32) 1 << var2);
if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
{
Overflow = 1;
var_out = (var1 > 0) ? MAX_16 : MIN_16;
}
else
{
var_out = extract_l (result);
}
}
return (var_out);
}
/*___________________________________________________________________________
| |
| Function Name : shr |
| |
| Purpose : |
| |
| Arithmetically shift the 16 bit input var1 right var2 positions with |
| sign extension. If var2 is negative, arithmetically shift var1 left by |
| -var2 with sign extension. Saturate the result in case of underflows or |
| overflows. |
| |
| Complexity weight : 1 |
| |
| 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 <= var1 <= 0x0000 7fff. |
| |
| Outputs : |
| |
| none |
| |
| Return Value : |
| |
| var_out |
| 16 bit short signed integer (Word16) whose value falls in the |
| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
|___________________________________________________________________________|
*/ __inline
Word16 shr (Word16 var1, Word16 var2)
{
Word16 var_out;
Word16 neg_var2;
if (var2 < 0)
{
neg_var2 = negate(var2);
var_out = shl (var1, neg_var2);
}
else
{
if (var2 >= 15)
{
var_out = (var1 < 0) ? -1 : 0;
}
else
{
if (var1 < 0)
{
var_out = ~((~var1) >> var2);
}
else
{
var_out = var1 >> var2;
}
}
}
return (var_out);
}
/*___________________________________________________________________________
| |
| Function Name : mult |
| |
| Purpose : |
| |
| Performs the multiplication of var1 by var2 and gives a 16 bit result |
| which is scaled i.e.: |
| mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and |
| mult(-32768,-32768) = 32767. |
| |
| Complexity weight : 1 |
| |
| 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 <= var1 <= 0x0000 7fff. |
| |
| Outputs : |
| |
| none |
| |
| Return Value : |
| |
| var_out |
| 16 bit short signed integer (Word16) whose value falls in the |
| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
|___________________________________________________________________________|
*/ __inline
Word16 mult (Word16 var1, Word16 var2)
{
Word16 var_out;
Word32 L_product;
L_product = (Word32) var1 *(Word32) var2;
L_product = (L_product & (Word32) 0xffff8000L) >> 15;
if (L_product & (Word32) 0x00010000L)
L_product = L_product | (Word32) 0xffff0000L;
var_out = saturate (L_product);
return (var_out);
}
/*___________________________________________________________________________
| |
| Function Name : L_mult |
| |
| Purpose : |
| |
| L_mult is the 32 bit result of the multiplication of var1 times var2 |
| with one shift left i.e.: |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -