📄 enh1632.c
字号:
/*
===========================================================================
File: ENH1632.C v.2.0 - 15.Nov.2004
===========================================================================
ITU-T STL BASIC OPERATORS
ENHANCED 16-BIT & 32-BIT ARITHMETIC OPERATORS
History:
07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
operators for the ITU-T Standard Tool Library as
described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
TD 11 document and subsequent discussions on the
wp3audio@yahoogroups.com email reflector.
============================================================================
*/
/*****************************************************************************
*
* Enhanced 16/32 bit operators :
* s_max()
* s_min()
* L_max()
* L_min()
* shl_r()
* L_shl_r()
* L_mac0()
* L_mult0()
* L_msu0()
* s_and()
* s_or()
* s_xor()
* L_and()
* L_or()
* lshl()
* lshr()
* L_lshl()
* L_lshr()
* rotr()
* rotl()
* L_rotr()
* L_rotl()
*
*****************************************************************************/
/*****************************************************************************
*
* Include-Files
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "stl.h"
#if (WMOPS)
extern BASIC_OP multiCounter[MAXCOUNTERS];
extern int currCounter;
#endif /* ifdef WMOPS */
/*****************************************************************************
*
* Local Functions
*
*****************************************************************************/
/*****************************************************************************
*
* Function Name : saturate
*
* Purpose :
*
* Limits the 32 bit input to the range of a 16 bit word.
* This function is defined in basicop2.c.
*
*****************************************************************************/
#ifdef _MSC_VER
extern Word16 saturate( Word32 L_var1);
#endif /* ifdef _MSC_VER */
/*****************************************************************************
*
* Constants and Globals
*
*****************************************************************************/
/*****************************************************************************
*
* Functions
*
*****************************************************************************/
/*****************************************************************************
*
* Function Name : lshl
*
* Purpose :
*
* Logically shifts left var1 by var2 positions.
* - If var2 is negative, var1 is shifted to the LSBits by (-var2)
* positions with insertion of 0 at the MSBit.
* - If var2 is positive, var1 is shifted to the MSBits by (var2)
* positions.
*
* 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 <= var2 <= 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.
*
*****************************************************************************/
Word16 lshl( Word16 var1, Word16 var2) {
Word16 var_out=0;
if( var2 < 0) {
var2 = -var2;
var_out = lshr( var1, var2);
#if (WMOPS)
multiCounter[currCounter].lshr--;
#endif /* ifdef WMOPS */
} else {
if( var2 == 0 || var1 == 0) {
var_out = var1;
} else if( var2 >= 16) {
var_out = 0;
} else {
var_out = var1 << var2;
}
}
#if (WMOPS)
multiCounter[currCounter].lshl++;
#endif /* ifdef WMOPS */
return( var_out);
}
/*****************************************************************************
*
* Function Name : lshr
*
* Purpose :
*
* Logically shifts right var1 by var2 positions.
* - If var2 is positive, var1 is shifted to the LSBits by (var2)
* positions with insertion of 0 at the MSBit.
* - If var2 is negative, var1 is shifted to the MSBits by (-var2)
* positions.
*
* 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 <= var2 <= 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.
*
*****************************************************************************/
Word16 lshr( Word16 var1, Word16 var2) {
Word16 var_out;
if( var2 < 0) {
var2 = -var2;
var_out = lshl( var1, var2);
#if (WMOPS)
multiCounter[currCounter].lshl--;
#endif /* ifdef WMOPS */
} else {
if( var2 == 0 || var1 == 0) {
var_out = var1;
} else if( var2 >= 16) {
var_out = 0;
} else {
var_out = var1 >> 1;
var_out = var_out & 0x7fff;
var_out = var_out >> ( var2-1);
}
}
#if (WMOPS)
multiCounter[currCounter].lshr++;
#endif /* ifdef WMOPS */
return( var_out);
}
/*****************************************************************************
*
* Function Name : L_lshl
*
* Purpose :
*
* Logically shifts left L_var1 by var2 positions.
* - If var2 is negative, L_var1 is shifted to the LSBits by (-var2)
* positions with insertion of 0 at the MSBit.
* - If var2 is positive, L_var1 is shifted to the MSBits by (var2)
* positions.
*
* Complexity weight : 1
*
* 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_var_out 32 bit long signed integer (Word32) whose value falls in
* the range 0x8000 0000 <= L_var_out <= 0x7fff ffff.
*
*****************************************************************************/
Word32 L_lshl( Word32 L_var1, Word16 var2) {
Word32 L_var_out=0;
if( var2 < 0) {
var2 = -var2;
L_var_out = L_lshr( L_var1, var2);
#if (WMOPS)
multiCounter[currCounter].L_lshr--;
#endif /* ifdef WMOPS */
} else {
if( var2 == 0 || L_var1 == 0) {
L_var_out = L_var1;
} else if( var2 >= 32) {
L_var_out = 0;
} else {
L_var_out = L_var1 << var2;
}
}
#if (WMOPS)
multiCounter[currCounter].L_lshl++;
#endif /* ifdef WMOPS */
return( L_var_out);
}
/*****************************************************************************
*
* Function Name : L_lshr
*
* Purpose :
*
* Logically shifts right L_var1 by var2 positions.
* - If var2 is positive, L_var1 is shifted to the LSBits by (var2)
* positions with insertion of 0 at the MSBit.
* - If var2 is negative, L_var1 is shifted to the MSBits by (-var2)
* positions.
*
* Complexity weight : 1
*
* 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_var_out 32 bit long signed integer (Word32) whose value falls in
* the range 0x8000 0000 <= L_var_out <= 0x7fff ffff.
*
*****************************************************************************/
Word32 L_lshr( Word32 L_var1, Word16 var2) {
Word32 L_var_out;
if( var2 < 0) {
var2 = -var2;
L_var_out = L_lshl( L_var1, var2);
#if (WMOPS)
multiCounter[currCounter].L_lshl--;
#endif /* ifdef WMOPS */
} else {
if( var2 == 0 || L_var1 == 0) {
L_var_out = L_var1;
} else if( var2 >= 32) {
L_var_out = 0;
} else {
L_var_out = L_var1 >> 1;
L_var_out = L_var_out & 0x7fffffff;
L_var_out = L_var_out >> (var2 - 1);
}
}
#if (WMOPS)
multiCounter[currCounter].L_lshr++;
#endif /* ifdef WMOPS */
return( L_var_out);
}
/*****************************************************************************
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -