⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iqmathcpp.h

📁 TMS320X281xDSP应用系统设计-光盘应用程序
💻 H
📖 第 1 页 / 共 5 页
字号:
//###########################################################################
//
// FILE:	IQmathCPP.h
//
// TITLE:	IQ Math C++ definitions.
//
//###########################################################################
//
// Ver  | dd-mmm-yyyy |  Who  | Description of changes
// =====|=============|=======|==============================================
//  1.3 | 19 Nov 2001 | A. T. | Original Release.
// -----|-------------|-------|----------------------------------------------
//  1.4 | 17 May 2002 | A. T. | Added new functions and support for
//      |             |       | intrinsics IQmpy, IQxmpy, IQsat.
//      |             |       | Added support for boolean and bit-wise
//      |             |       | operations.
//      |             |       | Expanded Q support range: 15 <= Q <= 30
// -----|-------------|-------|----------------------------------------------
//      |             |       |
//
//###########################################################################

//###########################################################################
#if MATH_TYPE == IQ_MATH
//###########################################################################
// If IQ_MATH is used, the following IQmath library definitions are used:
//===========================================================================

struct iq {
	//constructors:
	iq () : val(0) { }
	iq (long x) : val(x) { }

	//copy constructor:
	iq (const iq & x) : val(x.val) { }

	//assignment operators:
	inline iq & operator = (const iq & x);

	//arithmetic operators:
	inline iq & operator += (const iq &x);
	inline iq & operator -= (const iq &x);
	inline iq & operator *= (const iq &x);
	inline iq & operator /= (const iq &x);

    //bitwise operators:
    inline iq & operator &= (const long &x);
    inline iq & operator |= (const long &x);
    inline iq & operator ^= (const long &x);

	long val;
};

struct iq30 {
	//constructors:
	iq30 () : val(0) { }
	iq30 (long x) : val(x) { }

	//copy constructor:
	iq30 (const iq30 & x) : val(x.val) { }

	//assignment operators:
	inline iq30 & operator = (const iq30 & x);

	//arithmetic operators:
	inline iq30 & operator += (const iq30 &x);
	inline iq30 & operator -= (const iq30 &x);
	inline iq30 & operator *= (const iq30 &x);
	inline iq30 & operator /= (const iq30 &x);

    //bitwise operators:
    inline iq30 & operator &= (const long &x);
    inline iq30 & operator |= (const long &x);
    inline iq30 & operator ^= (const long &x);

	long val;
};

struct iq29 {
	//constructors:
	iq29 () : val(0) { }
	iq29 (long x) : val(x) { }

	//copy constructor:
	iq29 (const iq29 & x) : val(x.val) { }

	//assignment operators:
	inline iq29 & operator = (const iq29 & x);

	//arithmetic operators:
	inline iq29 & operator += (const iq29 &x);
	inline iq29 & operator -= (const iq29 &x);
	inline iq29 & operator *= (const iq29 &x);
	inline iq29 & operator /= (const iq29 &x);

    //bitwise operators:
    inline iq29 & operator &= (const long &x);
    inline iq29 & operator |= (const long &x);
    inline iq29 & operator ^= (const long &x);

	long val;
};

struct iq28 {
	//constructors:
	iq28 () : val(0) { }
	iq28 (long x) : val(x) { }

	//copy constructor:
	iq28 (const iq28 & x) : val(x.val) { }

	//assignment operators:
	inline iq28 & operator = (const iq28 & x);

	//arithmetic operators:
	inline iq28 & operator += (const iq28 &x);
	inline iq28 & operator -= (const iq28 &x);
	inline iq28 & operator *= (const iq28 &x);
	inline iq28 & operator /= (const iq28 &x);

    //bitwise operators:
    inline iq28 & operator &= (const long &x);
    inline iq28 & operator |= (const long &x);
    inline iq28 & operator ^= (const long &x);

	long val;
};

struct iq27 {
	//constructors:
	iq27 () : val(0) { }
	iq27 (long x) : val(x) { }

	//copy constructor:
	iq27 (const iq27 & x) : val(x.val) { }

	//assignment operators:
	inline iq27 & operator = (const iq27 & x);

	//arithmetic operators:
	inline iq27 & operator += (const iq27 &x);
	inline iq27 & operator -= (const iq27 &x);
	inline iq27 & operator *= (const iq27 &x);
	inline iq27 & operator /= (const iq27 &x);

    //bitwise operators:
    inline iq27 & operator &= (const long &x);
    inline iq27 & operator |= (const long &x);
    inline iq27 & operator ^= (const long &x);

	long val;
};

struct iq26 {
	//constructors:
	iq26 () : val(0) { }
	iq26 (long x) : val(x) { }

	//copy constructor:
	iq26 (const iq26 & x) : val(x.val) { }

	//assignment operators:
	inline iq26 & operator = (const iq26 & x);

	//arithmetic operators:
	inline iq26 & operator += (const iq26 &x);
	inline iq26 & operator -= (const iq26 &x);
	inline iq26 & operator *= (const iq26 &x);
	inline iq26 & operator /= (const iq26 &x);

    //bitwise operators:
    inline iq26 & operator &= (const long &x);
    inline iq26 & operator |= (const long &x);
    inline iq26 & operator ^= (const long &x);

	long val;
};

struct iq25 {
	//constructors:
	iq25 () : val(0) { }
	iq25 (long x) : val(x) { }

	//copy constructor:
	iq25 (const iq25 & x) : val(x.val) { }

	//assignment operators:
	inline iq25 & operator = (const iq25 & x);

	//arithmetic operators:
	inline iq25 & operator += (const iq25 &x);
	inline iq25 & operator -= (const iq25 &x);
	inline iq25 & operator *= (const iq25 &x);
	inline iq25 & operator /= (const iq25 &x);

    //bitwise operators:
    inline iq25 & operator &= (const long &x);
    inline iq25 & operator |= (const long &x);
    inline iq25 & operator ^= (const long &x);

	long val;
};

struct iq24 {
	//constructors:
	iq24 () : val(0) { }
	iq24 (long x) : val(x) { }

	//copy constructor:
	iq24 (const iq24 & x) : val(x.val) { }

	//assignment operators:
	inline iq24 & operator = (const iq24 & x);

	//arithmetic operators:
	inline iq24 & operator += (const iq24 &x);
	inline iq24 & operator -= (const iq24 &x);
	inline iq24 & operator *= (const iq24 &x);
	inline iq24 & operator /= (const iq24 &x);

    //bitwise operators:
    inline iq24 & operator &= (const long &x);
    inline iq24 & operator |= (const long &x);
    inline iq24 & operator ^= (const long &x);

	long val;
};

struct iq23 {
	//constructors:
	iq23 () : val(0) { }
	iq23 (long x) : val(x) { }

	//copy constructor:
	iq23 (const iq23 & x) : val(x.val) { }

	//assignment operators:
	inline iq23 & operator = (const iq23 & x);

	//arithmetic operators:
	inline iq23 & operator += (const iq23 &x);
	inline iq23 & operator -= (const iq23 &x);
	inline iq23 & operator *= (const iq23 &x);
	inline iq23 & operator /= (const iq23 &x);

    //bitwise operators:
    inline iq23 & operator &= (const long &x);
    inline iq23 & operator |= (const long &x);
    inline iq23 & operator ^= (const long &x);

	long val;
};

struct iq22 {
	//constructors:
	iq22 () : val(0) { }
	iq22 (long x) : val(x) { }

	//copy constructor:
	iq22 (const iq22 & x) : val(x.val) { }

	//assignment operators:
	inline iq22 & operator = (const iq22 & x);

	//arithmetic operators:
	inline iq22 & operator += (const iq22 &x);
	inline iq22 & operator -= (const iq22 &x);
	inline iq22 & operator *= (const iq22 &x);
	inline iq22 & operator /= (const iq22 &x);

    //bitwise operators:
    inline iq22 & operator &= (const long &x);
    inline iq22 & operator |= (const long &x);
    inline iq22 & operator ^= (const long &x);

	long val;
};

struct iq21 {
	//constructors:
	iq21 () : val(0) { }
	iq21 (long x) : val(x) { }

	//copy constructor:
	iq21 (const iq21 & x) : val(x.val) { }

	//assignment operators:
	inline iq21 & operator = (const iq21 & x);

	//arithmetic operators:
	inline iq21 & operator += (const iq21 &x);
	inline iq21 & operator -= (const iq21 &x);
	inline iq21 & operator *= (const iq21 &x);
	inline iq21 & operator /= (const iq21 &x);

    //bitwise operators:
    inline iq21 & operator &= (const long &x);
    inline iq21 & operator |= (const long &x);
    inline iq21 & operator ^= (const long &x);

	long val;
};

struct iq20 {
	//constructors:
	iq20 () : val(0) { }
	iq20 (long x) : val(x) { }

	//copy constructor:
	iq20 (const iq20 & x) : val(x.val) { }

	//assignment operators:
	inline iq20 & operator = (const iq20 & x);

	//arithmetic operators:
	inline iq20 & operator += (const iq20 &x);
	inline iq20 & operator -= (const iq20 &x);
	inline iq20 & operator *= (const iq20 &x);
	inline iq20 & operator /= (const iq20 &x);

    //bitwise operators:
    inline iq20 & operator &= (const long &x);
    inline iq20 & operator |= (const long &x);
    inline iq20 & operator ^= (const long &x);

	long val;
};

struct iq19 {
	//constructors:
	iq19 () : val(0) { }
	iq19 (long x) : val(x) { }

	//copy constructor:
	iq19 (const iq19 & x) : val(x.val) { }

	//assignment operators:
	inline iq19 & operator = (const iq19 & x);

	//arithmetic operators:
	inline iq19 & operator += (const iq19 &x);
	inline iq19 & operator -= (const iq19 &x);
	inline iq19 & operator *= (const iq19 &x);
	inline iq19 & operator /= (const iq19 &x);

    //bitwise operators:
    inline iq19 & operator &= (const long &x);
    inline iq19 & operator |= (const long &x);
    inline iq19 & operator ^= (const long &x);

	long val;
};

struct iq18 {
	//constructors:
	iq18 () : val(0) { }
	iq18 (long x) : val(x) { }

	//copy constructor:
	iq18 (const iq18 & x) : val(x.val) { }

	//assignment operators:
	inline iq18 & operator = (const iq18 & x);

	//arithmetic operators:
	inline iq18 & operator += (const iq18 &x);
	inline iq18 & operator -= (const iq18 &x);
	inline iq18 & operator *= (const iq18 &x);
	inline iq18 & operator /= (const iq18 &x);

    //bitwise operators:
    inline iq18 & operator &= (const long &x);
    inline iq18 & operator |= (const long &x);
    inline iq18 & operator ^= (const long &x);

	long val;
};

struct iq17 {
	//constructors:
	iq17 () : val(0) { }
	iq17 (long x) : val(x) { }

	//copy constructor:
	iq17 (const iq17 & x) : val(x.val) { }

	//assignment operators:
	inline iq17 & operator = (const iq17 & x);

	//arithmetic operators:
	inline iq17 & operator += (const iq17 &x);
	inline iq17 & operator -= (const iq17 &x);
	inline iq17 & operator *= (const iq17 &x);
	inline iq17 & operator /= (const iq17 &x);

    //bitwise operators:
    inline iq17 & operator &= (const long &x);
    inline iq17 & operator |= (const long &x);
    inline iq17 & operator ^= (const long &x);

	long val;
};

struct iq16 {
	//constructors:
	iq16 () : val(0) { }
	iq16 (long x) : val(x) { }

	//copy constructor:
	iq16 (const iq16 & x) : val(x.val) { }

	//assignment operators:
	inline iq16 & operator = (const iq16 & x);

	//arithmetic operators:
	inline iq16 & operator += (const iq16 &x);
	inline iq16 & operator -= (const iq16 &x);
	inline iq16 & operator *= (const iq16 &x);
	inline iq16 & operator /= (const iq16 &x);

    //bitwise operators:
    inline iq16 & operator &= (const long &x);
    inline iq16 & operator |= (const long &x);
    inline iq16 & operator ^= (const long &x);

	long val;
};

struct iq15 {
	//constructors:
	iq15 () : val(0) { }
	iq15 (long x) : val(x) { }

	//copy constructor:
	iq15 (const iq15 & x) : val(x.val) { }

	//assignment operators:
	inline iq15 & operator = (const iq15 & x);

	//arithmetic operators:
	inline iq15 & operator += (const iq15 &x);
	inline iq15 & operator -= (const iq15 &x);
	inline iq15 & operator *= (const iq15 &x);
	inline iq15 & operator /= (const iq15 &x);

    //bitwise operators:
    inline iq15 & operator &= (const long &x);
    inline iq15 & operator |= (const long &x);
    inline iq15 & operator ^= (const long &x);

	long val;
};

//---------------------------------------------------------------------------
// Functions: IQ(A), IQN(A)
//---------------------------------------------------------------------------

#define IQ(A)   (iq)   _IQ(A)
#define IQ30(A) (iq30) _IQ30(A)
#define IQ29(A) (iq29) _IQ29(A)
#define IQ28(A) (iq28) _IQ28(A)
#define IQ27(A) (iq27) _IQ27(A)
#define IQ26(A) (iq26) _IQ26(A)
#define IQ25(A) (iq25) _IQ25(A)
#define IQ24(A) (iq24) _IQ24(A)
#define IQ23(A) (iq23) _IQ23(A)
#define IQ22(A) (iq22) _IQ22(A)
#define IQ21(A) (iq21) _IQ21(A)
#define IQ20(A) (iq20) _IQ20(A)
#define IQ19(A) (iq19) _IQ19(A)
#define IQ18(A) (iq18) _IQ18(A)
#define IQ17(A) (iq17) _IQ17(A)
#define IQ16(A) (iq16) _IQ16(A)
#define IQ15(A) (iq15) _IQ15(A)

//---------------------------------------------------------------------------
// Functions: IQtoF(A), IQNtoF(A)
//---------------------------------------------------------------------------

inline	float	IQtoF(iq x)     { return _IQtoF(x.val);   }
inline	float	IQ30toF(iq30 x) { return _IQ30toF(x.val); }
inline	float	IQ29toF(iq29 x) { return _IQ29toF(x.val); }
inline	float	IQ28toF(iq28 x) { return _IQ28toF(x.val); }
inline	float	IQ27toF(iq27 x) { return _IQ27toF(x.val); }
inline	float	IQ26toF(iq26 x) { return _IQ26toF(x.val); }
inline	float	IQ25toF(iq25 x) { return _IQ25toF(x.val); }
inline	float	IQ24toF(iq24 x) { return _IQ24toF(x.val); }
inline	float	IQ23toF(iq23 x) { return _IQ23toF(x.val); }
inline	float	IQ22toF(iq22 x) { return _IQ22toF(x.val); }
inline	float	IQ21toF(iq21 x) { return _IQ21toF(x.val); }
inline	float	IQ20toF(iq20 x) { return _IQ20toF(x.val); }
inline	float	IQ19toF(iq19 x) { return _IQ19toF(x.val); }
inline	float	IQ18toF(iq18 x) { return _IQ18toF(x.val); }
inline	float	IQ17toF(iq17 x) { return _IQ17toF(x.val); }
inline	float	IQ16toF(iq16 x) { return _IQ16toF(x.val); }
inline	float	IQ15toF(iq15 x) { return _IQ15toF(x.val); }

//---------------------------------------------------------------------------
// Functions: IQsat(A, Pos, Neg)
//---------------------------------------------------------------------------

inline	iq		IQsat(iq x, iq Pos, iq Neg)   
{ 
	iq temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq30	IQsat(iq30 x, iq30 Pos, iq30 Neg)   
{ 
	iq30 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq29	IQsat(iq29 x, iq29 Pos, iq29 Neg)   
{ 
	iq29 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq28	IQsat(iq28 x, iq28 Pos, iq28 Neg)   
{ 
	iq28 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq27	IQsat(iq27 x, iq27 Pos, iq27 Neg)   
{ 
	iq27 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq26	IQsat(iq26 x, iq26 Pos, iq26 Neg)   
{ 
	iq26 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq25	IQsat(iq25 x, iq25 Pos, iq25 Neg)   
{ 
	iq25 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq24	IQsat(iq24 x, iq24 Pos, iq24 Neg)   
{ 
	iq24 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq23	IQsat(iq23 x, iq23 Pos, iq23 Neg)   
{ 
	iq23 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq22	IQsat(iq22 x, iq22 Pos, iq22 Neg)   
{ 
	iq22 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq21	IQsat(iq21 x, iq21 Pos, iq21 Neg)   
{ 
	iq21 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq20	IQsat(iq20 x, iq20 Pos, iq20 Neg)   
{ 
	iq20 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq19	IQsat(iq19 x, iq19 Pos, iq19 Neg)   
{ 
	iq19 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq18	IQsat(iq18 x, iq18 Pos, iq18 Neg)   
{ 
	iq18 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq17	IQsat(iq17 x, iq17 Pos, iq17 Neg)   
{ 
	iq17 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq16	IQsat(iq16 x, iq16 Pos, iq16 Neg)   
{ 
	iq16 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

inline	iq15	IQsat(iq15 x, iq15 Pos, iq15 Neg)   
{ 
	iq15 temp;
	temp.val = _IQsat(x.val, Pos.val, Neg.val);
	return temp;   
}

//---------------------------------------------------------------------------
// Functions: IQtoIQN(A)
//---------------------------------------------------------------------------

inline iq30 IQtoIQ30(iq x)
{
	iq30 temp;
	temp.val = _IQtoIQ30(x.val);
	return temp;
}

inline iq29 IQtoIQ29(iq x)
{
	iq29 temp;
	temp.val = _IQtoIQ29(x.val);
	return temp;
}

inline iq28 IQtoIQ28(iq x)
{
	iq28 temp;
	temp.val = _IQtoIQ28(x.val);
	return temp;
}

inline iq27 IQtoIQ27(iq x)
{
	iq27 temp;
	temp.val = _IQtoIQ27(x.val);
	return temp;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -