sc_uint_base.h

来自「基于4个mips核的noc设计」· C头文件 代码 · 共 2,628 行 · 第 1/5 页

H
2,628
字号
/*****************************************************************************  The following code is derived, directly or indirectly, from the SystemC  source code Copyright (c) 1996-2002 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.3 (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_uint_base.h -- A sc_uint is an unsigned integer whose length is less than               the machine's native integer length. We provide two               implementations (i) sc_uint with length between 1 - 64, and (ii)               sc_uint with length between 1 - 32. Implementation (i) is the               default implementation, while implementation (ii) can be used               only if compiled with -D_32BIT_. Unlike arbitrary precision,               arithmetic and bitwise operations are performed using the native               types (hence capped at 32/64 bits). The sc_uint integer is               useful when the user does not need arbitrary precision and the               performance is superior to sc_bigint/sc_biguint.  Original Author: Amit Rao, Synopsys, Inc. *****************************************************************************//*****************************************************************************  MODIFICATION LOG - modifiers, enter your name, affiliation, date and  changes you are making here.      Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.  Description of Modification: - Resolved ambiguity with sc_(un)signed.                               - Merged the code for 64- and 32-bit versions                                 via the constants in sc_nbdefs.h.                               - Eliminated redundant file inclusions.      Name, Affiliation, Date:  Description of Modification: *****************************************************************************/#ifndef SC_UINT_BASE_H#define SC_UINT_BASE_H#include "systemc/datatypes/int/sc_int_ids.h"#include "systemc/datatypes/int/sc_length_param.h"#include "systemc/datatypes/int/sc_nbdefs.h"#include "systemc/datatypes/fx/scfx_ieee.h"#include "systemc/utils/sc_iostream.h"namespace sc_dt{// classes defined in this moduletemplate <class T1, class T2> class sc_uint_concref_r;template <class T1, class T2> class sc_uint_concref;class sc_uint_bitref_r;class sc_uint_bitref;class sc_uint_subref_r;class sc_uint_subref;class sc_uint_base;// forward class declarationsclass sc_bv_base;class sc_lv_base;class sc_signed;class sc_unsigned;class sc_fxval;class sc_fxval_fast;class sc_fxnum;class sc_fxnum_fast;extern const uint_type mask_int[SC_INTWIDTH][SC_INTWIDTH];// to avoid code bloat in sc_uint_concref<T1,T2>externvoidsc_uint_concref_invalid_length( int length );// ----------------------------------------------------------------------------//  CLASS TEMPLATE : sc_uint_concref_r<T1,T2>////  Proxy class for sc_uint concatenation (r-value only).// ----------------------------------------------------------------------------template <class T1, class T2>class sc_uint_concref_r{    // support methods    void check_length() const	{ if( m_len > SC_INTWIDTH ) sc_uint_concref_invalid_length( m_len ); }public:    // constructor    sc_uint_concref_r( const T1& left_, const T2& right_, int delete_ = 0 )	: m_left( CCAST<T1&>( left_ ) ), m_right( CCAST<T2&>( right_ ) ),	  m_delete( delete_ ), m_refs( *new int( 1 ) )        { m_len = m_left.length() + m_right.length(); check_length(); }    // copy constructor    sc_uint_concref_r( const sc_uint_concref_r<T1,T2>& a )        : m_left( a.m_left ), m_right( a.m_right ), m_len( a.m_len ),          m_delete( a.m_delete ), m_refs( a.m_refs )	{ ++ m_refs; }    // destructor    ~sc_uint_concref_r();    // cloning    sc_uint_concref_r<T1,T2>* clone() const        { return new sc_uint_concref_r<T1,T2>( *this ); }    // capacity    int length() const	{ return m_len; }#ifdef SC_DT_DEPRECATED    int bitwidth() const	{ return length(); }#endif    // reduce methods    bool and_reduce() const;    bool nand_reduce() const	{ return ( ! and_reduce() ); }    bool or_reduce() const;    bool nor_reduce() const	{ return ( ! or_reduce() ); }    bool xor_reduce() const;    bool xnor_reduce() const	{ return ( ! xor_reduce() ); }    // implicit conversion to uint_type    operator uint_type() const;    // explicit conversions    uint_type value() const	{ return operator uint_type(); }    int           to_int() const;    unsigned int  to_uint() const;    long          to_long() const;    unsigned long to_ulong() const;    int64         to_int64() const;    uint64        to_uint64() const;    double        to_double() const;    // explicit conversion to character string    const sc_string to_string( sc_numrep numrep = SC_DEC ) const;    const sc_string to_string( sc_numrep numrep, bool w_prefix ) const;    // other methods    void print( ostream& os = cout ) const	{ os << to_string(); }protected:    T1&          m_left;    T2&          m_right;    int          m_len;    mutable int  m_delete;    mutable int& m_refs;private:    // disabled    sc_uint_concref_r();    sc_uint_concref_r<T1,T2>& operator = ( const sc_uint_concref_r<T1,T2>& );};// r-value concatenation operators and functionstemplate <class T1, class T2, class T3, class T4>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_concref_r<T3,T4> >operator , ( sc_uint_concref_r<T1,T2>, sc_uint_concref_r<T3,T4> );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_bitref_r>operator , ( sc_uint_concref_r<T1,T2>, sc_uint_bitref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_subref_r>operator , ( sc_uint_concref_r<T1,T2>, sc_uint_subref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>operator , ( sc_uint_concref_r<T1,T2>, const sc_uint_base& );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>operator , ( sc_uint_concref_r<T1,T2>, bool );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_base,sc_uint_concref_r<T1,T2> >operator , ( bool, sc_uint_concref_r<T1,T2> );template <class T1, class T2, class T3, class T4>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_concref_r<T3,T4> >concat( sc_uint_concref_r<T1,T2>, sc_uint_concref_r<T3,T4> );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_bitref_r>concat( sc_uint_concref_r<T1,T2>, sc_uint_bitref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_subref_r>concat( sc_uint_concref_r<T1,T2>, sc_uint_subref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>concat( sc_uint_concref_r<T1,T2>, const sc_uint_base& );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>concat( sc_uint_concref_r<T1,T2>, bool );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_base,sc_uint_concref_r<T1,T2> >concat( bool, sc_uint_concref_r<T1,T2> );#ifdef SC_DT_MIXED_COMMA_OPERATORStemplate <class T1, class T2, class T3, class T4>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_concref_r<T3,T4> >operator , ( sc_uint_concref_r<T1,T2>, sc_uint_concref<T3,T4> );template <class T1, class T2, class T3, class T4>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_concref_r<T3,T4> >operator , ( sc_uint_concref<T1,T2>, sc_uint_concref_r<T3,T4> );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_bitref_r>operator , ( sc_uint_concref_r<T1,T2>, sc_uint_bitref );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_bitref_r>operator , ( sc_uint_concref<T1,T2>, sc_uint_bitref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_subref_r>operator , ( sc_uint_concref_r<T1,T2>, sc_uint_subref );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_subref_r>operator , ( sc_uint_concref<T1,T2>, sc_uint_subref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>operator , ( sc_uint_concref_r<T1,T2>, sc_uint_base& );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>operator , ( sc_uint_concref<T1,T2>, const sc_uint_base& );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>operator , ( sc_uint_concref<T1,T2>, bool );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_base,sc_uint_concref_r<T1,T2> >operator , ( bool, sc_uint_concref<T1,T2> );template <class T1, class T2, class T3, class T4>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_concref_r<T3,T4> >concat( sc_uint_concref_r<T1,T2>, sc_uint_concref<T3,T4> );template <class T1, class T2, class T3, class T4>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_concref_r<T3,T4> >concat( sc_uint_concref<T1,T2>, sc_uint_concref_r<T3,T4> );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_bitref_r>concat( sc_uint_concref_r<T1,T2>, sc_uint_bitref );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_bitref_r>concat( sc_uint_concref<T1,T2>, sc_uint_bitref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_subref_r>concat( sc_uint_concref_r<T1,T2>, sc_uint_subref );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_subref_r>concat( sc_uint_concref<T1,T2>, sc_uint_subref_r );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>concat( sc_uint_concref_r<T1,T2>, sc_uint_base& );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>concat( sc_uint_concref<T1,T2>, const sc_uint_base& );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_concref_r<T1,T2>,sc_uint_base>concat( sc_uint_concref<T1,T2>, bool );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_base,sc_uint_concref_r<T1,T2> >concat( bool, sc_uint_concref<T1,T2> );#endiftemplate <class T1, class T2>inlineostream&operator << ( ostream&, const sc_uint_concref_r<T1,T2>& );// ----------------------------------------------------------------------------//  CLASS TEMPLATE : sc_uint_concref<T1,T2>////  Proxy class for sc_uint concatenation (r-value and l-value).// ----------------------------------------------------------------------------template <class T1, class T2>class sc_uint_concref    : public sc_uint_concref_r<T1,T2>{public:    // constructor    sc_uint_concref( T1& left_, T2& right_, int delete_ = 0 )	: sc_uint_concref_r<T1,T2>( left_, right_, delete_ )	{}    // copy constructor    sc_uint_concref( const sc_uint_concref<T1,T2>& a )	: sc_uint_concref_r<T1,T2>( a )	{}    // cloning    sc_uint_concref<T1,T2>* clone() const        { return new sc_uint_concref<T1,T2>( *this ); }    // assignment operators    sc_uint_concref<T1,T2>& operator = ( uint_type v );    template <class T3, class T4>    sc_uint_concref<T1,T2>& operator = ( const sc_uint_concref_r<T3,T4>& a )        { return operator = ( a.operator uint_type() ); }    template <class T3, class T4>    sc_uint_concref<T1,T2>& operator = ( const sc_uint_concref<T3,T4>& a )        { return operator = ( a.operator uint_type() ); }    sc_uint_concref<T1,T2>& operator = ( const sc_uint_base& a );    sc_uint_concref<T1,T2>& operator = ( const sc_uint_subref_r& a );    sc_uint_concref<T1,T2>& operator = ( const char* a );    sc_uint_concref<T1,T2>& operator = ( unsigned long a )	{ return operator = ( (uint_type) a ); }    sc_uint_concref<T1,T2>& operator = ( long a )	{ return operator = ( (uint_type) a ); }    sc_uint_concref<T1,T2>& operator = ( unsigned int a )	{ return operator = ( (uint_type) a ); }    sc_uint_concref<T1,T2>& operator = ( int a )	{ return operator = ( (uint_type) a ); }    sc_uint_concref<T1,T2>& operator = ( int64 a )	{ return operator = ( (uint_type) a ); }    sc_uint_concref<T1,T2>& operator = ( double a )	{ return operator = ( (uint_type) a ); }    sc_uint_concref<T1,T2>& operator = ( const sc_signed& );    sc_uint_concref<T1,T2>& operator = ( const sc_unsigned& );    sc_uint_concref<T1,T2>& operator = ( const sc_bv_base& );    sc_uint_concref<T1,T2>& operator = ( const sc_lv_base& );    // other methods    void scan( istream& is = cin );private:    // disabled    sc_uint_concref();};// l-value concatenation operators and functionstemplate <class T1, class T2, class T3, class T4>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_concref<T3,T4> >operator , ( sc_uint_concref<T1,T2>, sc_uint_concref<T3,T4> );template <class T1, class T2>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_bitref>operator , ( sc_uint_concref<T1,T2>, sc_uint_bitref );template <class T1, class T2>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_subref>operator , ( sc_uint_concref<T1,T2>, sc_uint_subref );template <class T1, class T2>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_base>operator , ( sc_uint_concref<T1,T2>, sc_uint_base& );template <class T1, class T2, class T3, class T4>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_concref<T3,T4> >concat( sc_uint_concref<T1,T2>, sc_uint_concref<T3,T4> );template <class T1, class T2>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_bitref>concat( sc_uint_concref<T1,T2>, sc_uint_bitref );template <class T1, class T2>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_subref>concat( sc_uint_concref<T1,T2>, sc_uint_subref );template <class T1, class T2>inlinesc_uint_concref<sc_uint_concref<T1,T2>,sc_uint_base>concat( sc_uint_concref<T1,T2>, sc_uint_base& );template <class T1, class T2>inlineistream&operator >> ( istream&, sc_uint_concref<T1,T2>& );// ----------------------------------------------------------------------------//  CLASS : sc_uint_bitref_r////  Proxy class for sc_uint bit selection (r-value only).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?