sc_fxval.h
来自「基于4个mips核的noc设计」· C头文件 代码 · 共 1,863 行 · 第 1/5 页
H
1,863 行
inlineistream&operator >> ( istream& is, sc_fxval& a ){ a.scan( is ); return is;}// ----------------------------------------------------------------------------// CLASS : sc_fxval_fast//// Fixed-point value type; limited precision.// ----------------------------------------------------------------------------// protected methodinlinesc_fxval_fast_observer*sc_fxval_fast::observer() const{ return m_observer;}// public constructorsinlinesc_fxval_fast::sc_fxval_fast( sc_fxval_fast_observer* observer_ ): m_val( 0.0 ), m_observer( observer_ ){ SC_FXVAL_FAST_OBSERVER_DEFAULT_ SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )}inlinesc_fxval_fast::sc_fxval_fast( const sc_fxval_fast& a, sc_fxval_fast_observer* observer_ ): m_val( a.m_val ), m_observer( observer_ ){ SC_FXVAL_FAST_OBSERVER_DEFAULT_ SC_FXVAL_FAST_OBSERVER_READ_( a ) SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this ) SC_FXVAL_FAST_OBSERVER_WRITE_( *this )}#define DEFN_CTOR_T(tp,arg) \inline \sc_fxval_fast::sc_fxval_fast( tp a, \ sc_fxval_fast_observer* observer_ ) \: m_val( arg ), \ m_observer( observer_ ) \{ \ SC_FXVAL_FAST_OBSERVER_DEFAULT_ \ SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this ) \ SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \}#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,static_cast<double>( a ))#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,from_string( a ))#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())DEFN_CTOR_T_A(int)DEFN_CTOR_T_A(unsigned int)DEFN_CTOR_T_A(long)DEFN_CTOR_T_A(unsigned long)DEFN_CTOR_T_A(double)DEFN_CTOR_T_B(const char*)DEFN_CTOR_T_C(const sc_fxval&)#ifndef SC_FX_EXCLUDE_OTHERDEFN_CTOR_T_A(int64)DEFN_CTOR_T_A(uint64)DEFN_CTOR_T_C(const sc_int_base&)DEFN_CTOR_T_C(const sc_uint_base&)DEFN_CTOR_T_C(const sc_signed&)DEFN_CTOR_T_C(const sc_unsigned&)#endif#undef DEFN_CTOR_T#undef DEFN_CTOR_T_A#undef DEFN_CTOR_T_B#undef DEFN_CTOR_T_C#undef DEFN_CTOR_T_D#undef DEFN_CTOR_T_Einlinesc_fxval_fast::~sc_fxval_fast(){ SC_FXVAL_FAST_OBSERVER_DESTRUCT_( *this )}// internal use only;inlinedoublesc_fxval_fast::get_val() const{ SC_FXVAL_FAST_OBSERVER_READ_( *this ) return m_val;}// internal use only;inlinevoidsc_fxval_fast::set_val( double val_ ){ m_val = val_; SC_FXVAL_FAST_OBSERVER_WRITE_( *this )}// unary operatorsinlineconst sc_fxval_fastsc_fxval_fast::operator - () const{ SC_FXVAL_FAST_OBSERVER_READ_( *this ) return sc_fxval_fast( - m_val );}inlineconst sc_fxval_fast&sc_fxval_fast::operator + () const{ // SC_FXVAL_FAST_OBSERVER_READ_( *this ) return *this;}// unary functionsinlinevoidneg( sc_fxval_fast& c, const sc_fxval_fast& a ){ SC_FXVAL_FAST_OBSERVER_READ_( a ) c.m_val = - a.m_val; SC_FXVAL_FAST_OBSERVER_WRITE_( c )}// binary operators#define DEFN_BIN_OP_T(op,tp) \inline \const sc_fxval_fast \operator op ( const sc_fxval_fast& a, tp b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( a ) \ sc_fxval_fast tmp( b ); \ return sc_fxval_fast( a.m_val op tmp.m_val ); \} \ \inline \const sc_fxval_fast \operator op ( tp a, const sc_fxval_fast& b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( b ) \ sc_fxval_fast tmp( a ); \ return sc_fxval_fast( tmp.m_val op b.m_val ); \}#ifndef SC_FX_EXCLUDE_OTHER#define DEFN_BIN_OP_OTHER(op) \DEFN_BIN_OP_T(op,int64) \DEFN_BIN_OP_T(op,uint64) \DEFN_BIN_OP_T(op,const sc_int_base&) \DEFN_BIN_OP_T(op,const sc_uint_base&) \DEFN_BIN_OP_T(op,const sc_signed&) \DEFN_BIN_OP_T(op,const sc_unsigned&)#else#define DEFN_BIN_OP_OTHER(op)#endif#define DEFN_BIN_OP(op,dummy) \inline \const sc_fxval_fast \operator op ( const sc_fxval_fast& a, const sc_fxval_fast& b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( a ) \ SC_FXVAL_FAST_OBSERVER_READ_( b ) \ return sc_fxval_fast( a.m_val op b.m_val ); \} \ \DEFN_BIN_OP_T(op,int) \DEFN_BIN_OP_T(op,unsigned int) \DEFN_BIN_OP_T(op,long) \DEFN_BIN_OP_T(op,unsigned long) \DEFN_BIN_OP_T(op,double) \DEFN_BIN_OP_T(op,const char*) \DEFN_BIN_OP_OTHER(op)DEFN_BIN_OP(*,mult)DEFN_BIN_OP(+,add)DEFN_BIN_OP(-,sub)//DEFN_BIN_OP(/,div)inlineconst sc_fxval_fastoperator / ( const sc_fxval_fast& a, const sc_fxval_fast& b ){ SC_FXVAL_FAST_OBSERVER_READ_( a ) SC_FXVAL_FAST_OBSERVER_READ_( b ) return sc_fxval_fast( a.m_val / b.m_val );}DEFN_BIN_OP_T(/,int)DEFN_BIN_OP_T(/,unsigned int)DEFN_BIN_OP_T(/,long)DEFN_BIN_OP_T(/,unsigned long)DEFN_BIN_OP_T(/,double)DEFN_BIN_OP_T(/,const char*)//DEFN_BIN_OP_OTHER(/)#ifndef SC_FX_EXCLUDE_OTHERDEFN_BIN_OP_T(/,int64)DEFN_BIN_OP_T(/,uint64)DEFN_BIN_OP_T(/,const sc_int_base&)DEFN_BIN_OP_T(/,const sc_uint_base&)DEFN_BIN_OP_T(/,const sc_signed&)DEFN_BIN_OP_T(/,const sc_unsigned&)#endif#undef DEFN_BIN_OP_T#undef DEFN_BIN_OP_OTHER#undef DEFN_BIN_OPinlineconst sc_fxval_fastoperator << ( const sc_fxval_fast& a, int b ){ SC_FXVAL_FAST_OBSERVER_READ_( a ) return sc_fxval_fast( a.m_val * scfx_pow2( b ) );}inlineconst sc_fxval_fastoperator >> ( const sc_fxval_fast& a, int b ){ SC_FXVAL_FAST_OBSERVER_READ_( a ) return sc_fxval_fast( a.m_val * scfx_pow2( -b ) );}// binary functions#define DEFN_BIN_FNC_T(fnc,op,tp) \inline \void \fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, tp b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( a ) \ sc_fxval_fast tmp( b ); \ c.m_val = a.m_val op tmp.m_val; \ SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \} \ \inline \void \fnc ( sc_fxval_fast& c, tp a, const sc_fxval_fast& b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( b ) \ sc_fxval_fast tmp( a ); \ c.m_val = tmp.m_val op b.m_val; \ SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \}#ifndef SC_FX_EXCLUDE_OTHER#define DEFN_BIN_FNC_OTHER(fnc,op) \DEFN_BIN_FNC_T(fnc,op,int64) \DEFN_BIN_FNC_T(fnc,op,uint64) \DEFN_BIN_FNC_T(fnc,op,const sc_int_base&) \DEFN_BIN_FNC_T(fnc,op,const sc_uint_base&) \DEFN_BIN_FNC_T(fnc,op,const sc_signed&) \DEFN_BIN_FNC_T(fnc,op,const sc_unsigned&)#else#define DEFN_BIN_FNC_OTHER(fnc,op)#endif#define DEFN_BIN_FNC(fnc,op) \inline \void \fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, const sc_fxval_fast& b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( a ) \ SC_FXVAL_FAST_OBSERVER_READ_( b ) \ c.m_val = a.m_val op b.m_val; \ SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \} \ \DEFN_BIN_FNC_T(fnc,op,int) \DEFN_BIN_FNC_T(fnc,op,unsigned int) \DEFN_BIN_FNC_T(fnc,op,long) \DEFN_BIN_FNC_T(fnc,op,unsigned long) \DEFN_BIN_FNC_T(fnc,op,double) \DEFN_BIN_FNC_T(fnc,op,const char*) \DEFN_BIN_FNC_OTHER(fnc,op)DEFN_BIN_FNC(mult,*)DEFN_BIN_FNC(div,/)DEFN_BIN_FNC(add,+)DEFN_BIN_FNC(sub,-)#undef DEFN_BIN_FNC_T#undef DEFN_BIN_FNC_OTHER#undef DEFN_BIN_FNCinlinevoidlshift( sc_fxval_fast& c, const sc_fxval_fast& a, int b ){ SC_FXVAL_FAST_OBSERVER_READ_( a ) c.m_val = a.m_val * scfx_pow2( b ); SC_FXVAL_FAST_OBSERVER_WRITE_( c )}inlinevoidrshift( sc_fxval_fast& c, const sc_fxval_fast& a, int b ){ SC_FXVAL_FAST_OBSERVER_READ_( a ) c.m_val = a.m_val * scfx_pow2( -b ); SC_FXVAL_FAST_OBSERVER_WRITE_( c )}// relational (including equality) operators#define DEFN_REL_OP_T(op,tp) \inline \bool \operator op ( const sc_fxval_fast& a, tp b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( a ) \ sc_fxval_fast tmp( b ); \ return ( a.m_val op tmp.m_val ); \} \ \inline \bool \operator op ( tp a, const sc_fxval_fast& b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( b ) \ sc_fxval_fast tmp( a ); \ return ( tmp.m_val op b.m_val ); \}#ifndef SC_FX_EXCLUDE_OTHER#define DEFN_REL_OP_OTHER(op) \DEFN_REL_OP_T(op,int64) \DEFN_REL_OP_T(op,uint64) \DEFN_REL_OP_T(op,const sc_int_base&) \DEFN_REL_OP_T(op,const sc_uint_base&) \DEFN_REL_OP_T(op,const sc_signed&) \DEFN_REL_OP_T(op,const sc_unsigned&)#else#define DEFN_REL_OP_OTHER(op)#endif#define DEFN_REL_OP(op) \inline \bool \operator op ( const sc_fxval_fast& a, const sc_fxval_fast& b ) \{ \ SC_FXVAL_FAST_OBSERVER_READ_( a ) \ SC_FXVAL_FAST_OBSERVER_READ_( b )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?