SystemC  Recoding Infrastructure for SystemC v0.6.3 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_int_base.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_int_base.h -- A sc_int is a signed integer whose length is less than the
21  machine's native integer length. We provide two implementations
22  (i) sc_int with length between 1 - 64, and (ii) sc_int with
23  length between 1 - 32. Implementation (i) is the default
24  implementation, while implementation (ii) can be used only if
25  the class library is compiled with -D_32BIT_. Unlike arbitrary
26  precision, arithmetic and bitwise operations are performed
27  using the native types (hence capped at 32/64 bits). The sc_int
28  integer is useful when the user does not need arbitrary
29  precision and the performance is superior to
30  sc_bigint/sc_biguint.
31 
32  Original Author: Amit Rao, Synopsys, Inc.
33 
34  *****************************************************************************/
35 
36 /*****************************************************************************
37 
38  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
39  changes you are making here.
40 
41  Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
42  Description of Modification: - Resolved ambiguity with sc_(un)signed.
43  - Merged the code for 64- and 32-bit versions
44  via the constants in sc_nbdefs.h.
45  - Eliminated redundant file inclusions.
46 
47  Name, Affiliation, Date:
48  Description of Modification:
49 
50  *****************************************************************************/
51 
52 // $Log: sc_int_base.h,v $
53 // Revision 1.3 2011/08/24 22:05:45 acg
54 // Torsten Maehne: initialization changes to remove warnings.
55 //
56 // Revision 1.2 2011/02/18 20:19:15 acg
57 // Andy Goodrich: updating Copyright notice.
58 //
59 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
60 // SystemC 2.3
61 //
62 // Revision 1.4 2006/05/08 17:50:01 acg
63 // Andy Goodrich: Added David Long's declarations for friend operators,
64 // functions, and methods, to keep the Microsoft compiler happy.
65 //
66 // Revision 1.3 2006/01/13 18:49:31 acg
67 // Added $Log command so that CVS check in comments are reproduced in the
68 // source.
69 //
70 
71 #ifndef SC_INT_BASE_H
72 #define SC_INT_BASE_H
73 
74 #include "sysc/kernel/sc_object.h"
80 #include "sysc/utils/sc_iostream.h"
82 
83 
84 namespace sc_dt
85 {
86 
87 class sc_concatref;
88 
89 // classes defined in this module
90 class sc_int_bitref_r;
91 class sc_int_bitref;
92 class sc_int_subref_r;
93 class sc_int_subref;
94 class sc_int_base;
95 class sc_signed_subref_r;
96 class sc_unsigned_subref_r;
97 
98 // forward class declarations
99 class sc_bv_base;
100 class sc_lv_base;
101 class sc_signed;
102 class sc_unsigned;
103 class sc_fxval;
104 class sc_fxval_fast;
105 class sc_fxnum;
106 class sc_fxnum_fast;
107 
108 
110 
111 // friend operator declarations
112  // relational operators
113 
114  inline bool operator == ( const sc_int_base& a, const sc_int_base& b );
115 
116  inline bool operator != ( const sc_int_base& a, const sc_int_base& b );
117 
118  inline bool operator < ( const sc_int_base& a, const sc_int_base& b );
119 
120  inline bool operator <= ( const sc_int_base& a, const sc_int_base& b );
121 
122  inline bool operator > ( const sc_int_base& a, const sc_int_base& b );
123 
124  inline bool operator >= ( const sc_int_base& a, const sc_int_base& b );
125 
126 
127 // ----------------------------------------------------------------------------
128 // CLASS : sc_int_bitref_r
129 //
130 // Proxy class for sc_int bit selection (r-value only).
131 // ----------------------------------------------------------------------------
132 
134 {
135  friend class sc_int_base;
136 
137 protected:
138 
139  // constructor
140 
142  {}
143 
144  // initializer for sc_core::sc_vpool:
145 
146  void initialize( const sc_int_base* obj_p, int index_ )
147  {
148  m_obj_p = (sc_int_base*)obj_p;
149  m_index = index_;
150  }
151 
152 public:
153 
154  // copy constructor
155 
158  {}
159 
160  // destructor
161 
163  {}
164 
165  // capacity
166 
167  int length() const
168  { return 1; }
169 
170 #ifdef SC_DT_DEPRECATED
171  int bitwidth() const
172  { return length(); }
173 #endif
174 
175  // concatenation support
176 
177  virtual int concat_length( bool *xz_present_p ) const
178  { if (xz_present_p) *xz_present_p = false; return 1; }
179  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const
180  {
181  int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
182  int word_i = low_i / BITS_PER_DIGIT;
183 
184  dst_p[word_i] &= ~bit_mask;
185  return false;
186  }
187  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const
188  {
189  bool non_zero;
190  int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
191  int word_i = low_i / BITS_PER_DIGIT;
192 
193  if ( operator uint64() )
194  {
195  dst_p[word_i] |= bit_mask;
196  non_zero = true;
197  }
198  else
199  {
200  dst_p[word_i] &= ~bit_mask;
201  non_zero = false;
202  }
203  return non_zero;
204  }
205  virtual uint64 concat_get_uint64() const
206  { return operator uint64(); }
207 
208 
209 
210 
211  // implicit conversions
212 
213  operator uint64 () const;
214  bool operator ! () const;
215  bool operator ~ () const;
216 
217 
218  // explicit conversions
219 
220  uint64 value() const
221  { return operator uint64(); }
222 
223  bool to_bool() const
224  { return operator uint64(); }
225 
226 
227  // other methods
228 
229  void print( ::std::ostream& os = ::std::cout ) const
230  { os << to_bool(); }
231 
232 protected:
233  int m_index;
235 
236 private:
237 
238  // disabled
239  sc_int_bitref_r& operator = ( const sc_int_bitref_r& );
240 };
241 
242 
243 inline
244 ::std::ostream&
245 operator << ( ::std::ostream&, const sc_int_bitref_r& );
246 
247 
248 // ----------------------------------------------------------------------------
249 // CLASS : sc_int_bitref
250 //
251 // Proxy class for sc_int bit selection (r-value and l-value).
252 // ----------------------------------------------------------------------------
253 
255  : public sc_int_bitref_r
256 {
257  friend class sc_int_base;
259 
260 
261  // constructor
262 
264  {}
265 
266 
267 public:
268 
269  // copy constructor
270 
272  {}
273 
274  // assignment operators
275 
278  sc_int_bitref& operator = ( bool b );
279 
280  sc_int_bitref& operator &= ( bool b );
281  sc_int_bitref& operator |= ( bool b );
282  sc_int_bitref& operator ^= ( bool b );
283 
284  // concatenation methods
285 
286  virtual void concat_set(int64 src, int low_i);
287  virtual void concat_set(const sc_signed& src, int low_i);
288  virtual void concat_set(const sc_unsigned& src, int low_i);
289  virtual void concat_set(uint64 src, int low_i);
290 
291 
292  // other methods
293 
294  void scan( ::std::istream& is = ::std::cin );
295 
296 public:
298 
299 };
300 
301 
302 
303 inline
304 ::std::istream&
305 operator >> ( ::std::istream&, sc_int_bitref& );
306 
307 
308 // ----------------------------------------------------------------------------
309 // CLASS : sc_int_subref_r
310 //
311 // Proxy class for sc_int part selection (r-value only).
312 // ----------------------------------------------------------------------------
313 
315 {
316  friend class sc_int_base;
317  friend class sc_int_signal;
318  friend class sc_int_subref;
319 
320 protected:
321 
322  // constructor
323 
325  {}
326 
327  // initializer for sc_core::sc_vpool:
328 
329  void initialize( const sc_int_base* obj_p, int left_i, int right_i )
330  {
331  m_obj_p = (sc_int_base*)obj_p;
332  m_left = left_i;
333  m_right = right_i;
334  }
335 
336 
337 public:
338  // copy constructor
339 
341  sc_value_base(a), m_left( a.m_left ), m_obj_p( a.m_obj_p ),
342  m_right( a.m_right )
343  {}
344 
345  // destructor
346 
348  {}
349 
350  // capacity
351 
352  int length() const
353  { return ( m_left - m_right + 1 ); }
354 
355 #ifdef SC_DT_DEPRECATED
356  int bitwidth() const
357  { return length(); }
358 #endif
359 
360  // concatenation support
361 
362  virtual int concat_length(bool* xz_present_p) const
363  { if ( xz_present_p ) *xz_present_p = false; return length(); }
364  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
365  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
366  virtual uint64 concat_get_uint64() const
367  {
368  int len = length();
369  uint64 val = operator uint_type();
370  if ( len < 64 )
371  return (uint64)(val & ~((uint_type)-1 << len));
372  else
373  return (uint64)val;
374  }
375 
376  // reduce methods
377 
378  bool and_reduce() const;
379 
380  bool nand_reduce() const
381  { return ( ! and_reduce() ); }
382 
383  bool or_reduce() const;
384 
385  bool nor_reduce() const
386  { return ( ! or_reduce() ); }
387 
388  bool xor_reduce() const;
389 
390  bool xnor_reduce() const
391  { return ( ! xor_reduce() ); }
392 
393 
394  // implicit conversion to uint_type
395 
396  operator uint_type () const;
397 
398 
399  // explicit conversions
400 
401  uint_type value() const
402  { return operator uint_type(); }
403 
404 
405  int to_int() const;
406  unsigned int to_uint() const;
407  long to_long() const;
408  unsigned long to_ulong() const;
409  int64 to_int64() const;
410  uint64 to_uint64() const;
411  double to_double() const;
412 
413 
414  // explicit conversion to character string
415 
416  const std::string to_string( sc_numrep numrep = SC_DEC ) const;
417  const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
418 
419 
420  // other methods
421 
422  void print( ::std::ostream& os = ::std::cout ) const
423  { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
424 
425 protected:
426 
427  int m_left;
429  int m_right;
430 
431 private:
432  const sc_int_subref_r& operator = ( const sc_int_subref_r& );
433 };
434 
435 
436 
437 inline
438 ::std::ostream&
439 operator << ( ::std::ostream&, const sc_int_subref_r& );
440 
441 
442 // ----------------------------------------------------------------------------
443 // CLASS : sc_int_subref
444 //
445 // Proxy class for sc_int part selection (r-value and l-value).
446 // ----------------------------------------------------------------------------
447 
449  : public sc_int_subref_r
450 {
451  friend class sc_int_base;
453 
454 
455 protected:
456 
457  // constructor
459  {}
460 
461 public:
462 
463  // copy constructor
464 
466  {}
467 
468  // assignment operators
469 
472 
474  { return operator = ( a.operator uint_type() ); }
475 
477  { return operator = ( a.operator uint_type() ); }
478 
479  template< class T >
481  { return operator = ( a->to_int64() ); }
482 
483  sc_int_subref& operator = ( const char* a );
484 
485  sc_int_subref& operator = ( unsigned long a )
486  { return operator = ( (int_type) a ); }
487 
489  { return operator = ( (int_type) a ); }
490 
491  sc_int_subref& operator = ( unsigned int a )
492  { return operator = ( (int_type) a ); }
493 
495  { return operator = ( (int_type) a ); }
496 
498  { return operator = ( (int_type) a ); }
499 
501  { return operator = ( (int_type) a ); }
502 
507 
508  // concatenation methods
509 
510  virtual void concat_set(int64 src, int low_i);
511  virtual void concat_set(const sc_signed& src, int low_i);
512  virtual void concat_set(const sc_unsigned& src, int low_i);
513  virtual void concat_set(uint64 src, int low_i);
514 
515  // other methods
516 
517  void scan( ::std::istream& is = ::std::cin );
518 
519 public:
521 
522 };
523 
524 
525 
526 inline
527 ::std::istream&
528 operator >> ( ::std::istream&, sc_int_subref& );
529 
530 
531 // ----------------------------------------------------------------------------
532 // CLASS : sc_int_base
533 //
534 // Base class for sc_int.
535 // ----------------------------------------------------------------------------
536 
538 {
539  friend class sc_int_bitref_r;
540  friend class sc_int_bitref;
541  friend class sc_int_subref_r;
542  friend class sc_int_subref;
543 
544 
545  // support methods
546 
547  void invalid_length() const;
548  void invalid_index( int i ) const;
549  void invalid_range( int l, int r ) const;
550 
551  void check_length() const
552  { if( m_len <= 0 || m_len > SC_INTWIDTH ) { invalid_length(); } }
553 
554  void check_index( int i ) const
555  { if( i < 0 || i >= m_len ) { invalid_index( i ); } }
556 
557  void check_range( int l, int r ) const
558  { if( r < 0 || l >= m_len || l < r ) { invalid_range( l, r ); } }
559 
560  void check_value() const;
561 
562  void extend_sign()
563  {
564 #ifdef DEBUG_SYSTEMC
565  check_value();
566 #endif
567  m_val = ( m_val << m_ulen >> m_ulen );
568  }
569 
570 public:
571 
572  // constructors
573 
574  explicit sc_int_base( int w = sc_length_param().len() )
575  : m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
576  { check_length(); }
577 
578  sc_int_base( int_type v, int w )
579  : m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
580  { check_length(); extend_sign(); }
581 
583  : sc_value_base(a), m_val( a.m_val ), m_len( a.m_len ),
584  m_ulen( a.m_ulen )
585  {}
586 
587  explicit sc_int_base( const sc_int_subref_r& a )
588  : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )
589  { extend_sign(); }
590 
591  template< class T >
592  explicit sc_int_base( const sc_generic_base<T>& a ) :
593  m_val( a->to_int64() ), m_len( a->length() ),
595  { check_length(); extend_sign(); }
596 
597  explicit sc_int_base( const sc_signed& a );
598  explicit sc_int_base( const sc_unsigned& a );
599  explicit sc_int_base( const sc_bv_base& v );
600  explicit sc_int_base( const sc_lv_base& v );
601  explicit sc_int_base( const sc_uint_subref_r& v );
602  explicit sc_int_base( const sc_signed_subref_r& v );
603  explicit sc_int_base( const sc_unsigned_subref_r& v );
604 
605 
606 
607  // destructor
608 
609  virtual ~sc_int_base()
610  {}
611 
612  // assignment operators
613 
615  { m_val = v; extend_sign(); return *this; }
616 
618  { m_val = a.m_val; extend_sign(); return *this; }
619 
621  { m_val = a; extend_sign(); return *this; }
622 
623  template<class T>
625  { m_val = a->to_int64(); extend_sign(); return *this; }
626 
627  sc_int_base& operator = ( const sc_signed& a );
628  sc_int_base& operator = ( const sc_unsigned& a );
629 
630 #ifdef SC_INCLUDE_FX
631  sc_int_base& operator = ( const sc_fxval& a );
633  sc_int_base& operator = ( const sc_fxnum& a );
635 #endif
636 
637  sc_int_base& operator = ( const sc_bv_base& a );
638  sc_int_base& operator = ( const sc_lv_base& a );
639 
640  sc_int_base& operator = ( const char* a );
641 
642  sc_int_base& operator = ( unsigned long a )
643  { m_val = a; extend_sign(); return *this; }
644 
646  { m_val = a; extend_sign(); return *this; }
647 
648  sc_int_base& operator = ( unsigned int a )
649  { m_val = a; extend_sign(); return *this; }
650 
652  { m_val = a; extend_sign(); return *this; }
653 
655  { m_val = a; extend_sign(); return *this; }
656 
658  { m_val = (int_type) a; extend_sign(); return *this; }
659 
660 
661  // arithmetic assignment operators
662 
664  { m_val += v; extend_sign(); return *this; }
665 
667  { m_val -= v; extend_sign(); return *this; }
668 
670  { m_val *= v; extend_sign(); return *this; }
671 
673  { m_val /= v; extend_sign(); return *this; }
674 
676  { m_val %= v; extend_sign(); return *this; }
677 
678 
679  // bitwise assignment operators
680 
682  { m_val &= v; extend_sign(); return *this; }
683 
685  { m_val |= v; extend_sign(); return *this; }
686 
688  { m_val ^= v; extend_sign(); return *this; }
689 
690 
692  { m_val <<= v; extend_sign(); return *this; }
693 
695  { m_val >>= v; /* no sign extension needed */ return *this; }
696 
697 
698  // prefix and postfix increment and decrement operators
699 
701  { ++ m_val; extend_sign(); return *this; }
702 
703  const sc_int_base operator ++ ( int ) // postfix
704  { sc_int_base tmp( *this ); ++ m_val; extend_sign(); return tmp; }
705 
707  { -- m_val; extend_sign(); return *this; }
708 
709  const sc_int_base operator -- ( int ) // postfix
710  { sc_int_base tmp( *this ); -- m_val; extend_sign(); return tmp; }
711 
712 
713  // relational operators
714 
715  friend bool operator == ( const sc_int_base& a, const sc_int_base& b )
716  { return a.m_val == b.m_val; }
717 
718  friend bool operator != ( const sc_int_base& a, const sc_int_base& b )
719  { return a.m_val != b.m_val; }
720 
721  friend bool operator < ( const sc_int_base& a, const sc_int_base& b )
722  { return a.m_val < b.m_val; }
723 
724  friend bool operator <= ( const sc_int_base& a, const sc_int_base& b )
725  { return a.m_val <= b.m_val; }
726 
727  friend bool operator > ( const sc_int_base& a, const sc_int_base& b )
728  { return a.m_val > b.m_val; }
729 
730  friend bool operator >= ( const sc_int_base& a, const sc_int_base& b )
731  { return a.m_val >= b.m_val; }
732 
733 
734  // bit selection
735 
736  sc_int_bitref& operator [] ( int i );
737  const sc_int_bitref_r& operator [] ( int i ) const;
738 
739  sc_int_bitref& bit( int i );
740  const sc_int_bitref_r& bit( int i ) const;
741 
742 
743  // part selection
744 
745  sc_int_subref& operator () ( int left, int right );
746  const sc_int_subref_r& operator () ( int left, int right ) const;
747 
748  sc_int_subref& range( int left, int right );
749  const sc_int_subref_r& range( int left, int right ) const;
750 
751 
752  // bit access, without bounds checking or sign extension
753 
754  bool test( int i ) const
755  { return ( 0 != (m_val & (UINT_ONE << i)) ); }
756 
757  void set( int i )
758  { m_val |= (UINT_ONE << i); }
759 
760  void set( int i, bool v )
761  { v ? m_val |= (UINT_ONE << i) : m_val &= ~(UINT_ONE << i); }
762 
763 
764  // capacity
765 
766  int length() const
767  { return m_len; }
768 
769 #ifdef SC_DT_DEPRECATED
770  int bitwidth() const
771  { return length(); }
772 #endif
773 
774  // concatenation support
775 
776  virtual int concat_length(bool* xz_present_p) const
777  { if ( xz_present_p ) *xz_present_p = false; return length(); }
778  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
779  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
780  virtual uint64 concat_get_uint64() const
781  {
782  if ( m_len < 64 )
783  return (uint64)(m_val & ~((uint_type)-1 << m_len));
784  else
785  return (uint64)m_val;
786  }
787  virtual void concat_set(int64 src, int low_i);
788  virtual void concat_set(const sc_signed& src, int low_i);
789  virtual void concat_set(const sc_unsigned& src, int low_i);
790  virtual void concat_set(uint64 src, int low_i);
791 
792 
793  // reduce methods
794 
795  bool and_reduce() const;
796 
797  bool nand_reduce() const
798  { return ( ! and_reduce() ); }
799 
800  bool or_reduce() const;
801 
802  bool nor_reduce() const
803  { return ( ! or_reduce() ); }
804 
805  bool xor_reduce() const;
806 
807  bool xnor_reduce() const
808  { return ( ! xor_reduce() ); }
809 
810 
811  // implicit conversion to int_type
812 
813  operator int_type() const
814  { return m_val; }
815 
816 
817  // explicit conversions
818 
819  int_type value() const
820  { return operator int_type(); }
821 
822 
823  int to_int() const
824  { return (int) m_val; }
825 
826  unsigned int to_uint() const
827  { return (unsigned int) m_val; }
828 
829  long to_long() const
830  { return (long) m_val; }
831 
832  unsigned long to_ulong() const
833  { return (unsigned long) m_val; }
834 
835  int64 to_int64() const
836  { return (int64) m_val; }
837 
839  { return (uint64) m_val; }
840 
841  double to_double() const
842  { return (double) m_val; }
843 
844 
845 #ifndef _32BIT_
846  long long_low() const
847  { return (long) (m_val & UINT64_32ONES); }
848 
849  long long_high() const
850  { return (long) ((m_val >> 32) & UINT64_32ONES); }
851 #endif
852 
853 
854  // explicit conversion to character string
855 
856  const std::string to_string( sc_numrep numrep = SC_DEC ) const;
857  const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
858 
859 
860  // other methods
861 
862  void print( ::std::ostream& os = ::std::cout ) const
863  { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
864 
865  void scan( ::std::istream& is = ::std::cin );
866 
867 protected:
868 
869  int_type m_val; // value
870  int m_len; // length
871  int m_ulen; // unused length
872 };
873 
874 
875 
876 inline
877 ::std::ostream&
878 operator << ( ::std::ostream&, const sc_int_base& );
879 
880 inline
881 ::std::istream&
882 operator >> ( ::std::istream&, sc_int_base& );
883 
884 
885 
886 // ----------------------------------------------------------------------------
887 // CLASS : sc_int_bitref_r
888 //
889 // Proxy class for sc_int bit selection (r-value only).
890 // ----------------------------------------------------------------------------
891 
892 // implicit conversion to uint64
893 
894 inline
895 sc_int_bitref_r::operator uint64 () const
896 {
897  return m_obj_p->test( m_index );
898 }
899 
900 inline
901 bool
903 {
904  return ! m_obj_p->test( m_index );
905 }
906 
907 inline
908 bool
910 {
911  return ! m_obj_p->test( m_index );
912 }
913 
914 
915 
916 inline
917 ::std::ostream&
918 operator << ( ::std::ostream& os, const sc_int_bitref_r& a )
919 {
920  a.print( os );
921  return os;
922 }
923 
924 
925 // ----------------------------------------------------------------------------
926 // CLASS : sc_int_bitref
927 //
928 // Proxy class for sc_int bit selection (r-value and l-value).
929 // ----------------------------------------------------------------------------
930 
931 // assignment operators
932 
933 inline
934 sc_int_bitref&
936 {
937  m_obj_p->set( m_index, (bool) b );
938  m_obj_p->extend_sign();
939  return *this;
940 }
941 
942 inline
945 {
946  m_obj_p->set( m_index, (bool) b );
947  m_obj_p->extend_sign();
948  return *this;
949 }
950 
951 inline
954 {
955  m_obj_p->set( m_index, b );
956  m_obj_p->extend_sign();
957  return *this;
958 }
959 
960 
961 inline
964 {
965  if( ! b ) {
966  m_obj_p->set( m_index, b );
967  m_obj_p->extend_sign();
968  }
969  return *this;
970 }
971 
972 inline
975 {
976  if( b ) {
977  m_obj_p->set( m_index, b );
978  m_obj_p->extend_sign();
979  }
980  return *this;
981 }
982 
983 inline
986 {
987  if( b ) {
988  m_obj_p->m_val ^= (UINT_ONE << m_index);
989  m_obj_p->extend_sign();
990  }
991  return *this;
992 }
993 
994 
995 
996 inline
997 ::std::istream&
998 operator >> ( ::std::istream& is, sc_int_bitref& a )
999 {
1000  a.scan( is );
1001  return is;
1002 }
1003 
1004 
1005 // ----------------------------------------------------------------------------
1006 // CLASS : sc_int_subref_r
1007 //
1008 // Proxy class for sc_int part selection (r-value only).
1009 // ----------------------------------------------------------------------------
1010 
1011 // implicit conversion to int_type
1012 
1013 inline
1014 sc_int_subref_r::operator uint_type() const
1015 {
1016  uint_type /*int_type*/ val = m_obj_p->m_val;
1017  int uleft = SC_INTWIDTH - (m_left + 1);
1018  int uright = uleft + m_right;
1019  return ( val << uleft >> uright );
1020 }
1021 
1022 
1023 // reduce methods
1024 
1025 inline
1026 bool
1028 {
1029  sc_int_base a( *this );
1030  return a.and_reduce();
1031 }
1032 
1033 inline
1034 bool
1036 {
1037  sc_int_base a( *this );
1038  return a.or_reduce();
1039 }
1040 
1041 inline
1042 bool
1044 {
1045  sc_int_base a( *this );
1046  return a.xor_reduce();
1047 }
1048 
1049 
1050 // explicit conversions
1051 
1052 inline
1053 int
1055 {
1056  int result = static_cast<int>(operator uint_type());
1057  return result;
1058 }
1059 
1060 inline
1061 unsigned int
1063 {
1064  unsigned int result = static_cast<unsigned int>(operator uint_type());
1065  return result;
1066 }
1067 
1068 inline
1069 long
1071 {
1072  long result = static_cast<long>(operator uint_type());
1073  return result;
1074 }
1075 
1076 inline
1077 unsigned long
1079 {
1080  unsigned long result = static_cast<unsigned long>(operator uint_type());
1081  return result;
1082 }
1083 
1084 inline
1085 int64
1087 {
1088  int64 result = operator uint_type();
1089  return result;
1090 }
1091 
1092 inline
1093 uint64
1095 {
1096  uint64 result = operator uint_type();
1097  return result;
1098 }
1099 
1100 inline
1101 double
1103 {
1104  double result = static_cast<double>(operator uint_type());
1105  return result;
1106 }
1107 
1108 
1109 // explicit conversion to character string
1110 
1111 inline
1112 const std::string
1114 {
1115  sc_uint_base a(length());
1116  a = operator uint_type();
1117  return a.to_string( numrep );
1118 }
1119 
1120 inline
1121 const std::string
1122 sc_int_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
1123 {
1124  sc_uint_base a(length());
1125  a = operator uint_type();
1126  return a.to_string( numrep, w_prefix );
1127 }
1128 
1129 
1130 // functional notation for the reduce methods
1131 
1132 inline
1133 bool
1135 {
1136  return a.and_reduce();
1137 }
1138 
1139 inline
1140 bool
1142 {
1143  return a.nand_reduce();
1144 }
1145 
1146 inline
1147 bool
1149 {
1150  return a.or_reduce();
1151 }
1152 
1153 inline
1154 bool
1156 {
1157  return a.nor_reduce();
1158 }
1159 
1160 inline
1161 bool
1163 {
1164  return a.xor_reduce();
1165 }
1166 
1167 inline
1168 bool
1170 {
1171  return a.xnor_reduce();
1172 }
1173 
1174 
1175 
1176 inline
1177 ::std::ostream&
1178 operator << ( ::std::ostream& os, const sc_int_subref_r& a )
1179 {
1180  a.print( os );
1181  return os;
1182 }
1183 
1184 
1185 // ----------------------------------------------------------------------------
1186 // CLASS : sc_int_subref
1187 //
1188 // Proxy class for sc_int part selection (r-value and l-value).
1189 // ----------------------------------------------------------------------------
1190 
1191 // assignment operators
1192 
1193 inline
1194 sc_int_subref&
1196 {
1197  return operator = ( a.operator int_type() );
1198 }
1199 
1200 inline
1203 {
1204  sc_int_base aa( length() );
1205  return ( *this = aa = a );
1206 }
1207 
1208 
1209 
1210 inline
1211 ::std::istream&
1212 operator >> ( ::std::istream& is, sc_int_subref& a )
1213 {
1214  a.scan( is );
1215  return is;
1216 }
1217 
1218 
1219 // ----------------------------------------------------------------------------
1220 // CLASS : sc_int_base
1221 //
1222 // Base class for sc_int.
1223 // ----------------------------------------------------------------------------
1224 
1225 // bit selection
1226 
1227 inline
1228 sc_int_bitref&
1230 {
1231  check_index( i );
1232  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1233  result_p->initialize(this, i);
1234  return *result_p;
1235 }
1236 
1237 inline
1238 const sc_int_bitref_r&
1240 {
1241  check_index( i );
1242  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1243  result_p->initialize(this, i);
1244  return *result_p;
1245 }
1246 
1247 
1248 inline
1251 {
1252  check_index( i );
1253  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1254  result_p->initialize(this, i);
1255  return *result_p;
1256 }
1257 
1258 inline
1259 const sc_int_bitref_r&
1260 sc_int_base::bit( int i ) const
1261 {
1262  check_index( i );
1263  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1264  result_p->initialize(this, i);
1265  return *result_p;
1266 }
1267 
1268 
1269 // part selection
1270 
1271 inline
1273 sc_int_base::operator () ( int left, int right )
1274 {
1275  check_range( left, right );
1276  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1277  result_p->initialize(this, left, right);
1278  return *result_p;
1279 }
1280 
1281 inline
1282 const sc_int_subref_r&
1283 sc_int_base::operator () ( int left, int right ) const
1284 {
1285  check_range( left, right );
1286  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1287  result_p->initialize(this, left, right);
1288  return *result_p;
1289 }
1290 
1291 
1292 inline
1294 sc_int_base::range( int left, int right )
1295 {
1296  check_range( left, right );
1297  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1298  result_p->initialize(this, left, right);
1299  return *result_p;
1300 }
1301 
1302 inline
1303 const sc_int_subref_r&
1304 sc_int_base::range( int left, int right ) const
1305 {
1306  check_range( left, right );
1307  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1308  result_p->initialize(this, left, right);
1309  return *result_p;
1310 }
1311 
1312 
1313 // functional notation for the reduce methods
1314 
1315 inline
1316 bool
1318 {
1319  return a.and_reduce();
1320 }
1321 
1322 inline
1323 bool
1325 {
1326  return a.nand_reduce();
1327 }
1328 
1329 inline
1330 bool
1332 {
1333  return a.or_reduce();
1334 }
1335 
1336 inline
1337 bool
1339 {
1340  return a.nor_reduce();
1341 }
1342 
1343 inline
1344 bool
1346 {
1347  return a.xor_reduce();
1348 }
1349 
1350 inline
1351 bool
1353 {
1354  return a.xnor_reduce();
1355 }
1356 
1357 
1358 
1359 inline
1360 ::std::ostream&
1361 operator << ( ::std::ostream& os, const sc_int_base& a )
1362 {
1363  a.print( os );
1364  return os;
1365 }
1366 
1367 inline
1368 ::std::istream&
1369 operator >> ( ::std::istream& is, sc_int_base& a )
1370 {
1371  a.scan( is );
1372  return is;
1373 }
1374 
1375 } // namespace sc_dt
1376 
1377 
1378 #endif
1379 
1380 // Taf!
unsigned long to_ulong() const
Definition: sc_int_base.h:832
sc_int_base(const sc_int_subref_r &a)
Definition: sc_int_base.h:587
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:780
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:366
void set(int i, bool v)
Definition: sc_int_base.h:760
sc_int_base & operator--()
Definition: sc_int_base.h:706
unsigned long to_ulong() const
Definition: sc_int_base.h:1078
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
friend bool operator>=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:730
unsigned int to_uint() const
Definition: sc_int_base.h:1062
void scan(::std::istream &is=::std::cin)
int64 to_int64() const
Definition: sc_int_base.h:1086
sc_int_base(int w=sc_length_param().len())
Definition: sc_int_base.h:574
bool xnor_reduce() const
Definition: sc_int_base.h:390
bool and_reduce() const
Definition: sc_int_base.h:1027
void scan(::std::istream &is=::std::cin)
uint64 uint_type
Definition: sc_nbdefs.h:234
bool to_bool() const
Definition: sc_int_base.h:223
sc_numrep
Definition: sc_nbdefs.h:91
int64_t int64
Definition: sc_nbdefs.h:182
bool operator<(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:721
sc_logic_value_t nand_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1546
friend bool operator<=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:724
sc_int_base & operator+=(int_type v)
Definition: sc_int_base.h:663
sc_int_subref & operator()(int left, int right)
Definition: sc_int_base.h:1273
sc_int_base & operator++()
Definition: sc_int_base.h:700
sc_int_bitref & operator&=(bool b)
Definition: sc_int_base.h:963
long to_long() const
Definition: sc_int_base.h:829
sc_int_base * m_obj_p
Definition: sc_int_base.h:234
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:422
friend bool operator==(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:715
friend class sc_int_signal
Definition: sc_int_base.h:317
sc_int_bitref & operator^=(bool b)
Definition: sc_int_base.h:985
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:229
sc_logic_value_t xor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1570
friend bool operator>(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:727
virtual ~sc_int_bitref_r()
Definition: sc_int_base.h:162
void set(int i)
Definition: sc_int_base.h:757
bool sc_io_show_base(systemc_ostream &)
Definition: sc_nbutils.h:112
unsigned int to_uint() const
Definition: sc_int_base.h:826
long long_low() const
Definition: sc_int_base.h:846
sc_int_base & operator>>=(int_type v)
Definition: sc_int_base.h:694
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:362
sc_int_subref(const sc_int_subref &a)
Definition: sc_int_base.h:465
sc_int_base & operator*=(int_type v)
Definition: sc_int_base.h:669
virtual void concat_set(int64 src, int low_i)
sc_int_bitref & operator|=(bool b)
Definition: sc_int_base.h:974
sc_int_bitref_r(const sc_int_bitref_r &a)
Definition: sc_int_base.h:156
long long_high() const
Definition: sc_int_base.h:849
friend bool operator<(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:721
int64 to_int64() const
Definition: sc_int_base.h:835
bool or_reduce() const
Definition: sc_int_base.h:1035
friend class sc_int_subref
Definition: sc_int_base.h:542
uint64 const sc_uint_base int b
Definition: sc_fxval.h:1003
sc_int_base(const sc_int_base &a)
Definition: sc_int_base.h:582
unsigned int sc_digit
Definition: sc_nbdefs.h:173
sc_int_base * m_obj_p
Definition: sc_int_base.h:428
const uint64 UINT_ONE
sc_int_subref & range(int left, int right)
Definition: sc_int_base.h:1294
bool operator!=(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:286
bool nor_reduce() const
Definition: sc_int_base.h:385
bool operator==(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:283
sc_logic_value_t nor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1562
uint64 to_uint64() const
Definition: sc_int_base.h:1094
uint64 to_uint64() const
Definition: sc_int_base.h:838
sc_int_bitref & bit(int i)
Definition: sc_int_base.h:1250
bool nand_reduce() const
Definition: sc_int_base.h:797
sc_int_bitref(const sc_int_bitref &a)
Definition: sc_int_base.h:271
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:862
const uint_type mask_int[SC_INTWIDTH][SC_INTWIDTH]
Definition: sc_uint_base.h:107
sc_numrep sc_io_base(systemc_ostream &, sc_numrep)
Definition: sc_nbutils.h:107
sc_int_base & operator|=(int_type v)
Definition: sc_int_base.h:684
const uint64 UINT64_32ONES
bool and_reduce() const
const std::string to_string(sc_numrep numrep=SC_DEC) const
virtual void concat_set(int64 src, int low_i)
sc_int_base & operator<<=(int_type v)
Definition: sc_int_base.h:691
#define BITS_PER_DIGIT
Definition: sc_nbdefs.h:137
static sc_core::sc_vpool< sc_int_bitref > m_pool
Definition: sc_int_base.h:297
inline::std::istream & operator>>(::std::istream &is, sc_bit &a)
Definition: sc_bit.h:394
const std::string to_string(sc_numrep numrep=SC_DEC) const
bool operator>=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:730
bool operator<=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:724
sc_logic_value_t or_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1554
uint64 value() const
Definition: sc_int_base.h:220
virtual ~sc_int_base()
Definition: sc_int_base.h:609
uint_type value() const
Definition: sc_int_base.h:401
sc_int_base & operator&=(int_type v)
Definition: sc_int_base.h:681
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
int length() const
Definition: sc_int_base.h:766
sc_int_base & operator^=(int_type v)
Definition: sc_int_base.h:687
sc_int_subref & operator=(int_type v)
bool test(int i) const
Definition: sc_int_base.h:754
sc_int_bitref & operator[](int i)
Definition: sc_int_base.h:1229
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:205
uint64_t uint64
Definition: sc_nbdefs.h:183
bool xor_reduce() const
sc_int_base & operator-=(int_type v)
Definition: sc_int_base.h:666
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
bool or_reduce() const
bool nand_reduce() const
Definition: sc_int_base.h:380
#define SC_INTWIDTH
Definition: sc_nbdefs.h:235
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:177
sc_int_base(const sc_generic_base< T > &a)
Definition: sc_int_base.h:592
static sc_core::sc_vpool< sc_int_subref > m_pool
Definition: sc_int_base.h:520
int to_int() const
Definition: sc_int_base.h:823
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
Definition: sc_int_base.h:187
friend class sc_int_subref_r
Definition: sc_int_base.h:541
void scan(::std::istream &is=::std::cin)
virtual ~sc_int_subref_r()
Definition: sc_int_base.h:347
bool operator~() const
Definition: sc_int_base.h:909
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
Definition: sc_int_base.h:179
const std::string to_string(sc_numrep numrep=SC_DEC) const
Definition: sc_int_base.h:1113
int_type value() const
Definition: sc_int_base.h:819
void initialize(const sc_int_base *obj_p, int left_i, int right_i)
Definition: sc_int_base.h:329
double to_double() const
Definition: sc_int_base.h:841
bool nor_reduce() const
Definition: sc_int_base.h:802
bool xnor_reduce() const
Definition: sc_int_base.h:807
sc_logic_value_t xnor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1578
virtual void concat_set(int64 src, int low_i)
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:386
bool operator>(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:727
sc_logic_value_t and_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1538
void initialize(const sc_int_base *obj_p, int index_)
Definition: sc_int_base.h:146
sc_int_base & operator%=(int_type v)
Definition: sc_int_base.h:675
friend class sc_int_bitref_r
Definition: sc_int_base.h:539
int64 int_type
Definition: sc_nbdefs.h:233
long to_long() const
Definition: sc_int_base.h:1070
sc_int_bitref & operator=(const sc_int_bitref_r &b)
Definition: sc_int_base.h:935
sc_int_base & operator/=(int_type v)
Definition: sc_int_base.h:672
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:776
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
sc_int_base(int_type v, int w)
Definition: sc_int_base.h:578
sc_int_subref_r(const sc_int_subref_r &a)
Definition: sc_int_base.h:340
friend bool operator!=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:718
double to_double() const
Definition: sc_int_base.h:1102
bool operator!() const
Definition: sc_int_base.h:902
sc_int_base & operator=(int_type v)
Definition: sc_int_base.h:614
bool xor_reduce() const
Definition: sc_int_base.h:1043
friend class sc_int_bitref
Definition: sc_int_base.h:540