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

📄 sc_proxy.h

📁 system C源码 一种替代verilog的语言
💻 H
📖 第 1 页 / 共 3 页
字号:
    int sz = x.size();    for( int i = 0; i < sz; ++ i ) {	sc_digit x_dw, x_cw, y_dw, y_cw;	get_words_( x, i, x_dw, x_cw );	get_words_( y, i, y_dw, y_cw );	sc_digit cw = x_cw & y_cw | x_cw & ~y_dw | ~x_dw & y_cw;	sc_digit dw = cw | x_dw | y_dw;	set_words_( x, i, dw, cw );    }    // tail cleaning not needed    return x;}// bitwise xortemplate <class X, class Y>inlineX&b_xor_assign_( sc_proxy<X>& a, const sc_proxy<Y>& b ){    X& x = a.back_cast();    const Y& y = b.back_cast();    assert( x.length() == y.length() );    int sz = x.size();    for( int i = 0; i < sz; ++ i ) {	sc_digit x_dw, x_cw, y_dw, y_cw;	get_words_( x, i, x_dw, x_cw );	get_words_( y, i, y_dw, y_cw );	sc_digit cw = x_cw | y_cw;	sc_digit dw = cw | x_dw ^ y_dw;	set_words_( x, i, dw, cw );    }    // tail cleaning not needed    return x;}// bitwise left shifttemplate <class X>inlineX&sc_proxy<X>::operator <<= ( int n ){    X& x = back_cast();    if( n < 0 ) {	char msg[BUFSIZ];	std::sprintf( msg,		 "left shift operation is only allowed with positive "		 "shift values, shift value = %d", n );	SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );    }    if( n >= x.length() ) {	extend_sign_w_( x, 0, false );	// no tail cleaning needed	return x;    }    int sz = x.size();    int wn = n / SC_DIGIT_SIZE;    int bn = n % SC_DIGIT_SIZE;    if( wn != 0 ) {	// shift words	int i = sz - 1;	for( ; i >= wn; -- i ) {	    set_words_( x, i, x.get_word( i - wn ), x.get_cword( i - wn ) );	}	for( ; i >= 0; -- i ) {	    set_words_( x, i, SC_DIGIT_ZERO, SC_DIGIT_ZERO );	}    }    if( bn != 0 ) {	// shift bits	for( int i = sz - 1; i >= 1; -- i ) {	    sc_digit x_dw, x_cw;	    get_words_( x, i, x_dw, x_cw );	    x_dw <<= bn;	    x_dw |= x.get_word( i - 1 ) >> (SC_DIGIT_SIZE - bn);	    x_cw <<= bn;	    x_cw |= x.get_cword( i - 1 ) >> (SC_DIGIT_SIZE - bn);	    set_words_( x, i, x_dw, x_cw );	}	sc_digit x_dw, x_cw;	get_words_( x, 0, x_dw, x_cw );	x_dw <<= bn;	x_cw <<= bn;	set_words_( x, 0, x_dw, x_cw );    }    x.clean_tail();    return x;}// bitwise right shifttemplate <class X>inlineX&sc_proxy<X>::operator >>= ( int n ){    X& x = back_cast();    if( n < 0 ) {	char msg[BUFSIZ];	std::sprintf( msg,		 "right shift operation is only allowed with positive "		 "shift values, shift value = %d", n );	SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );    }    if( n >= x.length() ) {	extend_sign_w_( x, 0, false );	// no tail cleaning needed	return x;    }    int sz = x.size();    int wn = n / SC_DIGIT_SIZE;    int bn = n % SC_DIGIT_SIZE;    if( wn != 0 ) {	// shift words	int i = 0;	for( ; i < (sz - wn); ++ i ) {	    set_words_( x, i, x.get_word( i + wn ), x.get_cword( i + wn ) );	}	for( ; i < sz; ++ i ) {	    set_words_( x, i, SC_DIGIT_ZERO, SC_DIGIT_ZERO );	}    }    if( bn != 0 ) {	// shift bits	for( int i = 0; i < (sz - 1); ++ i ) {	    sc_digit x_dw, x_cw;	    get_words_( x, i, x_dw, x_cw );	    x_dw >>= bn;	    x_dw |= x.get_word( i + 1 ) << (SC_DIGIT_SIZE - bn);	    x_cw >>= bn;	    x_cw |= x.get_cword( i + 1 ) << (SC_DIGIT_SIZE - bn);	    set_words_( x, i, x_dw, x_cw );	}	sc_digit x_dw, x_cw;	get_words_( x, sz - 1, x_dw, x_cw );	x_dw >>= bn;	x_cw >>= bn;	set_words_( x, sz - 1, x_dw, x_cw );    }    x.clean_tail();    return x;}// bitwise left rotatetemplate <class X>inlineconst sc_lv_baselrotate( const sc_proxy<X>& x, int n );// bitwise right rotatetemplate <class X>inlineconst sc_lv_baserrotate( const sc_proxy<X>& x, int n );// bitwise reversetemplate <class X>inlineX&sc_proxy<X>::reverse(){    X& x = back_cast();    int len = x.length();    int half_len = len / 2;    for( int i = 0, j = len - 1; i < half_len; ++ i, --j ) {	sc_logic_value_t t = x.get_bit( i );	x.set_bit( i, x.get_bit( j ) );	x.set_bit( j, t );    }    return x;}template <class X>inlineconst sc_lv_basereverse( const sc_proxy<X>& a );// reduce functionstemplate <class X>inlinesc_logic_value_tsc_proxy<X>::and_reduce() const{    const X& x = back_cast();    sc_logic_value_t result = sc_logic_value_t( 1 );    int len = x.length();    for( int i = 0; i < len; ++ i ) {	result = sc_logic::and_table[result][x.get_bit( i )];    }    return result;}template <class X>inlinesc_logic_value_tsc_proxy<X>::or_reduce() const{    const X& x = back_cast();    sc_logic_value_t result = sc_logic_value_t( 0 );    int len = x.length();    for( int i = 0; i < len; ++ i ) {	result = sc_logic::or_table[result][x.get_bit( i )];    }    return result;}template <class X>inlinesc_logic_value_tsc_proxy<X>::xor_reduce() const{    const X& x = back_cast();    sc_logic_value_t result = sc_logic_value_t( 0 );    int len = x.length();    for( int i = 0; i < len; ++ i ) {	result = sc_logic::xor_table[result][x.get_bit( i )];    }    return result;}// relational operatorstemplate <class X, class Y>inlinebooloperator != ( const sc_proxy<X>& px, const sc_proxy<Y>& py ){    return !( px == py );}#define DEFN_REL_OP_T(tp)                                                     \template <class X>                                                            \inline                                                                        \bool                                                                          \operator == ( tp b, const sc_proxy<X>& px )                                   \{                                                                             \    return ( px == b );                                                       \}                                                                             \                                                                              \template <class X>                                                            \inline                                                                        \bool                                                                          \operator != ( const sc_proxy<X>& px, tp b )                                   \{                                                                             \    return !( px == b );                                                      \}                                                                             \                                                                              \template <class X>                                                            \inline                                                                        \bool                                                                          \operator != ( tp b, const sc_proxy<X>& px )                                   \{                                                                             \    return !( px == b );                                                      \}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// explicit conversions to character stringtemplate <class X>inlineconst std::stringsc_proxy<X>::to_string() const{    const X& x = back_cast();    int len = x.length();    std::string s; // ( len + 1 );    for( int i = 0; i < len; ++ i ) {	s += sc_logic::logic_to_char[x.get_bit( len - i - 1 )];    }    return s;}template <class X>inlineconst std::stringsc_proxy<X>::to_string( sc_numrep numrep ) const{    return convert_to_fmt( to_string(), numrep, true );}template <class X>inlineconst std::stringsc_proxy<X>::to_string( sc_numrep numrep, bool w_prefix ) const{    return convert_to_fmt( to_string(), numrep, w_prefix );}// other methodstemplate <class X>inlinevoidsc_proxy<X>::scan( ::std::istream& is ){    std::string s;    is >> s;    back_cast() = s.c_str();}template <class X>inlinevoidsc_proxy<X>::check_bounds( int n ) const  // check if bit n accessible{    if( n < 0 || n >= back_cast().length() ) {	SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, 0 );    }}template <class X>inlinevoidsc_proxy<X>::check_wbounds( int n ) const  // check if word n accessible{    if( n < 0 || n >= back_cast().size() ) {	SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, 0 );    }}template <class X>inlinesc_digitsc_proxy<X>::to_anything_unsigned() const{    // only 0 word is returned    // can't convert logic values other than 0 and 1    const X& x = back_cast();    int len = x.length();    if( x.get_cword( 0 ) != SC_DIGIT_ZERO ) {	SC_REPORT_WARNING( sc_core::SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, 0 );    }    sc_digit w = x.get_word( 0 );    if( len >= SC_DIGIT_SIZE ) {	return w;    }    return ( w & (~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - len)) );}template <class X>inlineuint64 sc_proxy<X>::to_uint64() const{    // words 1 and 0 returned.    // can't convert logic values other than 0 and 1    const X& x = back_cast();    int len = x.length();    if( x.get_cword( 0 ) != SC_DIGIT_ZERO ) {	SC_REPORT_WARNING( sc_core::SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, 0 );    }    uint64 w = x.get_word( 0 );    if( len > SC_DIGIT_SIZE )     {	if( x.get_cword( 1 ) != SC_DIGIT_ZERO ) {	    SC_REPORT_WARNING( sc_core::SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, 0 );	}	uint64 w1 = x.get_word( 1 );        w = w | (w1 << SC_DIGIT_SIZE);		return w;    }    else if( len == SC_DIGIT_SIZE )     {	return w;    }    else    {	return ( w & (~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - len)) );    }}template <class X>inlineint64sc_proxy<X>::to_anything_signed() const{    // only 0 word is returned    // can't convert logic values other than 0 and 1    const X& x = back_cast();    int len = x.length();    if( x.get_cword( 0 ) != SC_DIGIT_ZERO ) {	SC_REPORT_WARNING( sc_core::SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, 0 );    }    int64 w = x.get_word( 0 );    uint64 zero = 0;    if( len >= 64 ) {	return (uint64) w;    }    sc_logic_value_t sgn = x.get_bit( len - 1 );    if( sgn == 0 ) {	return ( w & (~zero >> (64 - len)) );    } else {	return ( w | (~zero << len) );    }}// ----------------------------------------------------------------------------// functional notation for the reduce methodstemplate <class X>inlinesc_logic_value_tand_reduce( const sc_proxy<X>& a ){    return a.and_reduce();}template <class X>inlinesc_logic_value_tnand_reduce( const sc_proxy<X>& a ){    return a.nand_reduce();}template <class X>inlinesc_logic_value_tor_reduce( const sc_proxy<X>& a ){    return a.or_reduce();}template <class X>inlinesc_logic_value_tnor_reduce( const sc_proxy<X>& a ){    return a.nor_reduce();}template <class X>inlinesc_logic_value_txor_reduce( const sc_proxy<X>& a ){    return a.xor_reduce();}template <class X>inlinesc_logic_value_txnor_reduce( const sc_proxy<X>& a ){    return a.xnor_reduce();}// ----------------------------------------------------------------------------template <class X>inline::std::ostream&operator << ( ::std::ostream& os, const sc_proxy<X>& a ){    a.print( os );    return os;}template <class X>inline::std::istream&operator >> ( ::std::istream& is, sc_proxy<X>& a ){    a.scan( is );    return is;}} // namespace sc_dt#endif

⌨️ 快捷键说明

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