📄 sc_uint_base.cpp
字号:
voidsc_uint_base::invalid_range( int l, int r ) const{ char msg[BUFSIZ]; std::sprintf( msg, "sc_uint[_base] part selection: left = %d, right = %d violates " "0 <= right <= left <= %d", l, r, m_len - 1 ); SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );}voidsc_uint_base::check_value() const{ uint_type limit = (~UINT_ZERO >> m_ulen); if( m_val > limit ) { char msg[BUFSIZ]; std::sprintf( msg, "sc_uint[_base]: value does not fit into a length of %d", m_len ); SC_REPORT_WARNING( sc_core::SC_ID_OUT_OF_BOUNDS_, msg ); }}// constructorssc_uint_base::sc_uint_base( const sc_bv_base& v ) : m_val(0), m_len( v.length() ), m_ulen( SC_INTWIDTH - m_len ){ check_length(); *this = v;}sc_uint_base::sc_uint_base( const sc_lv_base& v ) : m_val(0), m_len( v.length() ), m_ulen( SC_INTWIDTH - m_len ){ check_length(); *this = v;}sc_uint_base::sc_uint_base( const sc_int_subref_r& v ) : m_val(0), m_len( v.length() ), m_ulen( SC_INTWIDTH - m_len ){ check_length(); *this = v.to_uint64();}sc_uint_base::sc_uint_base( const sc_signed_subref_r& v ) : m_val(0), m_len( v.length() ), m_ulen( SC_INTWIDTH - m_len ){ check_length(); *this = v.to_uint64();}sc_uint_base::sc_uint_base( const sc_unsigned_subref_r& v ) : m_val(0), m_len( v.length() ), m_ulen( SC_INTWIDTH - m_len ){ check_length(); *this = v.to_uint64();}sc_uint_base::sc_uint_base( const sc_signed& a ) : m_val( 0 ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len ){ check_length();#if 0 for( int i = m_len - 1; i >= 0; -- i ) { set( i, a.test( i ) ); } extend_sign();#else *this = a.to_uint64();#endif}sc_uint_base::sc_uint_base( const sc_unsigned& a ) : m_val( 0 ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len ){ check_length();#if 0 for( int i = m_len - 1; i >= 0; -- i ) { set( i, a.test( i ) ); } extend_sign();#else *this = a.to_uint64();#endif}// assignment operatorssc_uint_base&sc_uint_base::operator = ( const sc_signed& a ){ int minlen = sc_min( m_len, a.length() ); int i = 0; for( ; i < minlen; ++ i ) { set( i, a.test( i ) ); } bool sgn = a.sign(); for( ; i < m_len; ++ i ) { // sign extension set( i, sgn ); } extend_sign(); return *this;}sc_uint_base& sc_uint_base::operator = ( const sc_unsigned& a ){ int minlen = sc_min( m_len, a.length() ); int i = 0; for( ; i < minlen; ++ i ) { set( i, a.test( i ) ); } for( ; i < m_len; ++ i ) { // zero extension set( i, 0 ); } extend_sign(); return *this;}sc_uint_base&sc_uint_base::operator = ( const sc_bv_base& a ){ int minlen = sc_min( m_len, a.length() ); int i = 0; for( ; i < minlen; ++ i ) { set( i, a.get_bit( i ) ); } for( ; i < m_len; ++ i ) { // zero extension set( i, 0 ); } extend_sign(); return *this;}sc_uint_base&sc_uint_base::operator = ( const sc_lv_base& a ){ int minlen = sc_min( m_len, a.length() ); int i = 0; for( ; i < minlen; ++ i ) { set( i, sc_logic( a.get_bit( i ) ).to_bool() ); } for( ; i < m_len; ++ i ) { // zero extension set( i, 0 ); } extend_sign(); return *this;}sc_uint_base&sc_uint_base::operator = ( const char* a ){ if( a == 0 ) { SC_REPORT_ERROR( sc_core::SC_ID_CONVERSION_FAILED_, "character string is zero" ); } if( *a == 0 ) { SC_REPORT_ERROR( sc_core::SC_ID_CONVERSION_FAILED_, "character string is empty" ); } try { int len = m_len; sc_ufix aa( a, len, len, SC_TRN, SC_WRAP, 0, SC_ON ); return this->operator = ( aa ); } catch( sc_core::sc_report ) { char msg[BUFSIZ]; std::sprintf( msg, "character string '%s' is not valid", a ); SC_REPORT_ERROR( sc_core::SC_ID_CONVERSION_FAILED_, msg ); // never reached return *this; }}// explicit conversion to character stringconst std::stringsc_uint_base::to_string( sc_numrep numrep ) const{ int len = m_len; sc_ufix aa( *this, len, len, SC_TRN, SC_WRAP, 0, SC_ON ); return aa.to_string( numrep );}const std::stringsc_uint_base::to_string( sc_numrep numrep, bool w_prefix ) const{ int len = m_len; sc_ufix aa( *this, len, len, SC_TRN, SC_WRAP, 0, SC_ON ); return aa.to_string( numrep, w_prefix );}// reduce methodsboolsc_uint_base::and_reduce() const{ return ( m_val == (~UINT_ZERO >> m_ulen) );}boolsc_uint_base::or_reduce() const{ return ( m_val != uint_type( 0 ) );}boolsc_uint_base::xor_reduce() const{ uint_type mask = ~UINT_ZERO; uint_type val = m_val; int n = SC_INTWIDTH; do { n >>= 1; mask >>= n; val = ((val & (mask << n)) >> n) ^ (val & mask); } while( n != 1 ); return ( val != uint_type( 0 ) );}bool sc_uint_base::concat_get_ctrl( sc_digit* dst_p, int low_i ) const{ int dst_i; // Word in dst_p now processing. int end_i; // Highest order word in dst_p to process. int left_shift; // Left shift for val. sc_digit mask; // Mask for bits to extract or keep. dst_i = low_i / BITS_PER_DIGIT; left_shift = low_i % BITS_PER_DIGIT; end_i = (low_i + (m_len-1)) / BITS_PER_DIGIT; // PROCESS THE FIRST WORD: mask = ~((uint_type)-1 << left_shift); dst_p[dst_i] = (unsigned long)((dst_p[dst_i] & mask)); dst_i++; for ( ; dst_i <= end_i; dst_i++ ) dst_p[dst_i] = 0; return false;}bool sc_uint_base::concat_get_data( sc_digit* dst_p, int low_i ) const{ int dst_i; // Word in dst_p now processing. int end_i; // Highest order word in dst_p to process. int high_i; // Index of high order bit in dst_p to set. int left_shift; // Left shift for val. sc_digit mask; // Mask for bits to extract or keep. bool result; // True if inserting non-zero value. sc_digit val; // Value for this object. dst_i = low_i / BITS_PER_DIGIT; left_shift = low_i % BITS_PER_DIGIT; high_i = low_i + (m_len-1); end_i = high_i / BITS_PER_DIGIT; val = m_val; result = val != 0; // PROCESS THE FIRST WORD: mask = ~((uint_type)-1 << left_shift); dst_p[dst_i] = (unsigned long)(((dst_p[dst_i] & mask)) | ((val << left_shift) & DIGIT_MASK)); switch ( end_i - dst_i ) { // BITS ARE ACROSS TWO WORDS: case 1: dst_i++; val >>= (BITS_PER_DIGIT-left_shift); dst_p[dst_i] = (unsigned long)val; break; // BITS ARE ACROSS THREE WORDS: case 2: dst_i++; val >>= (BITS_PER_DIGIT-left_shift); dst_p[dst_i] = (unsigned long)(val & DIGIT_MASK); dst_i++; val >>= (BITS_PER_DIGIT-left_shift); dst_p[dst_i] = (unsigned long)val; break; } return result;}// #### OPTIMIZEvoid sc_uint_base::concat_set(int64 src, int low_i){ *this = (low_i < 64) ? src >> low_i : src >> 63;}void sc_uint_base::concat_set(const sc_signed& src, int low_i){ if ( low_i < src.length() ) *this = src >> low_i; else *this = (src < 0) ? (int_type)-1 : 0; }void sc_uint_base::concat_set(const sc_unsigned& src, int low_i){ if ( low_i < src.length() ) *this = src >> low_i; else *this = 0;}void sc_uint_base::concat_set(uint64 src, int low_i){ *this = (low_i < 64) ? src >> low_i : 0;}// other methodsvoidsc_uint_base::scan( ::std::istream& is ){ std::string s; is >> s; *this = s.c_str();}} // namespace sc_dt// Taf!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -