📄 sc_concatref.h
字号:
{ std::string s; is >> s; *this = s.c_str(); } public: static sc_core::sc_vpool<sc_concatref> m_pool; // Pool of temporary objects.public: enum concat_flags { cf_none = 0, // Normal value. cf_xz_present = 1 // X and/or Z values present. };protected: sc_value_base* m_left_p; // Left hand operand of concatenation. sc_value_base* m_right_p; // Right hand operand of concatenation. int m_len; // Length of concatenation. int m_len_r; // Length of m_rightt_p. concat_flags m_flags; // Value is read only.private: sc_concatref(const sc_concatref&); sc_concatref() { }};// functional notation for the reduce methodsinlinebooland_reduce( const sc_concatref& a ){ return a.and_reduce();}inlineboolnand_reduce( const sc_concatref& a ){ return a.nand_reduce();}inlineboolor_reduce( const sc_concatref& a ){ return a.or_reduce();}inlineboolnor_reduce( const sc_concatref& a ){ return a.nor_reduce();}inlineboolxor_reduce( const sc_concatref& a ){ return a.xor_reduce();}inlineboolxnor_reduce( const sc_concatref& a ){ return a.xnor_reduce();}// SHIFT OPERATORS FOR sc_concatref OBJECT INSTANCES://// Because sc_concatref has implicit casts to both uint64 and sc_unsigned// it is necessary to disambiguate the use of the shift operators. We do// this in favor of sc_unsigned so that precision is not lost. To get an// integer-based result use a cast to uint64 before performing the shift.inline const sc_unsigned operator << (const sc_concatref& target, uint64 shift){ return target.value() << (int)shift;}inline const sc_unsigned operator << (const sc_concatref& target, int64 shift){ return target.value() << (int)shift;}inline const sc_unsigned operator << ( const sc_concatref& target, unsigned long shift ){ return target.value() << (int)shift;}inline const sc_unsigned operator << ( const sc_concatref& target, unsigned int shift ){ return target.value() << (int)shift;}inline const sc_unsigned operator << ( const sc_concatref& target, long shift ){ return target.value() << (int)shift;}inline const sc_unsigned operator >> (const sc_concatref& target, uint64 shift){ return target.value() >> (int)shift;}inline const sc_unsigned operator >> (const sc_concatref& target, int64 shift){ return target.value() >> (int)shift;}inline const sc_unsigned operator >> ( const sc_concatref& target, unsigned long shift ){ return target.value() >> (int)shift;}inline const sc_unsigned operator >> ( const sc_concatref& target, unsigned int shift ){ return target.value() >> (int)shift;}inline const sc_unsigned operator >> ( const sc_concatref& target, long shift ){ return target.value() >> (int)shift;}// STREAM OPERATORS FOR sc_concatref OBJECT INSTANCES:inline::std::ostream&operator << ( ::std::ostream& os, const sc_concatref& v ){ return os << v.value();}inline::std::istream&operator >> ( ::std::istream& is, sc_concatref& a ){ sc_unsigned temp(a.concat_length(0)); temp.scan( is ); a = temp; return is;}// ----------------------------------------------------------------------------// CLASS TEMPLATE : sc_concat_bool//// Proxy class for read-only boolean values in concatenations.// ----------------------------------------------------------------------------class sc_concat_bool : public sc_value_base{ protected: static sc_core::sc_vpool<sc_concat_bool> m_pool; // Temporaries pool. bool m_value; // Value for this obj. public: // destructor: virtual ~sc_concat_bool() { } // allocation of temporary object: static inline sc_concat_bool* allocate( bool v ) { sc_concat_bool* result_p = m_pool.allocate(); result_p->m_value = v; return result_p; } // concatenation: virtual int concat_length( bool* xz_present_p ) const { if ( xz_present_p ) *xz_present_p = false; return 1; } virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const { int bit = 1 << (low_i % BITS_PER_DIGIT); int word_i = low_i / BITS_PER_DIGIT; dst_p[word_i] &= ~bit; return false; } virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const { int bit = 1 << (low_i % BITS_PER_DIGIT); int word_i = low_i / BITS_PER_DIGIT; if ( m_value ) dst_p[word_i] |= bit; else dst_p[word_i] &= ~bit; return m_value; } virtual uint64 concat_get_uint64() const { return m_value ? 1 : 0; }};// ----------------------------------------------------------------------------// ARITHMETIC AND LOGIC OPERATORS FOR sc_concatref// ----------------------------------------------------------------------------#define SC_CONCAT_OP_TYPE(RESULT,OP,OTHER_TYPE) \ inline RESULT operator OP ( const sc_concatref& a, OTHER_TYPE b ) \ { \ return a.value() OP b; \ } \ inline RESULT operator OP ( OTHER_TYPE a, const sc_concatref& b ) \ { \ return a OP b.value(); \ } #define SC_CONCAT_OP(RESULT,OP) \ inline RESULT operator OP ( const sc_concatref& a, const sc_concatref& b ) \ { \ return a.value() OP b.value(); \ } \ SC_CONCAT_OP_TYPE(const sc_signed,OP,int) \ SC_CONCAT_OP_TYPE(const sc_signed,OP,long) \ SC_CONCAT_OP_TYPE(const sc_signed,OP,int64) \ SC_CONCAT_OP_TYPE(RESULT,OP,unsigned int) \ SC_CONCAT_OP_TYPE(RESULT,OP,unsigned long) \ SC_CONCAT_OP_TYPE(RESULT,OP,uint64) \ SC_CONCAT_OP_TYPE(const sc_signed,OP,const sc_int_base&) \ SC_CONCAT_OP_TYPE(RESULT,OP,const sc_uint_base&) \ SC_CONCAT_OP_TYPE(const sc_signed,OP,const sc_signed&) \ SC_CONCAT_OP_TYPE(RESULT,OP,const sc_unsigned&) \ inline RESULT operator OP ( const sc_concatref& a, bool b ) \ { \ return a.value() OP (int)b; \ } \ inline RESULT operator OP ( bool a, const sc_concatref& b ) \ { \ return (int)a OP b.value(); \ } #define SC_CONCAT_BOOL_OP(OP) \ inline bool operator OP ( const sc_concatref& a, const sc_concatref& b ) \ { \ return a.value() OP b.value(); \ } \ SC_CONCAT_OP_TYPE(bool,OP,int) \ SC_CONCAT_OP_TYPE(bool,OP,long) \ SC_CONCAT_OP_TYPE(bool,OP,int64) \ SC_CONCAT_OP_TYPE(bool,OP,unsigned int) \ SC_CONCAT_OP_TYPE(bool,OP,unsigned long) \ SC_CONCAT_OP_TYPE(bool,OP,uint64) \ SC_CONCAT_OP_TYPE(bool,OP,const sc_int_base&) \ SC_CONCAT_OP_TYPE(bool,OP,const sc_uint_base&) \ SC_CONCAT_OP_TYPE(bool,OP,const sc_signed&) \ SC_CONCAT_OP_TYPE(bool,OP,const sc_unsigned&) \ inline bool operator OP ( const sc_concatref& a, bool b ) \ { \ return a.value() OP (int)b; \ } \ inline bool operator OP ( bool a, const sc_concatref& b ) \ { \ return (int)a OP b.value(); \ } SC_CONCAT_OP(const sc_unsigned,+)SC_CONCAT_OP(const sc_signed,-)SC_CONCAT_OP(const sc_unsigned,*)SC_CONCAT_OP(const sc_unsigned,/)SC_CONCAT_OP(const sc_unsigned,%)SC_CONCAT_OP(const sc_unsigned,&)SC_CONCAT_OP(const sc_unsigned,|)SC_CONCAT_OP(const sc_unsigned,^)SC_CONCAT_BOOL_OP(==)SC_CONCAT_BOOL_OP(<=)SC_CONCAT_BOOL_OP(>=)SC_CONCAT_BOOL_OP(!=)SC_CONCAT_BOOL_OP(>)SC_CONCAT_BOOL_OP(<)#undef SC_CONCAT_OP#undef SC_CONCAT_OP_TYPE// ----------------------------------------------------------------------------// CONCATENATION FUNCTION AND OPERATOR FOR STANDARD SYSTEM C DATA TYPES:// ----------------------------------------------------------------------------inline sc_dt::sc_concatref& concat( sc_dt::sc_value_base& a, sc_dt::sc_value_base& b){ sc_dt::sc_concatref* result_p; // Proxy for the concatenation. result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( a, b ); return *result_p;}inline constsc_dt::sc_concatref& concat( const sc_dt::sc_value_base& a, const sc_dt::sc_value_base& b){ sc_dt::sc_concatref* result_p; // Proxy for the concatenation. result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( a, b ); return *result_p;}inline constsc_dt::sc_concatref& concat(const sc_dt::sc_value_base& a, bool b){ const sc_dt::sc_concat_bool* b_p; // Proxy for boolean value. sc_dt::sc_concatref* result_p; // Proxy for the concatenation. b_p = sc_dt::sc_concat_bool::allocate(b); result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( a, *b_p ); return *result_p;}inline constsc_dt::sc_concatref& concat(bool a, const sc_dt::sc_value_base& b){ const sc_dt::sc_concat_bool* a_p; // Proxy for boolean value. sc_dt::sc_concatref* result_p; // Proxy for the concatenation. a_p = sc_dt::sc_concat_bool::allocate(a); result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( *a_p, b ); return *result_p;}inline sc_dt::sc_concatref& operator , ( sc_dt::sc_value_base& a, sc_dt::sc_value_base& b){ sc_dt::sc_concatref* result_p; // Proxy for the concatenation. result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( a, b ); return *result_p;}inline constsc_dt::sc_concatref& operator , ( const sc_dt::sc_value_base& a, const sc_dt::sc_value_base& b){ sc_dt::sc_concatref* result_p; // Proxy for the concatenation. result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( a, b ); return *result_p;}inline constsc_dt::sc_concatref& operator , (const sc_dt::sc_value_base& a, bool b){ const sc_dt::sc_concat_bool* b_p; // Proxy for boolean value. sc_dt::sc_concatref* result_p; // Proxy for the concatenation. b_p = sc_dt::sc_concat_bool::allocate(b); result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( a, *b_p ); return *result_p;}inline constsc_dt::sc_concatref& operator , (bool a, const sc_dt::sc_value_base& b){ const sc_dt::sc_concat_bool* a_p; // Proxy for boolean value. sc_dt::sc_concatref* result_p; // Proxy for the concatenation. a_p = sc_dt::sc_concat_bool::allocate(a); result_p = sc_dt::sc_concatref::m_pool.allocate(); result_p->initialize( *a_p, b ); return *result_p;}} // namespace sc_dt#endif // SC_CONCATREF_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -