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