src/sysc/datatypes/int/sc_uint_base.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_uint_base.h -- A sc_uint is an unsigned integer whose length is less than
00021                the machine's native integer length. We provide two
00022                implementations (i) sc_uint with length between 1 - 64, and (ii)
00023                sc_uint with length between 1 - 32. Implementation (i) is the
00024                default implementation, while implementation (ii) can be used
00025                only if compiled with -D_32BIT_. Unlike arbitrary precision,
00026                arithmetic and bitwise operations are performed using the native
00027                types (hence capped at 32/64 bits). The sc_uint integer is
00028                useful when the user does not need arbitrary precision and the
00029                performance is superior to sc_bigint/sc_biguint.
00030 
00031   Original Author: Amit Rao, Synopsys, Inc.
00032 
00033  *****************************************************************************/
00034 
00035 /*****************************************************************************
00036 
00037   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00038   changes you are making here.
00039 
00040       Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
00041   Description of Modification: - Resolved ambiguity with sc_(un)signed.
00042                                - Merged the code for 64- and 32-bit versions
00043                                  via the constants in sc_nbdefs.h.
00044                                - Eliminated redundant file inclusions.
00045 
00046       Name, Affiliation, Date:
00047   Description of Modification:
00048 
00049  *****************************************************************************/
00050 
00051 #ifndef SC_UINT_BASE_H
00052 #define SC_UINT_BASE_H
00053 
00054 
00055 #include "sysc/kernel/sc_object.h"
00056 #include "sysc/datatypes/misc/sc_value_base.h"
00057 #include "sysc/datatypes/int/sc_int_ids.h"
00058 #include "sysc/datatypes/int/sc_length_param.h"
00059 #include "sysc/datatypes/int/sc_nbdefs.h"
00060 #include "sysc/datatypes/fx/scfx_ieee.h"
00061 #include "sysc/utils/sc_iostream.h"
00062 #include "sysc/utils/sc_temporary.h"
00063 
00064 
00065 namespace sc_dt
00066 {
00067 
00068 class sc_concatref;
00069 
00070 // classes defined in this module
00071 class sc_uint_bitref_r;
00072 class sc_uint_bitref;
00073 class sc_uint_subref_r;
00074 class sc_uint_subref;
00075 class sc_uint_base;
00076 
00077 // forward class declarations
00078 class sc_bv_base;
00079 class sc_lv_base;
00080 class sc_int_subref_r;
00081 class sc_signed_subref_r;
00082 class sc_unsigned_subref_r;
00083 class sc_signed;
00084 class sc_unsigned;
00085 class sc_fxval;
00086 class sc_fxval_fast;
00087 class sc_fxnum;
00088 class sc_fxnum_fast;
00089 
00090 
00091 extern const uint_type mask_int[SC_INTWIDTH][SC_INTWIDTH];
00092 
00093 
00094 
00095 // ----------------------------------------------------------------------------
00096 //  CLASS : sc_uint_bitref_r
00097 //
00098 //  Proxy class for sc_uint bit selection (r-value only).
00099 // ----------------------------------------------------------------------------
00100 
00101 class sc_uint_bitref_r : public sc_value_base
00102 {
00103     friend class sc_uint_base;
00104     friend class sc_uint_signal;
00105 
00106 
00107     // constructors
00108 
00109 public:
00110     sc_uint_bitref_r( const sc_uint_bitref_r& init ) :
00111          m_index(init.m_index), m_obj_p(init.m_obj_p)
00112          {}
00113 
00114 protected:
00115     sc_uint_bitref_r()
00116         {}
00117 
00118     // initializer for sc_core::sc_vpool:
00119 
00120     void initialize( const sc_uint_base* obj_p, int index_ )
00121     {
00122         m_obj_p = (sc_uint_base*)obj_p;
00123         m_index = index_;
00124     }
00125 
00126 public:
00127 
00128     // destructor
00129 
00130     virtual ~sc_uint_bitref_r() 
00131         {}
00132 
00133     // concatenation support
00134 
00135     virtual int concat_length(bool* xz_present_p) const
00136         { if ( xz_present_p ) *xz_present_p = false; return 1; }
00137     virtual bool concat_get_ctrl( unsigned long* dst_p, int low_i ) const    
00138         { 
00139             int  bit_mask = 1 << (low_i % BITS_PER_DIGIT);
00140             int  word_i = low_i / BITS_PER_DIGIT;
00141 
00142             dst_p[word_i] &= ~bit_mask;
00143             return false;
00144         }
00145     virtual bool concat_get_data( unsigned long* dst_p, int low_i ) const    
00146         { 
00147             int  bit_mask = 1 << (low_i % BITS_PER_DIGIT);
00148             bool result;             // True is non-zero.
00149             int  word_i = low_i / BITS_PER_DIGIT;
00150 
00151             if ( operator uint64() )
00152             {
00153                 dst_p[word_i] |= bit_mask;
00154                 result = true;
00155             }
00156             else
00157             {
00158                 dst_p[word_i] &= ~bit_mask;
00159                 result = false;
00160             }
00161             return result;
00162         }
00163     virtual uint64 concat_get_uint64() const
00164         { return operator uint64(); }
00165 
00166     // capacity
00167 
00168     int length() const
00169         { return 1; }
00170 
00171 #ifdef SC_DT_DEPRECATED
00172     int bitwidth() const
00173         { return length(); }
00174 #endif
00175 
00176 
00177     // implicit conversion to uint64
00178 
00179     operator uint64 () const;
00180     bool operator ! () const;
00181     bool operator ~ () const;
00182 
00183 
00184     // explicit conversions
00185 
00186     uint64 value() const
00187         { return operator uint64 (); }
00188 
00189     bool to_bool() const
00190         { return operator uint64 (); }
00191 
00192 
00193     // other methods
00194 
00195     void print( ::std::ostream& os = ::std::cout ) const
00196         { os << to_bool(); }
00197 
00198 protected:
00199 
00200     int           m_index;
00201     sc_uint_base* m_obj_p;
00202 
00203 private:
00204 
00205     // disabled
00206     sc_uint_bitref_r& operator = ( const sc_uint_bitref_r& );
00207 };
00208 
00209 
00210 
00211 inline
00212 ::std::ostream&
00213 operator << ( ::std::ostream&, const sc_uint_bitref_r& );
00214 
00215 
00216 // ----------------------------------------------------------------------------
00217 //  CLASS : sc_uint_bitref
00218 //
00219 //  Proxy class for sc_uint bit selection (r-value and l-value).
00220 // ----------------------------------------------------------------------------
00221 
00222 class sc_uint_bitref
00223     : public sc_uint_bitref_r
00224 {
00225     friend class sc_uint_base;
00226     friend class sc_core::sc_vpool<sc_uint_bitref>;
00227 
00228 
00229     // constructors
00230 
00231 protected:
00232     sc_uint_bitref()
00233         {}
00234 public:
00235     sc_uint_bitref( const sc_uint_bitref& init ) : sc_uint_bitref_r(init)
00236         {}
00237 
00238 public:
00239 
00240     // assignment operators
00241 
00242     sc_uint_bitref& operator = ( const sc_uint_bitref_r& b );
00243     sc_uint_bitref& operator = ( const sc_uint_bitref& b );
00244     sc_uint_bitref& operator = ( bool b );
00245 
00246     sc_uint_bitref& operator &= ( bool b );
00247     sc_uint_bitref& operator |= ( bool b );
00248     sc_uint_bitref& operator ^= ( bool b );
00249 
00250         // concatenation methods
00251 
00252     virtual void concat_set(int64 src, int low_i);
00253     virtual void concat_set(const sc_signed& src, int low_i);
00254     virtual void concat_set(const sc_unsigned& src, int low_i);
00255     virtual void concat_set(uint64 src, int low_i);
00256 
00257     // other methods
00258 
00259     void scan( ::std::istream& is = ::std::cin );
00260 
00261 protected:
00262     static sc_core::sc_vpool<sc_uint_bitref> m_pool;
00263 
00264 };
00265 
00266 
00267 
00268 inline
00269 ::std::istream&
00270 operator >> ( ::std::istream&, sc_uint_bitref& );
00271 
00272 
00273 // ----------------------------------------------------------------------------
00274 //  CLASS : sc_uint_subref_r
00275 //
00276 //  Proxy class for sc_uint part selection (r-value only).
00277 // ----------------------------------------------------------------------------
00278 
00279 class sc_uint_subref_r : public sc_value_base
00280 {
00281     friend class sc_uint_base;
00282         friend class sc_uint_subref;
00283 
00284 
00285     // constructors
00286 
00287 public:
00288     sc_uint_subref_r( const sc_uint_subref_r& init ) :
00289         m_left(init.m_left), m_obj_p(init.m_obj_p), m_right(init.m_right)
00290         {}
00291     
00292 protected:
00293     sc_uint_subref_r() 
00294         {}
00295  
00296     // initializer for sc_core::sc_vpool:
00297 
00298     void initialize( const sc_uint_base* obj_p, int left_i, int right_i )
00299     {
00300         m_obj_p = (sc_uint_base*)obj_p;
00301         m_left = left_i;
00302         m_right = right_i;
00303     }
00304 
00305 public:
00306 
00307     // destructor
00308 
00309     virtual ~sc_uint_subref_r() 
00310         {}
00311 
00312     // capacity
00313 
00314     int length() const
00315         { return ( m_left - m_right + 1 ); }
00316 
00317 #ifdef SC_DT_DEPRECATED
00318     int bitwidth() const
00319         { return length(); }
00320 #endif
00321 
00322     // concatenation support
00323 
00324     virtual int concat_length(bool* xz_present_p) const
00325         { if ( xz_present_p ) *xz_present_p = false; return length(); }
00326     virtual bool concat_get_ctrl( unsigned long* dst_p, int low_i ) const;
00327     virtual bool concat_get_data( unsigned long* dst_p, int low_i ) const;
00328     virtual uint64 concat_get_uint64() const
00329         { return (uint64)operator uint_type(); }
00330 
00331 
00332     // reduce methods
00333 
00334     bool and_reduce() const;
00335 
00336     bool nand_reduce() const
00337         { return ( ! and_reduce() ); }
00338 
00339     bool or_reduce() const;
00340 
00341     bool nor_reduce() const
00342         { return ( ! or_reduce() ); }
00343 
00344     bool xor_reduce() const;
00345 
00346     bool xnor_reduce() const
00347         { return ( ! xor_reduce() ); }
00348 
00349 
00350     // implicit conversion to uint_type
00351 
00352     operator uint_type() const;
00353 
00354 
00355     // explicit conversions
00356 
00357     uint_type value() const
00358         { return operator uint_type(); }
00359 
00360 
00361     int           to_int() const;
00362     unsigned int  to_uint() const;
00363     long          to_long() const;
00364     unsigned long to_ulong() const;
00365     int64         to_int64() const;
00366     uint64        to_uint64() const;
00367     double        to_double() const;
00368 
00369 
00370     // explicit conversion to character string
00371 
00372     const std::string to_string( sc_numrep numrep = SC_DEC ) const;
00373     const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
00374 
00375 
00376     // other methods
00377 
00378     void print( ::std::ostream& os = ::std::cout ) const
00379         { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
00380 
00381 protected:
00382 
00383     int           m_left;
00384     sc_uint_base* m_obj_p;
00385     int           m_right;
00386 
00387 private:
00388 
00389     // disabled
00390     sc_uint_subref_r& operator = ( const sc_uint_subref_r& );
00391 };
00392 
00393 
00394 
00395 inline
00396 ::std::ostream&
00397 operator << ( ::std::ostream&, const sc_uint_subref_r& );
00398 
00399 
00400 // ----------------------------------------------------------------------------
00401 //  CLASS : sc_uint_subref
00402 //
00403 //  Proxy class for sc_uint part selection (r-value and l-value).
00404 // ----------------------------------------------------------------------------
00405 
00406 class sc_uint_subref
00407     : public sc_uint_subref_r
00408 {
00409     friend class sc_uint_base;
00410     friend class sc_core::sc_vpool<sc_uint_subref>;
00411 
00412 
00413     // constructors
00414 
00415 protected:
00416     sc_uint_subref()
00417         {}
00418 
00419 public:
00420     sc_uint_subref( const sc_uint_subref& init ) : sc_uint_subref_r(init)
00421         {}
00422   
00423 public:
00424 
00425     // assignment operators
00426 
00427     sc_uint_subref& operator = ( uint_type v );
00428 
00429     sc_uint_subref& operator = ( const sc_uint_base& a );
00430 
00431     sc_uint_subref& operator = ( const sc_uint_subref_r& a )
00432         { return operator = ( a.operator uint_type() ); }
00433 
00434     sc_uint_subref& operator = ( const sc_uint_subref& a )
00435         { return operator = ( a.operator uint_type() ); }
00436 
00437     template<class T>
00438     sc_uint_subref& operator = ( const sc_generic_base<T>& a )
00439         { return operator = ( a->to_uint64() ); }
00440 
00441     sc_uint_subref& operator = ( const char* a );
00442 
00443     sc_uint_subref& operator = ( unsigned long a )
00444         { return operator = ( (uint_type) a ); }
00445 
00446     sc_uint_subref& operator = ( long a )
00447         { return operator = ( (uint_type) a ); }
00448 
00449     sc_uint_subref& operator = ( unsigned int a )
00450         { return operator = ( (uint_type) a ); }
00451 
00452     sc_uint_subref& operator = ( int a )
00453         { return operator = ( (uint_type) a ); }
00454 
00455     sc_uint_subref& operator = ( int64 a )
00456         { return operator = ( (uint_type) a ); }
00457 
00458     sc_uint_subref& operator = ( double a )
00459         { return operator = ( (uint_type) a ); }
00460 
00461     sc_uint_subref& operator = ( const sc_signed& );
00462     sc_uint_subref& operator = ( const sc_unsigned& );
00463     sc_uint_subref& operator = ( const sc_bv_base& );
00464     sc_uint_subref& operator = ( const sc_lv_base& );
00465 
00466         // concatenation methods
00467 
00468     virtual void concat_set(int64 src, int low_i);
00469     virtual void concat_set(const sc_signed& src, int low_i);
00470     virtual void concat_set(const sc_unsigned& src, int low_i);
00471     virtual void concat_set(uint64 src, int low_i);
00472 
00473     // other methods
00474 
00475     void scan( ::std::istream& is = ::std::cin );
00476 
00477 protected:
00478     static sc_core::sc_vpool<sc_uint_subref> m_pool;
00479 
00480 };
00481 
00482 
00483 
00484 inline
00485 ::std::istream&
00486 operator >> ( ::std::istream&, sc_uint_subref& );
00487 
00488 
00489 // ----------------------------------------------------------------------------
00490 //  CLASS : sc_uint_base
00491 //
00492 //  Base class for sc_uint.
00493 // ----------------------------------------------------------------------------
00494 
00495 class sc_uint_base : public sc_value_base
00496 {
00497     friend class sc_uint_bitref_r;
00498     friend class sc_uint_bitref;
00499     friend class sc_uint_subref_r;
00500     friend class sc_uint_subref;
00501 
00502 
00503     // support methods
00504 
00505     void invalid_length() const;
00506     void invalid_index( int i ) const;
00507     void invalid_range( int l, int r ) const;
00508 
00509     void check_length() const
00510         { if( m_len <= 0 || m_len > SC_INTWIDTH ) { invalid_length(); } }
00511 
00512     void check_index( int i ) const
00513         { if( i < 0 || i >= m_len ) { invalid_index( i ); } }
00514 
00515     void check_range( int l, int r ) const
00516         { if( r < 0 || l >= m_len || l < r ) { invalid_range( l, r ); } }
00517 
00518     void check_value() const;
00519 
00520     void extend_sign()
00521         {
00522 #ifdef DEBUG_SYSTEMC
00523             check_value();
00524 #endif
00525             m_val &= ( ~UINT_ZERO >> m_ulen );
00526         }
00527 
00528 public:
00529 
00530     // constructors
00531 
00532     explicit sc_uint_base( int w = sc_length_param().len() )
00533         : m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
00534         { check_length(); }
00535 
00536     sc_uint_base( uint_type v, int w )
00537         : m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
00538         { check_length(); extend_sign(); }
00539 
00540     sc_uint_base( const sc_uint_base& a )
00541         : m_val( a.m_val ), m_len( a.m_len ), m_ulen( a.m_ulen )
00542         {}
00543 
00544     explicit sc_uint_base( const sc_uint_subref_r& a )
00545         : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )
00546         { extend_sign(); }
00547 
00548     template<class T>
00549     explicit sc_uint_base( const sc_generic_base<T>& a )
00550         : m_val( a->to_uint64() ), m_len( a->length() ), 
00551           m_ulen( SC_INTWIDTH - m_len )
00552         { check_length(); extend_sign(); }
00553 
00554     explicit sc_uint_base( const sc_bv_base& v );
00555     explicit sc_uint_base( const sc_lv_base& v );
00556     explicit sc_uint_base( const sc_int_subref_r& v );
00557     explicit sc_uint_base( const sc_signed_subref_r& v );
00558     explicit sc_uint_base( const sc_unsigned_subref_r& v );
00559     explicit sc_uint_base( const sc_signed& a );
00560     explicit sc_uint_base( const sc_unsigned& a );
00561 
00562 
00563     // destructor
00564 
00565     virtual ~sc_uint_base()
00566         {}
00567 
00568 
00569     // assignment operators
00570 
00571     sc_uint_base& operator = ( uint_type v )
00572         { m_val = v; extend_sign(); return *this; }
00573 
00574     sc_uint_base& operator = ( const sc_uint_base& a )
00575         { m_val = a.m_val; extend_sign(); return *this; }
00576 
00577     sc_uint_base& operator = ( const sc_uint_subref_r& a )
00578         { m_val = a; extend_sign(); return *this; }
00579 
00580     template<class T>
00581     sc_uint_base& operator = ( const sc_generic_base<T>& a )
00582         { m_val = a->to_uint64(); extend_sign(); return *this; }
00583 
00584     sc_uint_base& operator = ( const sc_signed& a );
00585     sc_uint_base& operator = ( const sc_unsigned& a );
00586 
00587 #ifdef SC_INCLUDE_FX
00588     sc_uint_base& operator = ( const sc_fxval& a );
00589     sc_uint_base& operator = ( const sc_fxval_fast& a );
00590     sc_uint_base& operator = ( const sc_fxnum& a );
00591     sc_uint_base& operator = ( const sc_fxnum_fast& a );
00592 #endif
00593 
00594     sc_uint_base& operator = ( const sc_bv_base& a );
00595     sc_uint_base& operator = ( const sc_lv_base& a );
00596 
00597     sc_uint_base& operator = ( const char* a );
00598 
00599     sc_uint_base& operator = ( unsigned long a )
00600         { m_val = a; extend_sign(); return *this; }
00601 
00602     sc_uint_base& operator = ( long a )
00603         { m_val = a; extend_sign(); return *this; }
00604 
00605     sc_uint_base& operator = ( unsigned int a )
00606         { m_val = a; extend_sign(); return *this; }
00607 
00608     sc_uint_base& operator = ( int a )
00609         { m_val = a; extend_sign(); return *this; }
00610 
00611     sc_uint_base& operator = ( int64 a )
00612         { m_val = a; extend_sign(); return *this; }
00613 
00614     sc_uint_base& operator = ( double a )
00615         { m_val = (uint_type) a; extend_sign(); return *this; }
00616 
00617 
00618     // arithmetic assignment operators
00619 
00620     sc_uint_base& operator += ( uint_type v )
00621         { m_val += v; extend_sign(); return *this; }
00622 
00623     sc_uint_base& operator -= ( uint_type v )
00624         { m_val -= v; extend_sign(); return *this; }
00625 
00626     sc_uint_base& operator *= ( uint_type v )
00627         { m_val *= v; extend_sign(); return *this; }
00628 
00629     sc_uint_base& operator /= ( uint_type v )
00630         { m_val /= v; extend_sign(); return *this; }
00631 
00632     sc_uint_base& operator %= ( uint_type v )
00633         { m_val %= v; extend_sign(); return *this; }
00634 
00635 
00636     // bitwise assignment operators
00637 
00638     sc_uint_base& operator &= ( uint_type v )
00639         { m_val &= v; extend_sign(); return *this; }
00640 
00641     sc_uint_base& operator |= ( uint_type v )
00642         { m_val |= v; extend_sign(); return *this; }
00643 
00644     sc_uint_base& operator ^= ( uint_type v )
00645         { m_val ^= v; extend_sign(); return *this; }
00646 
00647 
00648     sc_uint_base& operator <<= ( uint_type v )
00649         { m_val <<= v; extend_sign(); return *this; }
00650 
00651     sc_uint_base& operator >>= ( uint_type v )
00652         { m_val >>= v; /* no sign extension needed */ return *this; }
00653 
00654 
00655     // prefix and postfix increment and decrement operators
00656 
00657     sc_uint_base& operator ++ () // prefix
00658         { ++ m_val; extend_sign(); return *this; }
00659 
00660     const sc_uint_base operator ++ ( int ) // postfix
00661         { sc_uint_base tmp( *this ); ++ m_val; extend_sign(); return tmp; }
00662 
00663     sc_uint_base& operator -- () // prefix
00664         { -- m_val; extend_sign(); return *this; }
00665 
00666     const sc_uint_base operator -- ( int ) // postfix
00667         { sc_uint_base tmp( *this ); -- m_val; extend_sign(); return tmp; }
00668 
00669 
00670     // relational operators
00671 
00672     friend bool operator == ( const sc_uint_base& a, const sc_uint_base& b )
00673         { return a.m_val == b.m_val; }
00674 
00675     friend bool operator != ( const sc_uint_base& a, const sc_uint_base& b )
00676         { return a.m_val != b.m_val; }
00677 
00678     friend bool operator <  ( const sc_uint_base& a, const sc_uint_base& b )
00679         { return a.m_val < b.m_val; }
00680 
00681     friend bool operator <= ( const sc_uint_base& a, const sc_uint_base& b )
00682         { return a.m_val <= b.m_val; }
00683 
00684     friend bool operator >  ( const sc_uint_base& a, const sc_uint_base& b )
00685         { return a.m_val > b.m_val; }
00686 
00687     friend bool operator >= ( const sc_uint_base& a, const sc_uint_base& b )
00688         { return a.m_val >= b.m_val; }
00689 
00690 
00691     // bit selection
00692   
00693     sc_uint_bitref&         operator [] ( int i );
00694     const sc_uint_bitref_r& operator [] ( int i ) const;
00695 
00696     sc_uint_bitref&         bit( int i );
00697     const sc_uint_bitref_r& bit( int i ) const;
00698 
00699 
00700     // part selection
00701 
00702     sc_uint_subref&         operator () ( int left, int right );
00703     const sc_uint_subref_r& operator () ( int left, int right ) const;
00704 
00705     sc_uint_subref&         range( int left, int right );
00706     const sc_uint_subref_r& range( int left, int right ) const;
00707 
00708 
00709     // bit access, without bounds checking or sign extension
00710   
00711     bool test( int i ) const
00712         { return ( 0 != (m_val & (UINT_ONE << i)) ); }
00713 
00714     void set( int i )
00715         { m_val |= (UINT_ONE << i); }
00716 
00717     void set( int i, bool v )
00718         { v ? m_val |= (UINT_ONE << i) : m_val &= ~(UINT_ONE << i); }
00719 
00720 
00721     // capacity
00722 
00723     int length() const
00724         { return m_len; }
00725 
00726 #ifdef SC_DT_DEPRECATED
00727     int bitwidth() const
00728         { return length(); }
00729 #endif
00730 
00731     // concatenation support
00732 
00733     virtual int concat_length(bool* xz_present_p) const
00734         { if ( xz_present_p ) *xz_present_p = false; return length(); }
00735     virtual bool concat_get_ctrl( unsigned long* dst_p, int low_i ) const;
00736     virtual bool concat_get_data( unsigned long* dst_p, int low_i ) const;
00737     virtual uint64 concat_get_uint64() const
00738         { return m_val; }
00739     virtual void concat_set(int64 src, int low_i);
00740     virtual void concat_set(const sc_signed& src, int low_i);
00741     virtual void concat_set(const sc_unsigned& src, int low_i);
00742     virtual void concat_set(uint64 src, int low_i);
00743 
00744 
00745     // reduce methods
00746 
00747     bool and_reduce() const;
00748 
00749     bool nand_reduce() const
00750         { return ( ! and_reduce() ); }
00751 
00752     bool or_reduce() const;
00753 
00754     bool nor_reduce() const
00755         { return ( ! or_reduce() ); }
00756 
00757     bool xor_reduce() const;
00758 
00759     bool xnor_reduce() const
00760         { return ( ! xor_reduce() ); }
00761 
00762 
00763     // implicit conversion to uint_type
00764 
00765     operator uint_type() const
00766         { return m_val; }
00767 
00768 
00769     // explicit conversions
00770 
00771     uint_type value() const
00772         { return operator uint_type(); }
00773 
00774 
00775     int to_int() const
00776         { return (int) m_val; }
00777 
00778     unsigned int to_uint() const
00779         { return (unsigned int) m_val; }
00780 
00781     long to_long() const
00782         { return (long) m_val; }
00783 
00784     unsigned long to_ulong() const
00785         { return (unsigned long) m_val; }
00786 
00787     int64 to_int64() const
00788         { return (int64) m_val; }
00789 
00790     uint64 to_uint64() const
00791         { return (uint64) m_val; }
00792 
00793     double to_double() const
00794         { return uint64_to_double( m_val ); }
00795 
00796 
00797 #ifndef _32BIT_
00798     long long_low() const 
00799         { return (long) (m_val & UINT64_32ONES); }
00800 
00801     long long_high() const 
00802         { return (long) ((m_val >> 32) & UINT64_32ONES); }
00803 #endif
00804 
00805     // explicit conversion to character string
00806 
00807     const std::string to_string( sc_numrep numrep = SC_DEC ) const;
00808     const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
00809 
00810 
00811     // other methods
00812 
00813     void print( ::std::ostream& os = ::std::cout ) const
00814         { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
00815 
00816     void scan( ::std::istream& is = ::std::cin );
00817 
00818 protected:
00819 
00820     uint_type m_val;   // value
00821     int       m_len;   // length
00822     int       m_ulen;  // unused length
00823 };
00824 
00825 
00826 
00827 inline
00828 ::std::ostream&
00829 operator << ( ::std::ostream&, const sc_uint_base& );
00830 
00831 inline
00832 ::std::istream&
00833 operator >> ( ::std::istream&, sc_uint_base& );
00834 
00835 
00836 
00837 // ----------------------------------------------------------------------------
00838 //  CLASS : sc_uint_bitref_r
00839 //
00840 //  Proxy class for sc_uint bit selection (r-value only).
00841 // ----------------------------------------------------------------------------
00842 
00843 // implicit conversion to bool
00844 
00845 inline
00846 sc_uint_bitref_r::operator uint64 () const
00847 {
00848     return m_obj_p->test( m_index );
00849 }
00850 
00851 inline
00852 bool
00853 sc_uint_bitref_r::operator ! () const
00854 {
00855     return ! m_obj_p->test( m_index );
00856 }
00857 
00858 inline
00859 bool
00860 sc_uint_bitref_r::operator ~ () const
00861 {
00862     return ! m_obj_p->test( m_index );
00863 }
00864 
00865 
00866 
00867 inline
00868 ::std::ostream&
00869 operator << ( ::std::ostream& os, const sc_uint_bitref_r& a )
00870 {
00871     a.print( os );
00872     return os;
00873 }
00874 
00875 
00876 // ----------------------------------------------------------------------------
00877 //  CLASS : sc_uint_bitref
00878 //
00879 //  Proxy class for sc_uint bit selection (r-value and l-value).
00880 // ----------------------------------------------------------------------------
00881 
00882 // assignment operators
00883 
00884 inline
00885 sc_uint_bitref&
00886 sc_uint_bitref::operator = ( const sc_uint_bitref_r& b )
00887 {
00888     m_obj_p->set( m_index, b.to_bool() );
00889     return *this;
00890 }
00891 
00892 inline
00893 sc_uint_bitref&
00894 sc_uint_bitref::operator = ( const sc_uint_bitref& b )
00895 {
00896     m_obj_p->set( m_index, b.to_bool() );
00897     return *this;
00898 }
00899 
00900 inline
00901 sc_uint_bitref&
00902 sc_uint_bitref::operator = ( bool b )
00903 {
00904     m_obj_p->set( m_index, b );
00905     return *this;
00906 }
00907 
00908 
00909 inline
00910 sc_uint_bitref&
00911 sc_uint_bitref::operator &= ( bool b )
00912 {
00913     if( ! b ) {
00914         m_obj_p->set( m_index, b );
00915     }
00916     return *this;
00917 }
00918 
00919 inline
00920 sc_uint_bitref&
00921 sc_uint_bitref::operator |= ( bool b )
00922 {
00923     if( b ) {
00924         m_obj_p->set( m_index, b );
00925     }
00926     return *this;
00927 }
00928 
00929 inline
00930 sc_uint_bitref&
00931 sc_uint_bitref::operator ^= ( bool b )
00932 {
00933     if( b ) {
00934         m_obj_p->m_val ^= (UINT_ONE << m_index);
00935     }
00936     return *this;
00937 }
00938 
00939 
00940 
00941 inline
00942 ::std::istream&
00943 operator >> ( ::std::istream& is, sc_uint_bitref& a )
00944 {
00945     a.scan( is );
00946     return is;
00947 }
00948 
00949 
00950 // ----------------------------------------------------------------------------
00951 //  CLASS : sc_uint_subref_r
00952 //
00953 //  Proxy class for sc_uint part selection (r-value only).
00954 // ----------------------------------------------------------------------------
00955 
00956 // implicit conversion to uint_type
00957   
00958 inline
00959 sc_uint_subref_r::operator uint_type() const
00960 {
00961     uint_type val = m_obj_p->m_val;
00962     int uleft = SC_INTWIDTH - (m_left + 1);
00963     return ( (val & (~UINT_ZERO >> uleft)) >> m_right );
00964 }
00965 
00966 
00967 // reduce methods
00968 
00969 inline
00970 bool
00971 sc_uint_subref_r::and_reduce() const
00972 {
00973     sc_uint_base a( *this );
00974     return a.and_reduce();
00975 }
00976 
00977 inline
00978 bool
00979 sc_uint_subref_r::or_reduce() const
00980 {
00981     sc_uint_base a( *this );
00982     return a.or_reduce();
00983 }
00984 
00985 inline
00986 bool
00987 sc_uint_subref_r::xor_reduce() const
00988 {
00989     sc_uint_base a( *this );
00990     return a.xor_reduce();
00991 }
00992 
00993 
00994 // explicit conversions
00995 
00996 inline
00997 int
00998 sc_uint_subref_r::to_int() const
00999 {
01000     sc_uint_base a( *this );
01001     return a.to_int();
01002 }
01003 
01004 inline
01005 unsigned int
01006 sc_uint_subref_r::to_uint() const
01007 {
01008     sc_uint_base a( *this );
01009     return a.to_uint();
01010 }
01011 
01012 inline
01013 long
01014 sc_uint_subref_r::to_long() const
01015 {
01016     sc_uint_base a( *this );
01017     return a.to_long();
01018 }
01019 
01020 inline
01021 unsigned long
01022 sc_uint_subref_r::to_ulong() const
01023 {
01024     sc_uint_base a( *this );
01025     return a.to_ulong();
01026 }
01027 
01028 inline
01029 int64
01030 sc_uint_subref_r::to_int64() const
01031 {
01032     sc_uint_base a( *this );
01033     return a.to_int64();
01034 }
01035 
01036 inline
01037 uint64
01038 sc_uint_subref_r::to_uint64() const
01039 {
01040     sc_uint_base a( *this );
01041     return a.to_uint64();
01042 }
01043 
01044 inline
01045 double
01046 sc_uint_subref_r::to_double() const
01047 {
01048     sc_uint_base a( *this );
01049     return a.to_double();
01050 }
01051 
01052 
01053 // explicit conversion to character string
01054 
01055 inline
01056 const std::string
01057 sc_uint_subref_r::to_string( sc_numrep numrep ) const
01058 {
01059     sc_uint_base a( *this );
01060     return a.to_string( numrep );
01061 }
01062 
01063 inline
01064 const std::string
01065 sc_uint_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
01066 {
01067     sc_uint_base a( *this );
01068     return a.to_string( numrep, w_prefix );
01069 }
01070 
01071 
01072 // functional notation for the reduce methods
01073 
01074 inline
01075 bool
01076 and_reduce( const sc_uint_subref_r& a )
01077 {
01078     return a.and_reduce();
01079 }
01080 
01081 inline
01082 bool
01083 nand_reduce( const sc_uint_subref_r& a )
01084 {
01085     return a.nand_reduce();
01086 }
01087 
01088 inline
01089 bool
01090 or_reduce( const sc_uint_subref_r& a )
01091 {
01092     return a.or_reduce();
01093 }
01094 
01095 inline
01096 bool
01097 nor_reduce( const sc_uint_subref_r& a )
01098 {
01099     return a.nor_reduce();
01100 }
01101 
01102 inline
01103 bool
01104 xor_reduce( const sc_uint_subref_r& a )
01105 {
01106     return a.xor_reduce();
01107 }
01108 
01109 inline
01110 bool
01111 xnor_reduce( const sc_uint_subref_r& a )
01112 {
01113     return a.xnor_reduce();
01114 }
01115 
01116 
01117 
01118 inline
01119 ::std::ostream&
01120 operator << ( ::std::ostream& os, const sc_uint_subref_r& a )
01121 {
01122     a.print( os );
01123     return os;
01124 }
01125 
01126 
01127 // ----------------------------------------------------------------------------
01128 //  CLASS : sc_uint_subref
01129 //
01130 //  Proxy class for sc_uint part selection (r-value and l-value).
01131 // ----------------------------------------------------------------------------
01132 
01133 // assignment operators
01134 
01135 inline
01136 sc_uint_subref&
01137 sc_uint_subref::operator = ( const sc_uint_base& a )
01138 {
01139     return operator = ( a.operator uint_type() );
01140 }
01141 
01142 inline
01143 sc_uint_subref&
01144 sc_uint_subref::operator = ( const char* a )
01145 {
01146     sc_uint_base aa( length() );
01147     return ( *this = aa = a );
01148 }
01149 
01150 
01151 
01152 inline
01153 ::std::istream&
01154 operator >> ( ::std::istream& is, sc_uint_subref& a )
01155 {
01156     a.scan( is );
01157     return is;
01158 }
01159 
01160 
01161 // ----------------------------------------------------------------------------
01162 //  CLASS : sc_uint_base
01163 //
01164 //  Base class for sc_uint.
01165 // ----------------------------------------------------------------------------
01166 
01167 // bit selection
01168 
01169 inline
01170 sc_uint_bitref&
01171 sc_uint_base::operator [] ( int i )
01172 {
01173     check_index( i );
01174     sc_uint_bitref* result_p = sc_uint_bitref::m_pool.allocate();
01175     result_p->initialize(this, i);
01176     return *result_p;
01177 }
01178 
01179 inline
01180 const sc_uint_bitref_r&
01181 sc_uint_base::operator [] ( int i ) const
01182 {
01183     check_index( i );
01184     sc_uint_bitref* result_p = sc_uint_bitref::m_pool.allocate();
01185     result_p->initialize(this, i);
01186     return *result_p;
01187 }
01188 
01189 
01190 inline
01191 sc_uint_bitref&
01192 sc_uint_base::bit( int i )
01193 {
01194     check_index( i );
01195     sc_uint_bitref* result_p = sc_uint_bitref::m_pool.allocate();
01196     result_p->initialize(this, i);
01197     return *result_p;
01198 }
01199 
01200 inline
01201 const sc_uint_bitref_r&
01202 sc_uint_base::bit( int i ) const
01203 {
01204     check_index( i );
01205     sc_uint_bitref* result_p = sc_uint_bitref::m_pool.allocate();
01206     result_p->initialize(this, i);
01207     return *result_p;
01208 }
01209 
01210 
01211 // part selection
01212 
01213 inline
01214 sc_uint_subref&
01215 sc_uint_base::operator () ( int left, int right )
01216 {
01217     check_range( left, right );
01218     sc_uint_subref* result_p = sc_uint_subref::m_pool.allocate();
01219     result_p->initialize(this, left, right);
01220     return *result_p;
01221 }
01222 
01223 inline
01224 const sc_uint_subref_r&
01225 sc_uint_base::operator () ( int left, int right ) const
01226 {
01227     check_range( left, right );
01228     sc_uint_subref* result_p = sc_uint_subref::m_pool.allocate();
01229     result_p->initialize(this, left, right);
01230     return *result_p;
01231 }
01232 
01233 
01234 inline
01235 sc_uint_subref&
01236 sc_uint_base::range( int left, int right )
01237 {
01238     check_range( left, right );
01239     sc_uint_subref* result_p = sc_uint_subref::m_pool.allocate();
01240     result_p->initialize(this, left, right);
01241     return *result_p;
01242 }
01243 
01244 inline
01245 const sc_uint_subref_r&
01246 sc_uint_base::range( int left, int right ) const
01247 {
01248     check_range( left, right );
01249     sc_uint_subref* result_p = sc_uint_subref::m_pool.allocate();
01250     result_p->initialize(this, left, right);
01251     return *result_p;
01252 }
01253 
01254 
01255 // functional notation for the reduce methods
01256 
01257 inline
01258 bool
01259 and_reduce( const sc_uint_base& a )
01260 {
01261     return a.and_reduce();
01262 }
01263 
01264 inline
01265 bool
01266 nand_reduce( const sc_uint_base& a )
01267 {
01268     return a.nand_reduce();
01269 }
01270 
01271 inline
01272 bool
01273 or_reduce( const sc_uint_base& a )
01274 {
01275     return a.or_reduce();
01276 }
01277 
01278 inline
01279 bool
01280 nor_reduce( const sc_uint_base& a )
01281 {
01282     return a.nor_reduce();
01283 }
01284 
01285 inline
01286 bool
01287 xor_reduce( const sc_uint_base& a )
01288 {
01289     return a.xor_reduce();
01290 }
01291 
01292 inline
01293 bool
01294 xnor_reduce( const sc_uint_base& a )
01295 {
01296     return a.xnor_reduce();
01297 }
01298 
01299 
01300 
01301 inline
01302 ::std::ostream&
01303 operator << ( ::std::ostream& os, const sc_uint_base& a )
01304 {
01305     a.print( os );
01306     return os;
01307 }
01308 
01309 inline
01310 ::std::istream&
01311 operator >> ( ::std::istream& is, sc_uint_base& a )
01312 {
01313     a.scan( is );
01314     return is;
01315 }
01316 
01317 } // namespace sc_dt
01318 
01319 
01320 #endif
01321 
01322 // Taf!

Generated on Wed Apr 25 13:53:27 2007 for SystemC by  doxygen 1.5.1