📄 sc_concatref.h
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.4 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** sc_concatref.h -- Concatenation support. Original Author: Andy Goodrich, Forte Design, Inc. *****************************************************************************//***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affiliation, date and changes you are making here. Name, Affiliation, Date: Description of Modification: Andy Goodrich, Forte Design Systems, 17 Nov 2002 Creation of sc_concatref class by merging the capabilities of sc_int_concref, sc_int_concref, sc_uint_concref, sc_uint_concref, and implementing the capabilities of sc_signed_concref, sc_signed_concref, sc_unsigned_concref, and sc_unsigned_concref. The resultant class allows mixed mode concatenations on the left and right sides of an assignment. *****************************************************************************/// $Log: sc_concatref.h,v $// Revision 1.1.1.1 2006/12/15 20:31:36 acg// SystemC 2.2//// Revision 1.3 2006/01/13 18:54:01 acg// Andy Goodrich: added $Log command so that CVS comments are reproduced in// the source.//#ifndef SC_CONCATREF_H#define SC_CONCATREF_H#include "sysc/kernel/sc_object.h"#include "sysc/datatypes/misc/sc_value_base.h"#include "sysc/utils/sc_temporary.h"#include "sysc/utils/sc_string.h"#include "sysc/datatypes/bit/sc_bv.h"#include "sysc/datatypes/bit/sc_lv.h"#include "sysc/datatypes/int/sc_int_base.h"#include "sysc/datatypes/int/sc_uint_base.h"#include "sysc/datatypes/int/sc_signed.h"#include "sysc/datatypes/int/sc_unsigned.h"namespace sc_core { extern sc_byte_heap sc_temp_heap; // Temporary storage.} // namespace sc_corenamespace sc_dt{// ----------------------------------------------------------------------------// CLASS TEMPLATE : sc_concatref//// Proxy class for sized bit concatenation.// ----------------------------------------------------------------------------class sc_concatref : public sc_generic_base<sc_concatref>, public sc_value_base{public: friend class sc_core::sc_vpool<sc_concatref>; inline void initialize( sc_value_base& left, sc_value_base& right ) { bool left_xz; // True if x's and/or z's found in left. bool right_xz; // True if x's and/or z's found in right. m_left_p = (sc_value_base*)&left; m_right_p = (sc_value_base*)&right; m_len_r = right.concat_length(&right_xz); m_len = left.concat_length(&left_xz) + m_len_r; m_flags = ( left_xz || right_xz ) ? cf_xz_present : cf_none; } inline void initialize( const sc_value_base& left, const sc_value_base& right ) { bool left_xz; // True if x's and/or z's found in left. bool right_xz; // True if x's and/or z's found in right. m_left_p = (sc_value_base*)&left; m_right_p = (sc_value_base*)&right; m_len_r = right.concat_length(&right_xz); m_len = left.concat_length(&left_xz) + m_len_r; m_flags = ( left_xz || right_xz ) ? cf_xz_present : cf_none; } // destructor virtual ~sc_concatref() {} // capacity unsigned int length() const { return m_len; }#ifdef SC_DT_DEPRECATED int bitwidth() const { return length(); }#endif // concatenation virtual int concat_length( bool* xz_present_p ) const { if ( xz_present_p ) *xz_present_p = m_flags & cf_xz_present ? true : false; return m_len; } virtual void concat_clear_data( bool to_ones ) { m_left_p->concat_clear_data(to_ones); m_right_p->concat_clear_data(to_ones); } virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const { bool rnz = m_right_p->concat_get_ctrl( dst_p, low_i ); bool lnz = m_left_p->concat_get_ctrl( dst_p, low_i+m_len_r ); return rnz || lnz; } virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const { bool rnz = m_right_p->concat_get_data( dst_p, low_i ); bool lnz = m_left_p->concat_get_data( dst_p, low_i+m_len_r ); return rnz || lnz; } virtual uint64 concat_get_uint64() const { if ( m_len_r >= 64 ) return m_right_p->concat_get_uint64(); else { return (m_left_p->concat_get_uint64() << m_len_r) | m_right_p->concat_get_uint64(); } } virtual void concat_set( int64 src, int low_i ) { m_right_p->concat_set( src, low_i ); m_left_p->concat_set( src, low_i+m_len_r); } virtual void concat_set( const sc_signed& src, int low_i ) { m_right_p->concat_set( src, low_i ); m_left_p->concat_set( src, low_i+m_len_r); } virtual void concat_set( const sc_unsigned& src, int low_i ) { m_right_p->concat_set( src, low_i ); m_left_p->concat_set( src, low_i+m_len_r); } virtual void concat_set( uint64 src, int low_i ) { m_right_p->concat_set( src, low_i ); m_left_p->concat_set( src, low_i+m_len_r); } // explicit conversions uint64 to_uint64() const { uint64 mask; uint64 result; result = m_right_p->concat_get_uint64(); if ( m_len_r < 64 ) { mask = ~0; result = (m_left_p->concat_get_uint64() << m_len_r) | (result & ~(mask << m_len_r)); } if ( m_len < 64 ) { mask = ~0; result = result & ~(mask << m_len); } return result; } const sc_unsigned& value() const { bool left_non_zero; sc_unsigned* result_p = sc_unsigned::m_pool.allocate(); bool right_non_zero; result_p->nbits = result_p->num_bits(m_len); result_p->ndigits = (result_p->nbits+BITS_PER_DIGIT-1) / BITS_PER_DIGIT; result_p->digit = (sc_digit*)sc_core::sc_temp_heap.allocate( sizeof(sc_digit)*result_p->ndigits ); right_non_zero = m_right_p->concat_get_data( result_p->digit, 0 ); left_non_zero = m_left_p->concat_get_data(result_p->digit, m_len_r); if ( left_non_zero || right_non_zero ) result_p->sgn = SC_POS; else result_p->sgn = SC_ZERO; return *result_p; } int64 to_int64() const { return (int64)to_uint64(); } int to_int() const { return (int)to_int64(); } unsigned int to_uint() const { return (unsigned int)to_uint64(); } long to_long() const { return (long)to_int64(); } unsigned long to_ulong() const { return (unsigned long)to_uint64(); } double to_double() const { return value().to_double(); } void to_sc_signed( sc_signed& target ) const { target = value(); } void to_sc_unsigned( sc_unsigned& target ) const { target = value(); } // implicit conversions: operator uint64 () const { return to_uint64(); } operator const sc_unsigned& () const { return value(); } // unary operators: sc_unsigned operator + () const { return value(); } sc_signed operator - () const { return -value(); } sc_unsigned operator ~ () const { return ~value(); } // explicit conversion to character string const std::string to_string( sc_numrep numrep = SC_DEC ) const { return value().to_string(numrep); } const std::string to_string( sc_numrep numrep, bool w_prefix ) const { return value().to_string(numrep,w_prefix); } // assignments inline const sc_concatref& operator = ( int v ) { m_right_p->concat_set((int64)v, 0); m_left_p->concat_set((int64)v, m_len_r); return *this; } inline const sc_concatref& operator = ( long v ) { m_right_p->concat_set((int64)v, 0); m_left_p->concat_set((int64)v, m_len_r); return *this; } inline const sc_concatref& operator = ( int64 v ) { m_right_p->concat_set(v, 0); m_left_p->concat_set(v, m_len_r); return *this; } inline const sc_concatref& operator = ( unsigned int v ) { m_right_p->concat_set((uint64)v, 0); m_left_p->concat_set((uint64)v, m_len_r); return *this; } inline const sc_concatref& operator = ( unsigned long v ) { m_right_p->concat_set((uint64)v, 0); m_left_p->concat_set((uint64)v, m_len_r); return *this; } inline const sc_concatref& operator = ( uint64 v ) { m_right_p->concat_set(v, 0); m_left_p->concat_set(v, m_len_r); return *this; } const sc_concatref& operator = ( const sc_concatref& v ) { sc_unsigned temp(v.length()); temp = v.value(); m_right_p->concat_set(temp, 0); m_left_p->concat_set(temp, m_len_r); return *this; } const sc_concatref& operator = ( const sc_signed& v ) { m_right_p->concat_set(v, 0); m_left_p->concat_set(v, m_len_r); return *this; } const sc_concatref& operator = ( const sc_unsigned& v ) { m_right_p->concat_set(v, 0); m_left_p->concat_set(v, m_len_r); return *this; } const sc_concatref& operator = ( const char* v_p ) { sc_unsigned v(strlen(v_p)); v = v_p; m_right_p->concat_set(v, 0); m_left_p->concat_set(v, m_len_r); return *this; } const sc_concatref& operator = ( const sc_bv_base& v ) { sc_unsigned temp(v.length()); temp = v; m_right_p->concat_set(temp, 0); m_left_p->concat_set(temp, m_len_r); return *this; } const sc_concatref& operator = ( const sc_lv_base& v ) { sc_unsigned data(v.length()); data = v; m_right_p->concat_set(data, 0); m_left_p->concat_set(data, m_len_r); return *this; } // reduce methods bool and_reduce() const { return value().and_reduce(); } bool nand_reduce() const { return value().nand_reduce(); } bool or_reduce() const { return value().or_reduce(); } bool nor_reduce() const { return value().nor_reduce(); } bool xor_reduce() const { return value().xor_reduce(); } bool xnor_reduce() const { return value().xnor_reduce(); } // other methods void print( ::std::ostream& os = ::std::cout ) const { os << this->value(); } void scan( ::std::istream& is )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -