📄 basic_op.h
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS and its licensors.** All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.** See below for additional copyright and license information**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#ifndef BASIC_OP_H#define BASIC_OP_H/*___________________________________________________________________________ | | | Constants and Globals | | | | $Id $ |___________________________________________________________________________|*/extern Flag Overflow;extern Flag Carry;#define MAX_32 (Word32)0x7fffffffL#define MIN_32 (Word32)0x80000000L#define MAX_16 (Word16)0x7fff#define MIN_16 (Word16)0x8000/*___________________________________________________________________________ | | | Prototypes for basic arithmetic operators | |___________________________________________________________________________|*/#define round Roundstatic inline Word16 add (Word16 var1, Word16 var2); /* Short add, 1 */static inline Word16 sub (Word16 var1, Word16 var2); /* Short sub, 1 */static inline Word16 abs_s (Word16 var1); /* Short abs, 1 */static inline Word16 shl (Word16 var1, Word16 var2); /* Short shift left, 1 */static inline Word16 shr (Word16 var1, Word16 var2); /* Short shift right, 1 */static inline Word16 mult (Word16 var1, Word16 var2); /* Short mult, 1 */static inline Word32 L_mult (Word16 var1, Word16 var2); /* Long mult, 1 */static inline Word16 negate (Word16 var1); /* Short negate, 1 */static inline Word16 extract_h (Word32 L_var1); /* Extract high, 1 */static inline Word16 extract_l (Word32 L_var1); /* Extract low, 1 */static inline Word16 round (Word32 L_var1); /* Round, 1 */static inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2); /* Mac, 1 */static inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2); /* Msu, 1 */static inline Word32 L_macNs (Word32 L_var3, Word16 var1, Word16 var2); /* Mac without sat, 1 */static inline Word32 L_msuNs (Word32 L_var3, Word16 var1, Word16 var2); /* Msu without sat, 1 */static inline Word32 L_add (Word32 L_var1, Word32 L_var2); /* Long add, 2 */static inline Word32 L_sub (Word32 L_var1, Word32 L_var2); /* Long sub, 2 */static inline Word32 L_add_c (Word32 L_var1, Word32 L_var2); /* Long add with c, 2 */static inline Word32 L_sub_c (Word32 L_var1, Word32 L_var2); /* Long sub with c, 2 */static inline Word32 L_negate (Word32 L_var1); /* Long negate, 2 */static inline Word16 mult_r (Word16 var1, Word16 var2); /* Mult with round, 2 */static inline Word32 L_shl (Word32 L_var1, Word16 var2); /* Long shift left, 2 */static inline Word32 L_shr (Word32 L_var1, Word16 var2); /* Long shift right, 2*/static inline Word16 shr_r (Word16 var1, Word16 var2); /* Shift right with round, 2 */static inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2); /* Mac with rounding,2 */static inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2); /* Msu with rounding,2 */static inline Word32 L_deposit_h (Word16 var1); /* 16 bit var1 -> MSB, 2 */static inline Word32 L_deposit_l (Word16 var1); /* 16 bit var1 -> LSB, 2 */static inline Word32 L_shr_r (Word32 L_var1, Word16 var2); /* Long shift right with round, 3 */static inline Word32 L_abs (Word32 L_var1); /* Long abs, 3 */static inline Word32 L_sat (Word32 L_var1); /* Long saturation, 4 */static inline Word16 norm_s (Word16 var1); /* Short norm, 15 */static inline Word16 div_s (Word16 var1, Word16 var2); /* Short division, 18 */static inline Word16 norm_l (Word32 L_var1); /* Long norm, 30 */ /*___________________________________________________________________________ | | | Local Functions | |___________________________________________________________________________|*/static inline Word16 saturate (Word32 L_var1);/*___________________________________________________________________________ | | | Functions | |___________________________________________________________________________|*//*___________________________________________________________________________ | | | Function Name : saturate | | | | Purpose : | | | | Limit the 32 bit input to the range of a 16 bit word. | | | | 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 : | | | | var_out | | 16 bit short signed integer (Word16) whose value falls in the | | range : 0xffff 8000 <= var_out <= 0x0000 7fff. | |___________________________________________________________________________|*/static inline Word16 saturate (Word32 L_var1){ Word16 var_out; if (L_var1 > 0X00007fffL) { Overflow = 1; var_out = MAX_16; } else if (L_var1 < (Word32) 0xffff8000L) { Overflow = 1; var_out = MIN_16; } else { var_out = extract_l (L_var1);#if (WMOPS) multiCounter[currCounter].extract_l--;#endif } return (var_out);}/*___________________________________________________________________________ | | | Function Name : add | | | | Purpose : | | | | Performs the addition (var1+var2) with overflow control and saturation;| | the 16 bit result is set at +32767 when overflow occurs or at -32768 | | when underflow occurs. | | | | 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. | |___________________________________________________________________________|*/static inline Word16 add (Word16 var1, Word16 var2){ Word16 var_out; Word32 L_sum; L_sum = (Word32) var1 + var2; var_out = saturate (L_sum);#if (WMOPS) multiCounter[currCounter].add++;#endif return (var_out);}/*___________________________________________________________________________ | | | Function Name : sub | | | | Purpose : | | | | Performs the subtraction (var1+var2) with overflow control and satu- | | ration; the 16 bit result is set at +32767 when overflow occurs or at | | -32768 when underflow occurs. | | | | 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. | |___________________________________________________________________________|*/static inline Word16 sub (Word16 var1, Word16 var2){ Word16 var_out; Word32 L_diff; L_diff = (Word32) var1 - var2; var_out = saturate (L_diff);#if (WMOPS) multiCounter[currCounter].sub++;#endif return (var_out);}/*___________________________________________________________________________
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -