sc_lv_base.h

来自「system C源码 一种替代verilog的语言」· C头文件 代码 · 共 1,815 行 · 第 1/4 页

H
1,815
字号
DEFN_BITWISE_AND_OP_T_B(unsigned long)DEFN_BITWISE_AND_OP_T_B(long)DEFN_BITWISE_AND_OP_T_B(unsigned int)DEFN_BITWISE_AND_OP_T_B(int)DEFN_BITWISE_AND_OP_T_B(uint64)DEFN_BITWISE_AND_OP_T_B(int64)#undef DEFN_BITWISE_AND_OP_T_B// bitwise ortemplate <class X, class Y>inlineX&operator |= ( sc_proxy<X>& px, const sc_proxy<Y>& py ){    X& x = px.back_cast();    sc_lv_base a( x.length() );    a = py.back_cast();    return b_or_assign_( x, a );}#define DEFN_BITWISE_OR_ASN_OP_T(tp)                                          \template <class X>                                                            \inline                                                                        \X&                                                                            \sc_proxy<X>::operator |= ( tp b )                                             \{                                                                             \    X& x = back_cast();                                                       \    sc_lv_base a( x.length() );                                               \    a = b;                                                                    \    return b_or_assign_( x, a );                                              \}DEFN_BITWISE_OR_ASN_OP_T(const char*)DEFN_BITWISE_OR_ASN_OP_T(const bool*)DEFN_BITWISE_OR_ASN_OP_T(const sc_logic*)DEFN_BITWISE_OR_ASN_OP_T(const sc_unsigned&)DEFN_BITWISE_OR_ASN_OP_T(const sc_signed&)DEFN_BITWISE_OR_ASN_OP_T(unsigned long)DEFN_BITWISE_OR_ASN_OP_T(long)DEFN_BITWISE_OR_ASN_OP_T(uint64)DEFN_BITWISE_OR_ASN_OP_T(int64)#undef DEFN_BITWISE_OR_ASN_OP_Ttemplate <class X, class Y>inlineconst sc_lv_baseoperator | ( const sc_proxy<X>& px, const sc_proxy<Y>& py ){    sc_lv_base a( px.back_cast() );    return ( a |= py.back_cast() );}#define DEFN_BITWISE_OR_OP_T_A(tp)                                            \template <class X>                                                            \inline                                                                        \const sc_lv_base                                                              \sc_proxy<X>::operator | ( tp b ) const                                        \{                                                                             \    sc_lv_base a( back_cast() );                                              \    return ( a |= b );                                                        \}DEFN_BITWISE_OR_OP_T_A(const char*)DEFN_BITWISE_OR_OP_T_A(const bool*)DEFN_BITWISE_OR_OP_T_A(const sc_logic*)DEFN_BITWISE_OR_OP_T_A(const sc_unsigned&)DEFN_BITWISE_OR_OP_T_A(const sc_signed&)DEFN_BITWISE_OR_OP_T_A(const sc_uint_base&)DEFN_BITWISE_OR_OP_T_A(const sc_int_base&)DEFN_BITWISE_OR_OP_T_A(unsigned long)DEFN_BITWISE_OR_OP_T_A(long)DEFN_BITWISE_OR_OP_T_A(unsigned int)DEFN_BITWISE_OR_OP_T_A(int)DEFN_BITWISE_OR_OP_T_A(uint64)DEFN_BITWISE_OR_OP_T_A(int64)#undef DEFN_BITWISE_OR_OP_T_A#define DEFN_BITWISE_OR_OP_T_B(tp)                                           \template <class X>                                                            \inline                                                                        \const sc_lv_base                                                              \operator | ( tp b, const sc_proxy<X>& px )                                    \{                                                                             \    return ( px | b );                                                        \}DEFN_BITWISE_OR_OP_T_B(const char*)DEFN_BITWISE_OR_OP_T_B(const bool*)DEFN_BITWISE_OR_OP_T_B(const sc_logic*)DEFN_BITWISE_OR_OP_T_B(const sc_unsigned&)DEFN_BITWISE_OR_OP_T_B(const sc_signed&)DEFN_BITWISE_OR_OP_T_B(const sc_uint_base&)DEFN_BITWISE_OR_OP_T_B(const sc_int_base&)DEFN_BITWISE_OR_OP_T_B(unsigned long)DEFN_BITWISE_OR_OP_T_B(long)DEFN_BITWISE_OR_OP_T_B(unsigned int)DEFN_BITWISE_OR_OP_T_B(int)DEFN_BITWISE_OR_OP_T_B(uint64)DEFN_BITWISE_OR_OP_T_B(int64)#undef DEFN_BITWISE_OR_OP_T_B// bitwise xortemplate <class X, class Y>inlineX&operator ^= ( sc_proxy<X>& px, const sc_proxy<Y>& py ){    X& x = px.back_cast();    sc_lv_base a( x.length() );    a = py.back_cast();    return b_xor_assign_( x, a );}#define DEFN_BITWISE_XOR_ASN_OP_T(tp)                                         \template <class X>                                                            \inline                                                                        \X&                                                                            \sc_proxy<X>::operator ^= ( tp b )                                             \{                                                                             \    X& x = back_cast();                                                       \    sc_lv_base a( x.length() );                                               \    a = b;                                                                    \    return b_xor_assign_( x, a );                                             \}DEFN_BITWISE_XOR_ASN_OP_T(const char*)DEFN_BITWISE_XOR_ASN_OP_T(const bool*)DEFN_BITWISE_XOR_ASN_OP_T(const sc_logic*)DEFN_BITWISE_XOR_ASN_OP_T(const sc_unsigned&)DEFN_BITWISE_XOR_ASN_OP_T(const sc_signed&)DEFN_BITWISE_XOR_ASN_OP_T(unsigned long)DEFN_BITWISE_XOR_ASN_OP_T(long)DEFN_BITWISE_XOR_ASN_OP_T(uint64)DEFN_BITWISE_XOR_ASN_OP_T(int64)#undef DEFN_BITWISE_XOR_ASN_OP_Ttemplate <class X, class Y>inlineconst sc_lv_baseoperator ^ ( const sc_proxy<X>& px, const sc_proxy<Y>& py ){    sc_lv_base a( px.back_cast() );    return ( a ^= py.back_cast() );}#define DEFN_BITWISE_XOR_OP_T_A(tp)                                           \template <class X>                                                            \inline                                                                        \const sc_lv_base                                                              \sc_proxy<X>::operator ^ ( tp b ) const                                        \{                                                                             \    sc_lv_base a( back_cast() );                                              \    return ( a ^= b );                                                        \}DEFN_BITWISE_XOR_OP_T_A(const char*)DEFN_BITWISE_XOR_OP_T_A(const bool*)DEFN_BITWISE_XOR_OP_T_A(const sc_logic*)DEFN_BITWISE_XOR_OP_T_A(const sc_unsigned&)DEFN_BITWISE_XOR_OP_T_A(const sc_signed&)DEFN_BITWISE_XOR_OP_T_A(const sc_uint_base&)DEFN_BITWISE_XOR_OP_T_A(const sc_int_base&)DEFN_BITWISE_XOR_OP_T_A(unsigned long)DEFN_BITWISE_XOR_OP_T_A(long)DEFN_BITWISE_XOR_OP_T_A(unsigned int)DEFN_BITWISE_XOR_OP_T_A(int)DEFN_BITWISE_XOR_OP_T_A(uint64)DEFN_BITWISE_XOR_OP_T_A(int64)#undef DEFN_BITWISE_XOR_OP_T_A#define DEFN_BITWISE_XOR_OP_T_B(tp)                                           \template <class X>                                                            \inline                                                                        \const sc_lv_base                                                              \operator ^ ( tp b, const sc_proxy<X>& px )                                    \{                                                                             \    return ( px ^ b );                                                        \}DEFN_BITWISE_XOR_OP_T_B(const char*)DEFN_BITWISE_XOR_OP_T_B(const bool*)DEFN_BITWISE_XOR_OP_T_B(const sc_logic*)DEFN_BITWISE_XOR_OP_T_B(const sc_unsigned&)DEFN_BITWISE_XOR_OP_T_B(const sc_signed&)DEFN_BITWISE_XOR_OP_T_B(const sc_uint_base&)DEFN_BITWISE_XOR_OP_T_B(const sc_int_base&)DEFN_BITWISE_XOR_OP_T_B(unsigned long)DEFN_BITWISE_XOR_OP_T_B(long)DEFN_BITWISE_XOR_OP_T_B(unsigned int)DEFN_BITWISE_XOR_OP_T_B(int)DEFN_BITWISE_XOR_OP_T_B(uint64)DEFN_BITWISE_XOR_OP_T_B(int64)#undef DEFN_BITWISE_XOR_OP_T_B// bitwise left shifttemplate <class X>inlineconst sc_lv_basesc_proxy<X>::operator << ( int n ) const{    sc_lv_base a( back_cast().length()+n );	a = back_cast();    return ( a <<= n );}// bitwise right shifttemplate <class X>inlineconst sc_lv_basesc_proxy<X>::operator >> ( int n ) const{    sc_lv_base a( back_cast() );    return ( a >>= n );}// bitwise left rotatetemplate <class X>inlineX&sc_proxy<X>::lrotate( int n ){    X& x = back_cast();    if( n < 0 ) {	char msg[BUFSIZ];	std::sprintf( msg,		 "left rotate operation is only allowed with positive "		 "rotate values, rotate value = %d", n );	SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );    }    int len = x.length();    n %= len;    // x = (x << n) | (x >> (len - n));    sc_lv_base a( x << n );    sc_lv_base b( x >> (len - n) );    int sz = x.size();    for( int i = 0; i < sz; ++ i ) {	x.set_word( i, a.get_word( i ) | b.get_word( i ) );	x.set_cword( i, a.get_cword( i ) | b.get_cword( i ) );    }    x.clean_tail();    return x;}template <class X>inlineconst sc_lv_baselrotate( const sc_proxy<X>& x, int n ){    sc_lv_base a( x.back_cast() );    return a.lrotate( n );}// bitwise right rotatetemplate <class X>inlineX&sc_proxy<X>::rrotate( int n ){    X& x = back_cast();    if( n < 0 ) {	char msg[BUFSIZ];	std::sprintf( msg,		 "right rotate operation is only allowed with positive "		 "rotate values, rotate value = %d", n );	SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );    }    int len = x.length();    n %= len;    // x = (x >> n) | (x << (len - n));    sc_lv_base a( x >> n );    sc_lv_base b( x << (len - n) );    int sz = x.size();    for( int i = 0; i < sz; ++ i ) {	x.set_word( i, a.get_word( i ) | b.get_word( i ) );	x.set_cword( i, a.get_cword( i ) | b.get_cword( i ) );    }    x.clean_tail();    return x;}template <class X>inlineconst sc_lv_baserrotate( const sc_proxy<X>& x, int n ){    sc_lv_base a( x.back_cast() );    return a.rrotate( n );}// bitwise reversetemplate <class X>inlineconst sc_lv_basereverse( const sc_proxy<X>& x ){    sc_lv_base a( x.back_cast() );    return a.reverse();}// relational operatorstemplate <class X, class Y>inlinebooloperator == ( const sc_proxy<X>& px, const sc_proxy<Y>& py ){    const X& x = px.back_cast();    const Y& y = py.back_cast();    int x_len = x.length();    int y_len = y.length();    if( x_len != y_len ) {	return false;    }    int sz = x.size();    for( int i = 0; i < sz; ++ i ) {	if( x.get_word( i ) != y.get_word( i ) ||	    x.get_cword( i ) != y.get_cword( i ) ) {	    return false;	}    }    return true;}#define DEFN_REL_OP_T(tp)                                                     \template <class X>                                                            \inline                                                                        \bool                                                                          \sc_proxy<X>::operator == ( tp b ) const                                       \{                                                                             \    const X& x = back_cast();                                                 \    sc_lv_base y( x.length() );                                               \    y = b;                                                                    \    return ( x == y );                                                        \}DEFN_REL_OP_T(const char*)DEFN_REL_OP_T(const bool*)DEFN_REL_OP_T(const sc_logic*)DEFN_REL_OP_T(const sc_unsigned&)DEFN_REL_OP_T(const sc_signed&)DEFN_REL_OP_T(const sc_uint_base&)DEFN_REL_OP_T(const sc_int_base&)DEFN_REL_OP_T(unsigned long)DEFN_REL_OP_T(long)DEFN_REL_OP_T(unsigned int)DEFN_REL_OP_T(int)DEFN_REL_OP_T(uint64)DEFN_REL_OP_T(int64)#undef DEFN_REL_OP_T// ----------------------------------------------------------------------------//  CLASS TEMPLATE : sc_bitref_r<X>////  Proxy class for sc_proxy bit selection (r-value only).// ----------------------------------------------------------------------------// r-value concatenation operators and functionstemplate <class T>inlinesc_concref_r<sc_bitref_r<T>,sc_lv_base>operator , ( sc_bitref_r<T> a, const char* b ){    return sc_concref_r<sc_bitref_r<T>,sc_lv_base>(	*a.clone(), *new sc_lv_base( b ), 3 );}template <class T>inlinesc_concref_r<sc_lv_base,sc_bitref_r<T> >operator , ( const char* a, sc_bitref_r<T> b ){    return sc_concref_r<sc_lv_base,sc_bitref_r<T> >(	*new sc_lv_base( a ), *b.clone(), 3 );}template <class T>inlinesc_concref_r<sc_bitref_r<T>,sc_lv_base>operator , ( sc_bitref_r<T> a, const sc_logic& b ){    return sc_concref_r<sc_bitref_r<T>,sc_lv_base>(	*a.clone(), *new sc_lv_base( b, 1 ) );}template <class T>inlinesc_concref_r<sc_lv_base,sc_bitref_r<T> >operator , ( const sc_logic& a, sc_bitref_r<T> b ){    return sc_concref_r<sc_lv_base,sc_bitref_r<T> >(	*new sc_lv_base( a, 1 ), *b.clone(), 3 );}template <class T>inlinesc_concref_r<sc_bitref_r<T>,sc_lv_base>operator , ( sc_bitref_r<T> a, bool b ){    return sc_concref_r<sc_bitref_r<T>,sc_lv_base>(	*a.clone(), *new sc_lv_base( sc_logic( b ), 1 ) );}template <class T>inlinesc_concref_r<sc_lv_base,sc_bitref_r<T> >operator , ( bool a, sc_bitref_r<T> b ){    return sc_concref_r<sc_lv_base,sc_bitref_r<T> >(	*new sc_lv_base( sc_logic( a ), 1 ), *b.clone(), 3 );}template <class T>inlinesc_concref_r<sc_bitref_r<T>,sc_lv_base>concat( sc_bitref_r<T> a, const char* b ){    return sc_concref_r<sc_bitref_r<T>,sc_lv_base>(	*a.clone(), *new sc_lv_base( b ), 3 );}

⌨️ 快捷键说明

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