⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc_uint_base.h

📁 system C源码 一种替代verilog的语言
💻 H
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************  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_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: *****************************************************************************/// $Log: sc_uint_base.h,v $// Revision 1.1.1.1  2006/12/15 20:31:36  acg// SystemC 2.2//// Revision 1.3  2006/01/13 18:49:32  acg// Added $Log command so that CVS check in comments are reproduced in the// source.//#ifndef SC_UINT_BASE_H#define SC_UINT_BASE_H#include "sysc/kernel/sc_object.h"#include "sysc/datatypes/misc/sc_value_base.h"#include "sysc/datatypes/int/sc_int_ids.h"#include "sysc/datatypes/int/sc_length_param.h"#include "sysc/datatypes/int/sc_nbdefs.h"#include "sysc/datatypes/fx/scfx_ieee.h"#include "sysc/utils/sc_iostream.h"#include "sysc/utils/sc_temporary.h"namespace sc_dt{class sc_concatref;// classes defined in this moduleclass 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_int_subref_r;class sc_signed_subref_r;class sc_unsigned_subref_r;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];// friend operator declarations    inline bool operator == ( const sc_uint_base& a, const sc_uint_base& b );    inline bool operator != ( const sc_uint_base& a, const sc_uint_base& b );    inline bool operator <  ( const sc_uint_base& a, const sc_uint_base& b );    inline bool operator <= ( const sc_uint_base& a, const sc_uint_base& b );    inline bool operator >  ( const sc_uint_base& a, const sc_uint_base& b );    inline bool operator >= ( const sc_uint_base& a, const sc_uint_base& b );// ----------------------------------------------------------------------------//  CLASS : sc_uint_bitref_r////  Proxy class for sc_uint bit selection (r-value only).// ----------------------------------------------------------------------------class sc_uint_bitref_r : public sc_value_base{    friend class sc_uint_base;    friend class sc_uint_signal;    // constructorspublic:    sc_uint_bitref_r( const sc_uint_bitref_r& init ) :	 m_index(init.m_index), m_obj_p(init.m_obj_p)	 {}protected:    sc_uint_bitref_r()        {}    // initializer for sc_core::sc_vpool:    void initialize( const sc_uint_base* obj_p, int index_ )    {        m_obj_p = (sc_uint_base*)obj_p;        m_index = index_;    }public:    // destructor    virtual ~sc_uint_bitref_r()	{}    // concatenation support    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_mask = 1 << (low_i % BITS_PER_DIGIT);            int  word_i = low_i / BITS_PER_DIGIT;	    dst_p[word_i] &= ~bit_mask;	    return false;        }    virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const        {            int  bit_mask = 1 << (low_i % BITS_PER_DIGIT);	    bool result;             // True is non-zero.            int  word_i = low_i / BITS_PER_DIGIT;            if ( operator uint64() )	    {                dst_p[word_i] |= bit_mask;		result = true;	    }            else	    {                dst_p[word_i] &= ~bit_mask;		result = false;	    }	    return result;        }    virtual uint64 concat_get_uint64() const	{ return operator uint64(); }    // capacity    int length() const	{ return 1; }#ifdef SC_DT_DEPRECATED    int bitwidth() const	{ return length(); }#endif    // implicit conversion to uint64    operator uint64 () const;    bool operator ! () const;    bool operator ~ () const;    // explicit conversions    uint64 value() const	{ return operator uint64 (); }    bool to_bool() const	{ return operator uint64 (); }    // other methods    void print( ::std::ostream& os = ::std::cout ) const	{ os << to_bool(); }protected:    int           m_index;    sc_uint_base* m_obj_p;private:    // disabled    sc_uint_bitref_r& operator = ( const sc_uint_bitref_r& );};inline::std::ostream&operator << ( ::std::ostream&, const sc_uint_bitref_r& );// ----------------------------------------------------------------------------//  CLASS : sc_uint_bitref////  Proxy class for sc_uint bit selection (r-value and l-value).// ----------------------------------------------------------------------------class sc_uint_bitref    : public sc_uint_bitref_r{    friend class sc_uint_base;    friend class sc_core::sc_vpool<sc_uint_bitref>;    // constructorsprotected:    sc_uint_bitref()        {}public:    sc_uint_bitref( const sc_uint_bitref& init ) : sc_uint_bitref_r(init)        {}public:    // assignment operators    sc_uint_bitref& operator = ( const sc_uint_bitref_r& b );    sc_uint_bitref& operator = ( const sc_uint_bitref& b );    sc_uint_bitref& operator = ( bool b );    sc_uint_bitref& operator &= ( bool b );    sc_uint_bitref& operator |= ( bool b );    sc_uint_bitref& operator ^= ( bool b );	// concatenation methods    virtual void concat_set(int64 src, int low_i);    virtual void concat_set(const sc_signed& src, int low_i);    virtual void concat_set(const sc_unsigned& src, int low_i);    virtual void concat_set(uint64 src, int low_i);    // other methods    void scan( ::std::istream& is = ::std::cin );protected:    static sc_core::sc_vpool<sc_uint_bitref> m_pool;};inline::std::istream&operator >> ( ::std::istream&, sc_uint_bitref& );// ----------------------------------------------------------------------------//  CLASS : sc_uint_subref_r////  Proxy class for sc_uint part selection (r-value only).// ----------------------------------------------------------------------------class sc_uint_subref_r : public sc_value_base{    friend class sc_uint_base;	friend class sc_uint_subref;    // constructorspublic:    sc_uint_subref_r( const sc_uint_subref_r& init ) :        m_left(init.m_left), m_obj_p(init.m_obj_p), m_right(init.m_right)	{}protected:    sc_uint_subref_r()	{}    // initializer for sc_core::sc_vpool:    void initialize( const sc_uint_base* obj_p, int left_i, int right_i )    {        m_obj_p = (sc_uint_base*)obj_p;        m_left = left_i;        m_right = right_i;    }public:    // destructor    virtual ~sc_uint_subref_r()	{}    // capacity    int length() const	{ return ( m_left - m_right + 1 ); }#ifdef SC_DT_DEPRECATED    int bitwidth() const	{ return length(); }#endif    // concatenation support    virtual int concat_length(bool* xz_present_p) const	{ if ( xz_present_p ) *xz_present_p = false; return length(); }    virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;    virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;    virtual uint64 concat_get_uint64() const	{ return (uint64)operator uint_type(); }    // 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 std::string to_string( sc_numrep numrep = SC_DEC ) const;    const std::string to_string( sc_numrep numrep, bool w_prefix ) const;    // other methods    void print( ::std::ostream& os = ::std::cout ) const	{ os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }protected:    int           m_left;    sc_uint_base* m_obj_p;    int           m_right;private:    // disabled    sc_uint_subref_r& operator = ( const sc_uint_subref_r& );};inline::std::ostream&operator << ( ::std::ostream&, const sc_uint_subref_r& );// ----------------------------------------------------------------------------//  CLASS : sc_uint_subref////  Proxy class for sc_uint part selection (r-value and l-value).// ----------------------------------------------------------------------------class sc_uint_subref    : public sc_uint_subref_r{    friend class sc_uint_base;    friend class sc_core::sc_vpool<sc_uint_subref>;    // constructorsprotected:    sc_uint_subref()        {}public:    sc_uint_subref( const sc_uint_subref& init ) : sc_uint_subref_r(init)        {}public:    // assignment operators    sc_uint_subref& operator = ( uint_type v );    sc_uint_subref& operator = ( const sc_uint_base& a );    sc_uint_subref& operator = ( const sc_uint_subref_r& a )	{ return operator = ( a.operator uint_type() ); }    sc_uint_subref& operator = ( const sc_uint_subref& a )	{ return operator = ( a.operator uint_type() ); }    template<class T>    sc_uint_subref& operator = ( const sc_generic_base<T>& a )        { return operator = ( a->to_uint64() ); }    sc_uint_subref& operator = ( const char* a );    sc_uint_subref& operator = ( unsigned long a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( long a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( unsigned int a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( int a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( int64 a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( double a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( const sc_signed& );    sc_uint_subref& operator = ( const sc_unsigned& );    sc_uint_subref& operator = ( const sc_bv_base& );    sc_uint_subref& operator = ( const sc_lv_base& );	// concatenation methods    virtual void concat_set(int64 src, int low_i);    virtual void concat_set(const sc_signed& src, int low_i);    virtual void concat_set(const sc_unsigned& src, int low_i);    virtual void concat_set(uint64 src, int low_i);    // other methods    void scan( ::std::istream& is = ::std::cin );protected:    static sc_core::sc_vpool<sc_uint_subref> m_pool;};inline::std::istream&operator >> ( ::std::istream&, sc_uint_subref& );// ----------------------------------------------------------------------------//  CLASS : sc_uint_base////  Base class for sc_uint.// ----------------------------------------------------------------------------class sc_uint_base : public sc_value_base{    friend class sc_uint_bitref_r;    friend class sc_uint_bitref;    friend class sc_uint_subref_r;    friend class sc_uint_subref;    // support methods    void invalid_length() const;    void invalid_index( int i ) const;    void invalid_range( int l, int r ) const;    void check_length() const	{ if( m_len <= 0 || m_len > SC_INTWIDTH ) { invalid_length(); } }    void check_index( int i ) const	{ if( i < 0 || i >= m_len ) { invalid_index( i ); } }    void check_range( int l, int r ) const	{ if( r < 0 || l >= m_len || l < r ) { invalid_range( l, r ); } }    void check_value() const;    void extend_sign()	{#ifdef DEBUG_SYSTEMC	    check_value();#endif	    m_val &= ( ~UINT_ZERO >> m_ulen );	}public:    // constructors    explicit sc_uint_base( int w = sc_length_param().len() )	: m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )	{ check_length(); }    sc_uint_base( uint_type v, int w )	: m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )	{ check_length(); extend_sign(); }    sc_uint_base( const sc_uint_base& a )	: m_val( a.m_val ), m_len( a.m_len ), m_ulen( a.m_ulen )	{}    explicit sc_uint_base( const sc_uint_subref_r& a )        : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )        { extend_sign(); }    template<class T>    explicit sc_uint_base( const sc_generic_base<T>& a )	: m_val( a->to_uint64() ), m_len( a->length() ),	  m_ulen( SC_INTWIDTH - m_len )	{ check_length(); extend_sign(); }    explicit sc_uint_base( const sc_bv_base& v );    explicit sc_uint_base( const sc_lv_base& v );    explicit sc_uint_base( const sc_int_subref_r& v );    explicit sc_uint_base( const sc_signed_subref_r& v );    explicit sc_uint_base( const sc_unsigned_subref_r& v );    explicit sc_uint_base( const sc_signed& a );    explicit sc_uint_base( const sc_unsigned& a );    // destructor    virtual ~sc_uint_base()	{}    // assignment operators    sc_uint_base& operator = ( uint_type v )	{ m_val = v; extend_sign(); return *this; }    sc_uint_base& operator = ( const sc_uint_base& a )	{ m_val = a.m_val; extend_sign(); return *this; }    sc_uint_base& operator = ( const sc_uint_subref_r& a )        { m_val = a; extend_sign(); return *this; }    template<class T>    sc_uint_base& operator = ( const sc_generic_base<T>& a )        { m_val = a->to_uint64(); extend_sign(); return *this; }    sc_uint_base& operator = ( const sc_signed& a );    sc_uint_base& operator = ( const sc_unsigned& a );#ifdef SC_INCLUDE_FX    sc_uint_base& operator = ( const sc_fxval& a );    sc_uint_base& operator = ( const sc_fxval_fast& a );    sc_uint_base& operator = ( const sc_fxnum& a );    sc_uint_base& operator = ( const sc_fxnum_fast& a );#endif    sc_uint_base& operator = ( const sc_bv_base& a );    sc_uint_base& operator = ( const sc_lv_base& a );    sc_uint_base& operator = ( const char* a );    sc_uint_base& operator = ( unsigned long a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( long a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( unsigned int a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( int a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( int64 a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( double a )	{ m_val = (uint_type) a; extend_sign(); return *this; }    // arithmetic assignment operators    sc_uint_base& operator += ( uint_type v )	{ m_val += v; extend_sign(); return *this; }    sc_uint_base& operator -= ( uint_type v )	{ m_val -= v; extend_sign(); return *this; }    sc_uint_base& operator *= ( uint_type v )	{ m_val *= v; extend_sign(); return *this; }    sc_uint_base& operator /= ( uint_type v )	{ m_val /= v; extend_sign(); return *this; }    sc_uint_base& operator %= ( uint_type v )	{ m_val %= v; extend_sign(); return *this; }    // bitwise assignment operators    sc_uint_base& operator &= ( uint_type v )	{ m_val &= v; extend_sign(); return *this; }    sc_uint_base& operator |= ( uint_type v )	{ m_val |= v; extend_sign(); return *this; }    sc_uint_base& operator ^= ( uint_type v )	{ m_val ^= v; extend_sign(); return *this; }    sc_uint_base& operator <<= ( uint_type v )	{ m_val <<= v; extend_sign(); return *this; }    sc_uint_base& operator >>= ( uint_type v )	{ m_val >>= v; /* no sign extension needed */ return *this; }

⌨️ 快捷键说明

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