Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

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

Generated on Fri Jan 14 08:29:03 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18