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