📄 sc_proxy.h
字号:
template <class X, class Y>inlineconst sc_lv_baseoperator | ( const sc_proxy<X>& px, const sc_proxy<Y>& py );#define DECL_BITWISE_OR_OP_T(tp) \template <class X> \inline \const sc_lv_base \operator | ( tp a, const sc_proxy<X>& px );DECL_BITWISE_OR_OP_T(const char*)DECL_BITWISE_OR_OP_T(const bool*)DECL_BITWISE_OR_OP_T(const sc_logic*)DECL_BITWISE_OR_OP_T(const sc_unsigned&)DECL_BITWISE_OR_OP_T(const sc_signed&)DECL_BITWISE_OR_OP_T(const sc_uint_base&)DECL_BITWISE_OR_OP_T(const sc_int_base&)DECL_BITWISE_OR_OP_T(unsigned long)DECL_BITWISE_OR_OP_T(long)DECL_BITWISE_OR_OP_T(unsigned int)DECL_BITWISE_OR_OP_T(int)DECL_BITWISE_OR_OP_T(uint64)DECL_BITWISE_OR_OP_T(int64)#undef DECL_BITWISE_OR_OP_T// bitwise xortemplate <class X, class Y>inlineX&operator ^= ( sc_proxy<X>& px, const sc_proxy<Y>& py );template <class X, class Y>inlineconst sc_lv_baseoperator ^ ( const sc_proxy<X>& px, const sc_proxy<Y>& py );#define DECL_BITWISE_XOR_OP_T(tp) \template <class X> \inline \const sc_lv_base \operator ^ ( tp a, const sc_proxy<X>& px );DECL_BITWISE_XOR_OP_T(const char*)DECL_BITWISE_XOR_OP_T(const bool*)DECL_BITWISE_XOR_OP_T(const sc_logic*)DECL_BITWISE_XOR_OP_T(const sc_unsigned&)DECL_BITWISE_XOR_OP_T(const sc_signed&)DECL_BITWISE_XOR_OP_T(const sc_uint_base&)DECL_BITWISE_XOR_OP_T(const sc_int_base&)DECL_BITWISE_XOR_OP_T(unsigned long)DECL_BITWISE_XOR_OP_T(long)DECL_BITWISE_XOR_OP_T(unsigned int)DECL_BITWISE_XOR_OP_T(int)DECL_BITWISE_XOR_OP_T(uint64)DECL_BITWISE_XOR_OP_T(int64)#undef DECL_BITWISE_XOR_OP_T// relational operatorstemplate <class X, class Y>inlinebooloperator == ( const sc_proxy<X>& px, const sc_proxy<Y>& py );template <class X, class Y>inlinebooloperator != ( const sc_proxy<X>& px, const sc_proxy<Y>& py );#define DECL_REL_OP_T(tp) \template <class X> \inline \bool \operator == ( tp b, const sc_proxy<X>& px ); \ \template <class X> \inline \bool \operator != ( const sc_proxy<X>& px, tp b ); \ \template <class X> \inline \bool \operator != ( tp b, const sc_proxy<X>& px );DECL_REL_OP_T(const char*)DECL_REL_OP_T(const bool*)DECL_REL_OP_T(const sc_logic*)DECL_REL_OP_T(const sc_unsigned&)DECL_REL_OP_T(const sc_signed&)DECL_REL_OP_T(const sc_uint_base&)DECL_REL_OP_T(const sc_int_base&)DECL_REL_OP_T(unsigned long)DECL_REL_OP_T(long)DECL_REL_OP_T(unsigned int)DECL_REL_OP_T(int)DECL_REL_OP_T(uint64)DECL_REL_OP_T(int64)#undef DECL_REL_OP_T// l-value concatenation// Due to the fact that temporary objects cannot be passed to non-const// references, we have to enumerate, use call by value, and use dynamic// memory allocation (and deallocation).// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIItemplate <class X>inlinevoidget_words_( const X& x, int wi, sc_digit& x_dw, sc_digit& x_cw ){ x_dw = x.get_word( wi ); x_cw = x.get_cword( wi );}template <class X>inlinevoidset_words_( X& x, int wi, sc_digit x_dw, sc_digit x_cw ){ x.set_word( wi, x_dw ); x.set_cword( wi, x_cw );}template <class X>inlinevoidextend_sign_w_( X& x, int wi, bool sign ){ int sz = x.size(); unsigned int sgn = (sign ? ~SC_DIGIT_ZERO : SC_DIGIT_ZERO); for( int i = wi; i < sz; ++ i ) { set_words_( x, i, sgn, SC_DIGIT_ZERO ); }}// assignment functionstemplate <class X, class Y>inlinevoidassign_p_( sc_proxy<X>& px, const sc_proxy<Y>& py ){ if( (void*) &px != (void*) &py ) { X& x = px.back_cast(); const Y& y = py.back_cast(); int sz = x.size(); int min_sz = sc_min( sz, y.size() ); int i = 0; for( ; i < min_sz; ++ i ) { set_words_( x, i, y.get_word( i ), y.get_cword( i ) ); } // extend with zeros extend_sign_w_( x, i, false ); x.clean_tail(); }}// Vector types that are not derived from sc_proxy, sc_int_base,// sc_uint_base, sc_signed, or sc_unsigned, must have a length()// function and an operator []. The vector argument type must support// accessing bits that are beyond the msb. The vector argument type// decides what to do there (e.g. sign extension or zero padding).template <class X, class T>inlinevoidassign_v_( sc_proxy<X>& px, const T& a ){ X& x = px.back_cast(); int i; int len_x = x.length(); int len_a = a.length(); if ( len_a > len_x ) len_a = len_x; for( i = 0 ; i < len_a; ++ i ) { x.set_bit( i, sc_logic_value_t( (bool) a[i] ) ); } for( ; i < len_x; ++ i ) { x.set_bit( i, sc_logic_value_t( false ) ); }}template <class X>inlinevoidassign_v_( sc_proxy<X>& px, const sc_int_base& a ){ X& x = px.back_cast(); int i; bool sign = a < 0; int len_x = x.length(); int len_a = a.length(); if ( len_a > len_x ) len_a = len_x; for( i = 0 ; i < len_a; ++ i ) { x.set_bit( i, sc_logic_value_t( (bool) a[i] ) ); } for( ; i < len_x; ++ i ) { x.set_bit( i, sc_logic_value_t( sign ) ); }}template <class X>inlinevoidassign_v_( sc_proxy<X>& px, const sc_signed& a ){ X& x = px.back_cast(); int i; bool sign = a < 0; int len_x = x.length(); int len_a = a.length(); if ( len_a > len_x ) len_a = len_x; for( i = 0 ; i < len_a; ++ i ) { x.set_bit( i, sc_logic_value_t( (bool) a[i] ) ); } for( ; i < len_x; ++ i ) { x.set_bit( i, sc_logic_value_t( sign ) ); }}template <class X>inlinevoidassign_v_( sc_proxy<X>& px, const sc_uint_base& a ){ X& x = px.back_cast(); int i; int len_x = x.length(); int len_a = a.length(); if ( len_a > len_x ) len_a = len_x; for( i = 0 ; i < len_a; ++ i ) { x.set_bit( i, sc_logic_value_t( (bool) a[i] ) ); } for( ; i < len_x; ++ i ) { x.set_bit( i, sc_logic_value_t( false ) ); }}template <class X>inlinevoidassign_v_( sc_proxy<X>& px, const sc_unsigned& a ){ X& x = px.back_cast(); int i; int len_x = x.length(); int len_a = a.length(); if ( len_a > len_x ) len_a = len_x; for( i = 0 ; i < len_a; ++ i ) { x.set_bit( i, sc_logic_value_t( (bool) a[i] ) ); } for( ; i < len_x; ++ i ) { x.set_bit( i, sc_logic_value_t( false ) ); }}// assignment operatorstemplate <class X>inlineX&sc_proxy<X>::assign_( const char* a ){ X& x = back_cast(); std::string s = convert_to_bin( a ); int len = x.length(); int s_len = s.length() - 1; int min_len = sc_min( len, s_len ); int i = 0; for( ; i < min_len; ++ i ) { char c = s[s_len - i - 1]; x.set_bit( i, sc_logic::char_to_logic[(int)c] ); } // if formatted, fill the rest with sign(s), otherwise fill with zeros sc_logic_value_t fill = (s[s_len] == 'F' ? sc_logic_value_t( s[0] - '0' ) : sc_logic_value_t( 0 )); for( ; i < len; ++ i ) { x.set_bit( i, fill ); } return x;}template <class X>inlineX&sc_proxy<X>::assign_( const bool* a ){ // the length of 'a' must be larger than or equal to the length of 'this' X& x = back_cast(); int len = x.length(); for( int i = 0; i < len; ++ i ) { x.set_bit( i, sc_logic_value_t( a[i] ) ); } return x;}template <class X>inlineX&sc_proxy<X>::assign_( const sc_logic* a ){ // the length of 'a' must be larger than or equal to the length of 'this' X& x = back_cast(); int len = x.length(); for( int i = 0; i < len; ++ i ) { x.set_bit( i, a[i].value() ); } return x;}template <class X>inlineX&sc_proxy<X>::assign_( unsigned int a ){ X& x = back_cast(); set_words_( x, 0, (sc_digit)a, SC_DIGIT_ZERO ); // extend with zeros extend_sign_w_( x, 1, false ); x.clean_tail(); return x;}template <class X>inlineX&sc_proxy<X>::assign_( int a ){ X& x = back_cast(); set_words_( x, 0, (sc_digit) a, SC_DIGIT_ZERO ); // extend with sign(a) extend_sign_w_( x, 1, (a < 0) ); x.clean_tail(); return x;}#if defined(SC_LONG_64) template <class X> inline X& sc_proxy<X>::assign_( unsigned long a ) { X& x = back_cast(); set_words_( x, 0, ((sc_digit) a & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); if( x.size() > 1 ) { set_words_( x, 1, ((sc_digit) (a >> SC_DIGIT_SIZE) & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); // extend with zeros extend_sign_w_( x, 2, false ); } x.clean_tail(); return x; } template <class X> inline X& sc_proxy<X>::assign_( long a ) { X& x = back_cast(); set_words_( x, 0, ((sc_digit) a & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); if( x.size() > 1 ) { set_words_( x, 1, ((sc_digit) ((uint64) a >> SC_DIGIT_SIZE) & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); // extend with sign(a) extend_sign_w_( x, 2, (a < 0) ); } x.clean_tail(); return x; }#else template <class X> inline X& sc_proxy<X>::assign_( unsigned long a ) { X& x = back_cast(); set_words_( x, 0, (sc_digit)a, SC_DIGIT_ZERO ); // extend with zeros extend_sign_w_( x, 1, false ); x.clean_tail(); return x; } template <class X> inline X& sc_proxy<X>::assign_( long a ) { X& x = back_cast(); set_words_( x, 0, (sc_digit) a, SC_DIGIT_ZERO ); // extend with sign(a) extend_sign_w_( x, 1, (a < 0) ); x.clean_tail(); return x; }#endiftemplate <class X>inlineX&sc_proxy<X>::assign_( uint64 a ){ X& x = back_cast(); set_words_( x, 0, ((sc_digit) a & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); if( x.size() > 1 ) { set_words_( x, 1, ((sc_digit) (a >> SC_DIGIT_SIZE) & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); // extend with zeros extend_sign_w_( x, 2, false ); } x.clean_tail(); return x;}template <class X>inlineX&sc_proxy<X>::assign_( int64 a ){ X& x = back_cast(); set_words_( x, 0, ((sc_digit) a & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); if( x.size() > 1 ) { set_words_( x, 1, ((sc_digit) ((uint64) a >> SC_DIGIT_SIZE) & ~SC_DIGIT_ZERO), SC_DIGIT_ZERO ); // extend with sign(a) extend_sign_w_( x, 2, (a < 0) ); } x.clean_tail(); return x;}// bitwise operators and functions// bitwise complementtemplate <class X>inlineX&sc_proxy<X>::b_not(){ X& x = back_cast(); int sz = x.size(); for( int i = 0; i < sz; ++ i ) { sc_digit x_dw, x_cw; get_words_( x, i, x_dw, x_cw ); x.set_word( i, x_cw | ~x_dw ); } x.clean_tail(); return x;}// bitwise andtemplate <class X, class Y>inlineX&b_and_assign_( sc_proxy<X>& px, const sc_proxy<Y>& py ){ X& x = px.back_cast(); const Y& y = py.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_dw & y_cw | x_cw & y_dw | 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 ortemplate <class X, class Y>inlineX&b_or_assign_( sc_proxy<X>& px, const sc_proxy<Y>& py ){ X& x = px.back_cast(); const Y& y = py.back_cast(); assert( x.length() == y.length() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -