📄 mathevrc.c
字号:
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* swOut
* 16 bit short signed integer (Shortword) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* KEYWORDS: assign, truncate
*
*************************************************************************/
Shortword extract_h(Longword L_var1)
{
Shortword var2;
OP_COUNT(1); /* Complexity Count -- LT 6/96 */
var2 = (Shortword) (0x0000ffffL & (L_var1 >> 16));
return (var2);
}
/***************************************************************************
*
* FUNCTION NAME: extract_l
*
* PURPOSE:
*
* Extract the 16 LS bits of a 32 bit Longword. Return the 16 bit
* number as a Shortword. The upper portion of the input Longword
* has no impact whatsoever on the output.
*
* INPUTS:
*
* L_var1
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* swOut
* 16 bit short signed integer (Shortword) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
*
* KEYWORDS: extract, assign
*
*************************************************************************/
Shortword extract_l(Longword L_var1)
{
Shortword var2;
OP_COUNT(1); /* Complexity Count -- LT 6/96 */
var2 = (Shortword) (0x0000ffffL & L_var1);
return (var2);
}
/****************************************************************************
*
* FUNCTION NAME: isOverflow
*
* PURPOSE:
*
* Check to see whether an overflow/saturation/limiting has occurred
*
* INPUTS:
*
* none
*
*
* OUTPUTS: none
*
* RETURN VALUE: 1 if overflow has been flagged
* 0 otherwise
*
* KEYWORDS: saturation, limit, overflow
*
***************************************************************************/
int isOverflow(void)
{
return (giOverflow);
}
/***************************************************************************
*
* FUNCTION NAME: L_abs
*
* PURPOSE:
*
* Take the absolute value of the 32 bit input. An input of
* -0x8000 0000 results in a return value of 0x7fff ffff.
*
* INPUTS:
*
* L_var1
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
*
*
* KEYWORDS: absolute value, abs
*
*************************************************************************/
Longword L_abs(Longword L_var1)
{
Longword L_Out;
OP_COUNT(3); /* Complexity Count -- LT 6/96 */
if (L_var1 == LW_MIN)
{
L_Out = LW_MAX;
giOverflow = 1;
}
else
{
if (L_var1 < 0)
L_Out = -L_var1;
else
L_Out = L_var1;
}
return (L_Out);
}
/***************************************************************************
*
* FUNCTION NAME: L_add
*
* PURPOSE:
*
* Perform the addition of the two 32 bit input variables with
* saturation.
*
* INPUTS:
*
* L_var1
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
* L_var2
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var2 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Perform the addition of the two 32 bit input variables with
* saturation.
*
* L_Out = L_var1 + L_var2
*
* L_Out is set to 0x7fff ffff if the operation results in an
* overflow. L_Out is set to 0x8000 0000 if the operation
* results in an underflow.
*
* KEYWORDS: add, addition
*
*************************************************************************/
Longword L_add(Longword L_var1, Longword L_var2)
{
Longword L_Sum;
double dSum;
OP_COUNT(2); /* Complexity Count -- LT 6/96 */
dSum = (double) L_var1 + (double) L_var2;
L_Sum = L_var1 + L_var2;
if (dSum != (double) L_Sum)
{
/* overflow occurred */
L_Sum = L_saturate(dSum); OP_COUNT(-4);
}
return (L_Sum);
}
/***************************************************************************
*
* FUNCTION NAME: L_deposit_h
*
* PURPOSE:
*
* Put the 16 bit input into the 16 MSB's of the output Longword. The
* LS 16 bits are zeroed.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff 0000.
*
*
* KEYWORDS: deposit, assign, fractional assign
*
*************************************************************************/
Longword L_deposit_h(Shortword var1)
{
Longword L_var2;
OP_COUNT(1); /* Complexity Count -- LT 6/96 */
L_var2 = (Longword) var1 << 16;
return (L_var2);
}
/***************************************************************************
*
* FUNCTION NAME: L_deposit_l
*
* PURPOSE:
*
* Put the 16 bit input into the 16 LSB's of the output Longword with
* sign extension i.e. the top 16 bits are set to either 0 or 0xffff.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0xffff 8000 <= L_var1 <= 0x0000 7fff.
*
* KEYWORDS: deposit, assign
*
*************************************************************************/
Longword L_deposit_l(Shortword var1)
{
Longword L_Out;
OP_COUNT(1); /* Complexity Count -- LT 6/96 */
L_Out = var1;
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 (Shortword) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
* var2
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
* L_var3
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var2 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) 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
*
*************************************************************************/
Longword L_mac(Longword L_var3, Shortword var1, Shortword var2)
{
Longword L_product;
double dlwA, dlwB;
OP_COUNT(1); /* Complexity Count -- LT 6/96 */
L_product = (Longword) var1 *var2; /* integer multiply */
if (L_product == (Longword) 0x40000000)
{
/* the event 0x8000 * 0x8000, the only possible saturation
* in the multiply */
L_product = L_saturate(2147483648.0 + (double) L_var3); OP_COUNT(-4);
}
else
{
/* no overflow possible in mult */
L_product = L_product << 1;
L_product = L_add(L_var3, L_product); OP_COUNT(-2);
}
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 (Shortword) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
* var2
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
* L_var3
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var2 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) 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
*
*************************************************************************/
Longword L_msu(Longword L_var3, Shortword var1, Shortword var2)
{
Longword L_product;
double dlwA, dlwB;
OP_COUNT(1); /* Complexity Count -- LT 6/96 */
L_product = (Longword) var1 *var2; /* integer multiply */
if (L_product == (Longword) 0x40000000)
{
/* the event 0x8000 * 0x8000, the only possible saturation
* in the multiply */
L_product = L_saturate((double) L_var3 - 2147483648.0); OP_COUNT(-4);
}
else
{
/* no overflow possible in mult */
L_product <<= 1;
L_product = L_sub(L_var3, L_product); OP_COUNT(-2); /* LT 6/96 */
}
return (L_product);
}
/***************************************************************************
*
* FUNCTION NAME: L_mult
*
* PURPOSE:
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -