sc_proxy.h
来自「基于4个mips核的noc设计」· C头文件 代码 · 共 1,337 行 · 第 1/3 页
H
1,337 行
} // 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]; sprintf( msg, "left shift operation is only allowed with positive " "shift values, shift value = %d", n ); SC_REPORT_ERROR( 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 / UL_SIZE; int bn = n % UL_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, UL_ZERO, UL_ZERO ); } } if( bn != 0 ) { // shift bits for( int i = sz - 1; i >= 1; -- i ) { unsigned long x_dw, x_cw; get_words_( x, i, x_dw, x_cw ); x_dw <<= bn; x_dw |= x.get_word( i - 1 ) >> (UL_SIZE - bn); x_cw <<= bn; x_cw |= x.get_cword( i - 1 ) >> (UL_SIZE - bn); set_words_( x, i, x_dw, x_cw ); } unsigned long 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]; sprintf( msg, "right shift operation is only allowed with positive " "shift values, shift value = %d", n ); SC_REPORT_ERROR( 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 / UL_SIZE; int bn = n % UL_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, UL_ZERO, UL_ZERO ); } } if( bn != 0 ) { // shift bits for( int i = 0; i < (sz - 1); ++ i ) { unsigned long x_dw, x_cw; get_words_( x, i, x_dw, x_cw ); x_dw >>= bn; x_dw |= x.get_word( i + 1 ) << (UL_SIZE - bn); x_cw >>= bn; x_cw |= x.get_cword( i + 1 ) << (UL_SIZE - bn); set_words_( x, i, x_dw, x_cw ); } unsigned long 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 sc_stringsc_proxy<X>::to_string() const{ const X& x = back_cast(); int len = x.length(); sc_string s( len + 1 ); for( int i = 0; i < len; ++ i ) { s[i] = sc_logic::logic_to_char[x.get_bit( len - i - 1 )]; } s[len] = 0; return s;}template <class X>inlineconst sc_stringsc_proxy<X>::to_string( sc_numrep numrep ) const{ return convert_to_fmt( to_string(), numrep, true );}template <class X>inlineconst sc_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( istream& is ){ sc_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_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_ID_OUT_OF_BOUNDS_, 0 ); }}template <class X>inlineunsigned longsc_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 ) != UL_ZERO ) { SC_REPORT_WARNING( SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, 0 ); } unsigned long w = x.get_word( 0 ); if( len >= UL_SIZE ) { return w; } return ( w & (~UL_ZERO >> (UL_SIZE - len)) );}template <class X>inlinelongsc_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 ) != UL_ZERO ) { SC_REPORT_WARNING( SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, 0 ); } unsigned long w = x.get_word( 0 ); if( len >= UL_SIZE ) { return (long) w; } sc_logic_value_t sgn = x.get_bit( len - 1 ); if( sgn == 0 ) { return ( w & (~UL_ZERO >> (UL_SIZE - len)) ); } else { return ( w | (~UL_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>inlineostream&operator << ( ostream& os, const sc_proxy<X>& a ){ a.print( os ); return os;}template <class X>inlineistream&operator >> ( istream& is, sc_proxy<X>& a ){ a.scan( is ); return is;}} // namespace sc_dt#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?