SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_uint_base.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_uint_base.h -- An unsigned integer whose length is less than 64 bits.
23 */
38 /*****************************************************************************
39 
40  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
41  changes you are making here.
42 
43  Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
44  Description of Modification: - Resolved ambiguity with sc_(un)signed.
45  - Merged the code for 64- and 32-bit versions
46  via the constants in sc_nbdefs.h.
47  - Eliminated redundant file inclusions.
48 
49  Name, Affiliation, Date:
50  Description of Modification:
51 
52  *****************************************************************************/
53 
54 // $Log: sc_uint_base.h,v $
55 // Revision 1.3 2011/08/24 22:05:46 acg
56 // Torsten Maehne: initialization changes to remove warnings.
57 //
58 // Revision 1.2 2011/02/18 20:19:15 acg
59 // Andy Goodrich: updating Copyright notice.
60 //
61 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
62 // SystemC 2.3
63 //
64 // Revision 1.4 2006/05/08 17:50:02 acg
65 // Andy Goodrich: Added David Long's declarations for friend operators,
66 // functions, and methods, to keep the Microsoft compiler happy.
67 //
68 // Revision 1.3 2006/01/13 18:49:32 acg
69 // Added $Log command so that CVS check in comments are reproduced in the
70 // source.
71 //
72 
73 #ifndef SC_UINT_BASE_H
74 #define SC_UINT_BASE_H
75 
76 
77 #include "sysc/kernel/sc_object.h"
84 
85 
86 namespace sc_dt
87 {
88 
89 class sc_concatref;
90 
91 // classes defined in this module
92 class sc_uint_bitref_r;
93 class sc_uint_bitref;
94 class sc_uint_subref_r;
95 class sc_uint_subref;
96 class sc_uint_base;
97 
98 // forward class declarations
99 class sc_bv_base;
100 class sc_lv_base;
101 class sc_int_subref_r;
102 class sc_signed_subref_r;
103 class sc_unsigned_subref_r;
104 class sc_signed;
105 class sc_unsigned;
106 class sc_fxval;
107 class sc_fxval_fast;
108 class sc_fxnum;
109 class sc_fxnum_fast;
110 
111 } // namespace sc_dt
112 
113 // extern template instantiations
114 namespace sc_core {
115 SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_uint_bitref>;
116 SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_uint_subref>;
117 } // namespace sc_core
118 
119 namespace sc_dt {
120 
122 
123 // friend operator declarations
124  inline bool operator == ( const sc_uint_base& a, const sc_uint_base& b );
125  inline bool operator != ( const sc_uint_base& a, const sc_uint_base& b );
126  inline bool operator < ( const sc_uint_base& a, const sc_uint_base& b );
127  inline bool operator <= ( const sc_uint_base& a, const sc_uint_base& b );
128  inline bool operator > ( const sc_uint_base& a, const sc_uint_base& b );
129  inline bool operator >= ( const sc_uint_base& a, const sc_uint_base& b );
130 
131 
132 
140 {
141  friend class sc_uint_base;
142  friend class sc_uint_signal;
143 
144 
145  // constructors
146 
147 public:
149  sc_value_base(init), m_index(init.m_index), m_obj_p(init.m_obj_p)
150  {}
151 
152 protected:
153  sc_uint_bitref_r() : sc_value_base(), m_index(0), m_obj_p(0)
154  {}
155 
156  // initializer for sc_core::sc_vpool:
157 
158  void initialize( const sc_uint_base* obj_p, int index_ )
159  {
160  m_obj_p = (sc_uint_base*)obj_p;
161  m_index = index_;
162  }
163 
164 public:
165 
166  // destructor
167 
169  {}
170 
171  // concatenation support
172 
173  virtual int concat_length(bool* xz_present_p) const
174  { if ( xz_present_p ) *xz_present_p = false; return 1; }
175  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const
176  {
177  int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
178  int word_i = low_i / BITS_PER_DIGIT;
179 
180  dst_p[word_i] &= ~bit_mask;
181  return false;
182  }
183  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const
184  {
185  int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
186  bool result; // True is non-zero.
187  int word_i = low_i / BITS_PER_DIGIT;
188 
189  if ( operator uint64() )
190  {
191  dst_p[word_i] |= bit_mask;
192  result = true;
193  }
194  else
195  {
196  dst_p[word_i] &= ~bit_mask;
197  result = false;
198  }
199  return result;
200  }
201  virtual uint64 concat_get_uint64() const
202  { return operator uint64(); }
203 
204  // capacity
205 
206  int length() const
207  { return 1; }
208 
209 #ifdef SC_DT_DEPRECATED
210  int bitwidth() const
211  { return length(); }
212 #endif
213 
214 
215  // implicit conversion to uint64
216 
217  operator uint64 () const;
218  bool operator ! () const;
219  bool operator ~ () const;
220 
221 
222  // explicit conversions
223 
224  uint64 value() const
225  { return operator uint64 (); }
226 
227  bool to_bool() const
228  { return operator uint64 (); }
229 
230 
231  // other methods
232 
233  void print( ::std::ostream& os = ::std::cout ) const
234  { os << to_bool(); }
235 
236 protected:
237 
238  int m_index;
240 
241 private:
242 
243  // disabled
244  sc_uint_bitref_r& operator = ( const sc_uint_bitref_r& );
245 };
246 
247 
248 
249 inline
250 ::std::ostream&
251 operator << ( ::std::ostream&, const sc_uint_bitref_r& );
252 
253 
261  : public sc_uint_bitref_r
262 {
263  friend class sc_uint_base;
265 
266 
267  // constructors
268 
269 protected:
271  {}
272 public:
274  {}
275 
276 public:
277 
278  // assignment operators
279 
280  sc_uint_bitref& operator = ( const sc_uint_bitref_r& b );
281  sc_uint_bitref& operator = ( const sc_uint_bitref& b );
282  sc_uint_bitref& operator = ( bool b );
283 
284  sc_uint_bitref& operator &= ( bool b );
285  sc_uint_bitref& operator |= ( bool b );
286  sc_uint_bitref& operator ^= ( bool b );
287 
288  // concatenation methods
289 
290  virtual void concat_set(int64 src, int low_i);
291  virtual void concat_set(const sc_signed& src, int low_i);
292  virtual void concat_set(const sc_unsigned& src, int low_i);
293  virtual void concat_set(uint64 src, int low_i);
294 
295  // other methods
296 
297  void scan( ::std::istream& is = ::std::cin );
298 
299 protected:
301 
302 };
303 
304 
305 
306 inline
307 ::std::istream&
308 operator >> ( ::std::istream&, sc_uint_bitref& );
309 
310 
318 {
319  friend class sc_uint_base;
320  friend class sc_uint_subref;
321 
322 
323  // constructors
324 
325 public:
327  sc_value_base(init), m_left(init.m_left), m_obj_p(init.m_obj_p),
328  m_right(init.m_right)
329  {}
330 
331 protected:
332  sc_uint_subref_r() : sc_value_base(), m_left(0), m_obj_p(0), m_right(0)
333  {}
334 
335  // initializer for sc_core::sc_vpool:
336 
337  void initialize( const sc_uint_base* obj_p, int left_i, int right_i )
338  {
339  m_obj_p = (sc_uint_base*)obj_p;
340  m_left = left_i;
341  m_right = right_i;
342  }
343 
344 public:
345 
346  // destructor
347 
349  {}
350 
351  // capacity
352 
353  int length() const
354  { return ( m_left - m_right + 1 ); }
355 
356 #ifdef SC_DT_DEPRECATED
357  int bitwidth() const
358  { return length(); }
359 #endif
360 
361  // concatenation support
362 
363  virtual int concat_length(bool* xz_present_p) const
364  { if ( xz_present_p ) *xz_present_p = false; return length(); }
365  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
366  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
367  virtual uint64 concat_get_uint64() const
368  { return (uint64)operator uint_type(); }
369 
370 
371  // reduce methods
372 
373  bool and_reduce() const;
374 
375  bool nand_reduce() const
376  { return ( ! and_reduce() ); }
377 
378  bool or_reduce() const;
379 
380  bool nor_reduce() const
381  { return ( ! or_reduce() ); }
382 
383  bool xor_reduce() const;
384 
385  bool xnor_reduce() const
386  { return ( ! xor_reduce() ); }
387 
388 
389  // implicit conversion to uint_type
390 
391  operator uint_type() const;
392 
393 
394  // explicit conversions
395 
396  uint_type value() const
397  { return operator uint_type(); }
398 
399 
400  int to_int() const;
401  unsigned int to_uint() const;
402  long to_long() const;
403  unsigned long to_ulong() const;
404  int64 to_int64() const;
405  uint64 to_uint64() const;
406  double to_double() const;
407 
408 
409  // explicit conversion to character string
410 
411  const std::string to_string( sc_numrep numrep = SC_DEC ) const;
412  const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
413 
414 
415  // other methods
416 
417  void print( ::std::ostream& os = ::std::cout ) const
418  { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
419 
420 protected:
421 
422  int m_left;
424  int m_right;
425 
426 private:
427 
428  // disabled
429  sc_uint_subref_r& operator = ( const sc_uint_subref_r& );
430 };
431 
432 
433 
434 inline
435 ::std::ostream&
436 operator << ( ::std::ostream&, const sc_uint_subref_r& );
437 
438 
446  : public sc_uint_subref_r
447 {
448  friend class sc_uint_base;
450 
451 
452  // constructors
453 
454 protected:
456  {}
457 
458 public:
460  {}
461 
462 public:
463 
464  // assignment operators
465 
466  sc_uint_subref& operator = ( uint_type v );
467 
468  sc_uint_subref& operator = ( const sc_uint_base& a );
469 
470  sc_uint_subref& operator = ( const sc_uint_subref_r& a )
471  { return operator = ( a.operator uint_type() ); }
472 
473  sc_uint_subref& operator = ( const sc_uint_subref& a )
474  { return operator = ( a.operator uint_type() ); }
475 
476  template<class T>
477  sc_uint_subref& operator = ( const sc_generic_base<T>& a )
478  { return operator = ( a->to_uint64() ); }
479 
480  sc_uint_subref& operator = ( const char* a );
481 
482  sc_uint_subref& operator = ( unsigned long a )
483  { return operator = ( (uint_type) a ); }
484 
485  sc_uint_subref& operator = ( long a )
486  { return operator = ( (uint_type) a ); }
487 
488  sc_uint_subref& operator = ( unsigned int a )
489  { return operator = ( (uint_type) a ); }
490 
491  sc_uint_subref& operator = ( int a )
492  { return operator = ( (uint_type) a ); }
493 
494  sc_uint_subref& operator = ( int64 a )
495  { return operator = ( (uint_type) a ); }
496 
497  sc_uint_subref& operator = ( double a )
498  { return operator = ( (uint_type) a ); }
499 
500  sc_uint_subref& operator = ( const sc_signed& );
501  sc_uint_subref& operator = ( const sc_unsigned& );
502  sc_uint_subref& operator = ( const sc_bv_base& );
503  sc_uint_subref& operator = ( const sc_lv_base& );
504 
505  // concatenation methods
506 
507  virtual void concat_set(int64 src, int low_i);
508  virtual void concat_set(const sc_signed& src, int low_i);
509  virtual void concat_set(const sc_unsigned& src, int low_i);
510  virtual void concat_set(uint64 src, int low_i);
511 
512  // other methods
513 
514  void scan( ::std::istream& is = ::std::cin );
515 
516 protected:
518 
519 };
520 
521 
522 
523 inline
524 ::std::istream&
525 operator >> ( ::std::istream&, sc_uint_subref& );
526 
527 
535 {
536  friend class sc_uint_bitref_r;
537  friend class sc_uint_bitref;
538  friend class sc_uint_subref_r;
539  friend class sc_uint_subref;
540 
541 
542  // support methods
543 
544  void invalid_length() const;
545  void invalid_index( int i ) const;
546  void invalid_range( int l, int r ) const;
547 
548  void check_length() const
549  { if( m_len <= 0 || m_len > SC_INTWIDTH ) { invalid_length(); } }
550 
551  void check_index( int i ) const
552  { if( i < 0 || i >= m_len ) { invalid_index( i ); } }
553 
554  void check_range( int l, int r ) const
555  { if( r < 0 || l >= m_len || l < r ) { invalid_range( l, r ); } }
556 
557  void check_value() const;
558 
559  void extend_sign()
560  {
561 #ifdef DEBUG_SYSTEMC
562  check_value();
563 #endif
564  m_val &= ( ~UINT_ZERO >> m_ulen );
565  }
566 
567 public:
568 
569  // constructors
570 
571  explicit sc_uint_base( int w = sc_length_param().len() )
572  : m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
573  { check_length(); }
574 
576  : m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
577  { check_length(); extend_sign(); }
578 
580  : sc_value_base(a), m_val(a.m_val), m_len(a.m_len), m_ulen(a.m_ulen)
581  {}
582 
583  explicit sc_uint_base( const sc_uint_subref_r& a )
584  : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )
585  { extend_sign(); }
586 
587  template<class T>
588  explicit sc_uint_base( const sc_generic_base<T>& a )
589  : m_val( a->to_uint64() ), m_len( a->length() ),
590  m_ulen( SC_INTWIDTH - m_len )
591  { check_length(); extend_sign(); }
592 
593  explicit sc_uint_base( const sc_bv_base& v );
594  explicit sc_uint_base( const sc_lv_base& v );
595  explicit sc_uint_base( const sc_int_subref_r& v );
596  explicit sc_uint_base( const sc_signed_subref_r& v );
597  explicit sc_uint_base( const sc_unsigned_subref_r& v );
598  explicit sc_uint_base( const sc_signed& a );
599  explicit sc_uint_base( const sc_unsigned& a );
600 
601 
602  // destructor
603 
604  virtual ~sc_uint_base()
605  {}
606 
607 
608  // assignment operators
609 
610  sc_uint_base& operator = ( uint_type v )
611  { m_val = v; extend_sign(); return *this; }
612 
613  sc_uint_base& operator = ( const sc_uint_base& a )
614  { m_val = a.m_val; extend_sign(); return *this; }
615 
616  sc_uint_base& operator = ( const sc_uint_subref_r& a )
617  { m_val = a; extend_sign(); return *this; }
618 
619  template<class T>
620  sc_uint_base& operator = ( const sc_generic_base<T>& a )
621  { m_val = a->to_uint64(); extend_sign(); return *this; }
622 
623  sc_uint_base& operator = ( const sc_signed& a );
624  sc_uint_base& operator = ( const sc_unsigned& a );
625 
626 #ifdef SC_INCLUDE_FX
627  sc_uint_base& operator = ( const sc_fxval& a );
628  sc_uint_base& operator = ( const sc_fxval_fast& a );
629  sc_uint_base& operator = ( const sc_fxnum& a );
630  sc_uint_base& operator = ( const sc_fxnum_fast& a );
631 #endif
632 
633  sc_uint_base& operator = ( const sc_bv_base& a );
634  sc_uint_base& operator = ( const sc_lv_base& a );
635 
636  sc_uint_base& operator = ( const char* a );
637 
638  sc_uint_base& operator = ( unsigned long a )
639  { m_val = a; extend_sign(); return *this; }
640 
641  sc_uint_base& operator = ( long a )
642  { m_val = a; extend_sign(); return *this; }
643 
644  sc_uint_base& operator = ( unsigned int a )
645  { m_val = a; extend_sign(); return *this; }
646 
647  sc_uint_base& operator = ( int a )
648  { m_val = a; extend_sign(); return *this; }
649 
650  sc_uint_base& operator = ( int64 a )
651  { m_val = a; extend_sign(); return *this; }
652 
653  sc_uint_base& operator = ( double a )
654  { m_val = (uint_type) a; extend_sign(); return *this; }
655 
656 
657  // arithmetic assignment operators
658 
659  sc_uint_base& operator += ( uint_type v )
660  { m_val += v; extend_sign(); return *this; }
661 
662  sc_uint_base& operator -= ( uint_type v )
663  { m_val -= v; extend_sign(); return *this; }
664 
665  sc_uint_base& operator *= ( uint_type v )
666  { m_val *= v; extend_sign(); return *this; }
667 
668  sc_uint_base& operator /= ( uint_type v )
669  { m_val /= v; extend_sign(); return *this; }
670 
671  sc_uint_base& operator %= ( uint_type v )
672  { m_val %= v; extend_sign(); return *this; }
673 
674 
675  // bitwise assignment operators
676 
678  { m_val &= v; extend_sign(); return *this; }
679 
681  { m_val |= v; extend_sign(); return *this; }
682 
684  { m_val ^= v; extend_sign(); return *this; }
685 
686 
687  sc_uint_base& operator <<= ( uint_type v )
688  { m_val <<= v; extend_sign(); return *this; }
689 
690  sc_uint_base& operator >>= ( uint_type v )
691  { m_val >>= v; /* no sign extension needed */ return *this; }
692 
693 
694  // prefix and postfix increment and decrement operators
695 
696  sc_uint_base& operator ++ () // prefix
697  { ++ m_val; extend_sign(); return *this; }
698 
699  const sc_uint_base operator ++ ( int ) // postfix
700  { sc_uint_base tmp( *this ); ++ m_val; extend_sign(); return tmp; }
701 
702  sc_uint_base& operator -- () // prefix
703  { -- m_val; extend_sign(); return *this; }
704 
705  const sc_uint_base operator -- ( int ) // postfix
706  { sc_uint_base tmp( *this ); -- m_val; extend_sign(); return tmp; }
707 
708 
709  // relational operators
710 
711  friend bool operator == ( const sc_uint_base& a, const sc_uint_base& b )
712  { return a.m_val == b.m_val; }
713 
714  friend bool operator != ( const sc_uint_base& a, const sc_uint_base& b )
715  { return a.m_val != b.m_val; }
716 
717  friend bool operator < ( const sc_uint_base& a, const sc_uint_base& b )
718  { return a.m_val < b.m_val; }
719 
720  friend bool operator <= ( const sc_uint_base& a, const sc_uint_base& b )
721  { return a.m_val <= b.m_val; }
722 
723  friend bool operator > ( const sc_uint_base& a, const sc_uint_base& b )
724  { return a.m_val > b.m_val; }
725 
726  friend bool operator >= ( const sc_uint_base& a, const sc_uint_base& b )
727  { return a.m_val >= b.m_val; }
728 
729 
730  // bit selection
731 
732  sc_uint_bitref& operator [] ( int i );
733  const sc_uint_bitref_r& operator [] ( int i ) const;
734 
735  sc_uint_bitref& bit( int i );
736  const sc_uint_bitref_r& bit( int i ) const;
737 
738 
739  // part selection
740 
741  sc_uint_subref& operator () ( int left, int right );
742  const sc_uint_subref_r& operator () ( int left, int right ) const;
743 
744  sc_uint_subref& range( int left, int right );
745  const sc_uint_subref_r& range( int left, int right ) const;
746 
747 
748  // bit access, without bounds checking or sign extension
749 
750  bool test( int i ) const
751  { return ( 0 != (m_val & (UINT_ONE << i)) ); }
752 
753  void set( int i )
754  { m_val |= (UINT_ONE << i); }
755 
756  void set( int i, bool v )
757  { v ? m_val |= (UINT_ONE << i) : m_val &= ~(UINT_ONE << i); }
758 
759 
760  // capacity
761 
762  int length() const
763  { return m_len; }
764 
765 #ifdef SC_DT_DEPRECATED
766  int bitwidth() const
767  { return length(); }
768 #endif
769 
770  // concatenation support
771 
772  virtual int concat_length(bool* xz_present_p) const
773  { if ( xz_present_p ) *xz_present_p = false; return length(); }
774  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
775  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
776  virtual uint64 concat_get_uint64() const
777  { return m_val; }
778  virtual void concat_set(int64 src, int low_i);
779  virtual void concat_set(const sc_signed& src, int low_i);
780  virtual void concat_set(const sc_unsigned& src, int low_i);
781  virtual void concat_set(uint64 src, int low_i);
782 
783 
784  // reduce methods
785 
786  bool and_reduce() const;
787 
788  bool nand_reduce() const
789  { return ( ! and_reduce() ); }
790 
791  bool or_reduce() const;
792 
793  bool nor_reduce() const
794  { return ( ! or_reduce() ); }
795 
796  bool xor_reduce() const;
797 
798  bool xnor_reduce() const
799  { return ( ! xor_reduce() ); }
800 
801 
802  // implicit conversion to uint_type
803 
804  operator uint_type() const
805  { return m_val; }
806 
807 
808  // explicit conversions
809 
810  uint_type value() const
811  { return operator uint_type(); }
812 
813 
814  int to_int() const
815  { return (int) m_val; }
816 
817  unsigned int to_uint() const
818  { return (unsigned int) m_val; }
819 
820  long to_long() const
821  { return (long) m_val; }
822 
823  unsigned long to_ulong() const
824  { return (unsigned long) m_val; }
825 
826  int64 to_int64() const
827  { return (int64) m_val; }
828 
830  { return (uint64) m_val; }
831 
832  double to_double() const
833  { return uint64_to_double( m_val ); }
834 
835 
836  long long_low() const
837  { return (long) (m_val & UINT64_32ONES); }
838 
839  long long_high() const
840  { return (long) ((m_val >> 32) & UINT64_32ONES); }
841 
842 
843  // explicit conversion to character string
844 
845  const std::string to_string( sc_numrep numrep = SC_DEC ) const;
846  const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
847 
848 
849  // other methods
850 
851  void print( ::std::ostream& os = ::std::cout ) const
852  { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
853 
854  void scan( ::std::istream& is = ::std::cin );
855 
856 protected:
857 
858  uint_type m_val; // value
859  int m_len; // length
860  int m_ulen; // unused length
861 };
862 
863 
864 
865 inline
866 ::std::ostream&
867 operator << ( ::std::ostream&, const sc_uint_base& );
868 
869 inline
870 ::std::istream&
871 operator >> ( ::std::istream&, sc_uint_base& );
872 
873 
874 
881 // implicit conversion to bool
882 
883 inline
884 sc_uint_bitref_r::operator uint64 () const
885 {
886  return m_obj_p->test( m_index );
887 }
888 
889 inline
890 bool
892 {
893  return ! m_obj_p->test( m_index );
894 }
895 
896 inline
897 bool
899 {
900  return ! m_obj_p->test( m_index );
901 }
902 
903 
904 
905 inline
906 ::std::ostream&
907 operator << ( ::std::ostream& os, const sc_uint_bitref_r& a )
908 {
909  a.print( os );
910  return os;
911 }
912 
913 
920 // assignment operators
921 
922 inline
925 {
926  m_obj_p->set( m_index, b.to_bool() );
927  return *this;
928 }
929 
930 inline
933 {
934  m_obj_p->set( m_index, b.to_bool() );
935  return *this;
936 }
937 
938 inline
941 {
942  m_obj_p->set( m_index, b );
943  return *this;
944 }
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->set( m_index, b );
963  }
964  return *this;
965 }
966 
967 inline
970 {
971  if( b ) {
972  m_obj_p->m_val ^= (UINT_ONE << m_index);
973  }
974  return *this;
975 }
976 
977 
978 
979 inline
980 ::std::istream&
981 operator >> ( ::std::istream& is, sc_uint_bitref& a )
982 {
983  a.scan( is );
984  return is;
985 }
986 
987 
994 // implicit conversion to uint_type
995 
996 inline
997 sc_uint_subref_r::operator uint_type() const
998 {
999  uint_type val = m_obj_p->m_val;
1000  int uleft = SC_INTWIDTH - (m_left + 1);
1001  return ( (val & (~UINT_ZERO >> uleft)) >> m_right );
1002 }
1003 
1004 
1005 // reduce methods
1006 
1007 inline
1008 bool
1010 {
1011  sc_uint_base a( *this );
1012  return a.and_reduce();
1013 }
1014 
1015 inline
1016 bool
1018 {
1019  sc_uint_base a( *this );
1020  return a.or_reduce();
1021 }
1022 
1023 inline
1024 bool
1026 {
1027  sc_uint_base a( *this );
1028  return a.xor_reduce();
1029 }
1030 
1031 
1032 // explicit conversions
1033 
1034 inline
1035 int
1037 {
1038  sc_uint_base a( *this );
1039  return a.to_int();
1040 }
1041 
1042 inline
1043 unsigned int
1045 {
1046  sc_uint_base a( *this );
1047  return a.to_uint();
1048 }
1049 
1050 inline
1051 long
1053 {
1054  sc_uint_base a( *this );
1055  return a.to_long();
1056 }
1057 
1058 inline
1059 unsigned long
1061 {
1062  sc_uint_base a( *this );
1063  return a.to_ulong();
1064 }
1065 
1066 inline
1067 int64
1069 {
1070  sc_uint_base a( *this );
1071  return a.to_int64();
1072 }
1073 
1074 inline
1075 uint64
1077 {
1078  sc_uint_base a( *this );
1079  return a.to_uint64();
1080 }
1081 
1082 inline
1083 double
1085 {
1086  sc_uint_base a( *this );
1087  return a.to_double();
1088 }
1089 
1090 
1091 // explicit conversion to character string
1092 
1093 inline
1094 const std::string
1096 {
1097  sc_uint_base a( *this );
1098  return a.to_string( numrep );
1099 }
1100 
1101 inline
1102 const std::string
1103 sc_uint_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
1104 {
1105  sc_uint_base a( *this );
1106  return a.to_string( numrep, w_prefix );
1107 }
1108 
1109 
1110 // functional notation for the reduce methods
1111 
1112 inline
1113 bool
1115 {
1116  return a.and_reduce();
1117 }
1118 
1119 inline
1120 bool
1122 {
1123  return a.nand_reduce();
1124 }
1125 
1126 inline
1127 bool
1129 {
1130  return a.or_reduce();
1131 }
1132 
1133 inline
1134 bool
1136 {
1137  return a.nor_reduce();
1138 }
1139 
1140 inline
1141 bool
1143 {
1144  return a.xor_reduce();
1145 }
1146 
1147 inline
1148 bool
1150 {
1151  return a.xnor_reduce();
1152 }
1153 
1154 
1155 
1156 inline
1157 ::std::ostream&
1158 operator << ( ::std::ostream& os, const sc_uint_subref_r& a )
1159 {
1160  a.print( os );
1161  return os;
1162 }
1163 
1164 
1171 // assignment operators
1172 
1173 inline
1176 {
1177  return operator = ( a.operator uint_type() );
1178 }
1179 
1180 inline
1183 {
1184  sc_uint_base aa( length() );
1185  return ( *this = aa = a );
1186 }
1187 
1188 
1189 
1190 inline
1191 ::std::istream&
1192 operator >> ( ::std::istream& is, sc_uint_subref& a )
1193 {
1194  a.scan( is );
1195  return is;
1196 }
1197 
1198 
1205 // bit selection
1206 
1207 inline
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 inline
1218 const sc_uint_bitref_r&
1220 {
1221  check_index( i );
1222  sc_uint_bitref* result_p = sc_uint_bitref::m_pool.allocate();
1223  result_p->initialize(this, i);
1224  return *result_p;
1225 }
1226 
1227 
1228 inline
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 inline
1239 const sc_uint_bitref_r&
1240 sc_uint_base::bit( int i ) const
1241 {
1242  check_index( i );
1243  sc_uint_bitref* result_p = sc_uint_bitref::m_pool.allocate();
1244  result_p->initialize(this, i);
1245  return *result_p;
1246 }
1247 
1248 
1249 // part selection
1250 
1251 inline
1253 sc_uint_base::operator () ( int left, int right )
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 inline
1262 const sc_uint_subref_r&
1263 sc_uint_base::operator () ( int left, int right ) const
1264 {
1265  check_range( left, right );
1266  sc_uint_subref* result_p = sc_uint_subref::m_pool.allocate();
1267  result_p->initialize(this, left, right);
1268  return *result_p;
1269 }
1270 
1271 
1272 inline
1274 sc_uint_base::range( int left, int right )
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 inline
1283 const sc_uint_subref_r&
1284 sc_uint_base::range( int left, int right ) const
1285 {
1286  check_range( left, right );
1287  sc_uint_subref* result_p = sc_uint_subref::m_pool.allocate();
1288  result_p->initialize(this, left, right);
1289  return *result_p;
1290 }
1291 
1292 
1293 // functional notation for the reduce methods
1294 
1295 inline
1296 bool
1298 {
1299  return a.and_reduce();
1300 }
1301 
1302 inline
1303 bool
1305 {
1306  return a.nand_reduce();
1307 }
1308 
1309 inline
1310 bool
1312 {
1313  return a.or_reduce();
1314 }
1315 
1316 inline
1317 bool
1319 {
1320  return a.nor_reduce();
1321 }
1322 
1323 inline
1324 bool
1326 {
1327  return a.xor_reduce();
1328 }
1329 
1330 inline
1331 bool
1333 {
1334  return a.xnor_reduce();
1335 }
1336 
1337 
1338 
1339 inline
1340 ::std::ostream&
1341 operator << ( ::std::ostream& os, const sc_uint_base& a )
1342 {
1343  a.print( os );
1344  return os;
1345 }
1346 
1347 inline
1348 ::std::istream&
1349 operator >> ( ::std::istream& is, sc_uint_base& a )
1350 {
1351  a.scan( is );
1352  return is;
1353 }
1354 
1355 } // namespace sc_dt
1356 
1357 #endif
1358 
1359 // Taf!
const std::string to_string(sc_numrep numrep=SC_DEC) const
Base class for the fixed-point types; limited precision.
Definition: sc_fxnum.h:991
void scan(::std::istream &is=::std::cin)
sc_uint_subref_r(const sc_uint_subref_r &init)
Definition: sc_uint_base.h:326
uint_type value() const
Definition: sc_uint_base.h:810
#define BITS_PER_DIGIT
Definition: sc_nbdefs.h:143
int length() const
Definition: sc_uint_base.h:762
sc_uint_base(uint_type v, int w)
Definition: sc_uint_base.h:575
sc_uint_bitref_r(const sc_uint_bitref_r &init)
Definition: sc_uint_base.h:148
uint64 to_uint64() const
Definition: sc_uint_base.h:829
long long_low() const
Definition: sc_uint_base.h:836
Proxy class for sc_uint part selection (r-value only).
Definition: sc_uint_base.h:317
sc_uint_subref(const sc_uint_subref &init)
Definition: sc_uint_base.h:459
bool operator==(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:289
unsigned long to_ulong() const
Definition: sc_uint_base.h:823
Proxy class for sc_int part selection (r-value only).
Definition: sc_int_base.h:325
Fixed-point value types; limited precision.
Definition: sc_fxval.h:439
sc_uint_subref & operator=(uint_type v)
sc_proxy< X >::value_type nand_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1545
bool test(int i) const
Definition: sc_uint_base.h:750
X & operator&=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:342
Report ids for the datatypes/int code.
void print(::std::ostream &os=::std::cout) const
Definition: sc_uint_base.h:233
sc_uint_bitref & operator^=(bool b)
Definition: sc_uint_base.h:969
long to_long() const
Definition: sc_uint_base.h:820
int64 to_int64() const
Definition: sc_uint_base.h:826
sc_uint_base * m_obj_p
Definition: sc_uint_base.h:239
double to_double() const
Definition: sc_uint_base.h:832
int64_t int64
Definition: sc_nbdefs.h:188
Proxy class for sc_unsigned part selection (r-value only).
Definition: sc_unsigned.h:811
long long_high() const
Definition: sc_uint_base.h:839
sc_proxy< X >::value_type xnor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1577
bool xnor_reduce() const
Definition: sc_uint_base.h:385
virtual uint64 concat_get_uint64() const
Definition: sc_uint_base.h:367
Base class for sc_uint.
Definition: sc_uint_base.h:534
bool xnor_reduce() const
Definition: sc_uint_base.h:798
sc_proxy< X >::value_type nor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1561
Proxy class for sc_uint bit selection (r-value and l-value).
Definition: sc_uint_base.h:260
static const uint64 UINT_ONE
Definition: sc_nbdefs.h:237
X & operator|=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:444
Arbitrary precision signed number.
Definition: sc_signed.h:1099
uint64 to_uint64() const
int to_int() const
Definition: sc_uint_base.h:814
Abstract base class of all SystemC native variables.
Definition: sc_value_base.h:82
unsigned int to_uint() const
uint64_t uint64
Definition: sc_nbdefs.h:189
Arbitrary precision unsigned number.
Definition: sc_unsigned.h:1001
Base class for the fixed-point types; arbitrary precision.
Definition: sc_fxnum.h:564
sc_uint_subref & operator()(int left, int right)
Base class for SystemC bit values.
bool nand_reduce() const
Definition: sc_uint_base.h:375
unsigned long to_ulong() const
unsigned int sc_digit
Definition: sc_nbdefs.h:179
uint_type value() const
Definition: sc_uint_base.h:396
uint64 const sc_uint_base int b
Definition: sc_fxval.h:1005
Proxy class for sc_uint part selection (r-value and l-value).
Definition: sc_uint_base.h:445
bool xor_reduce() const
bool operator!=(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:292
sc_uint_bitref & operator&=(bool b)
bool and_reduce() const
sc_proxy< X >::value_type xor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1569
void scan(::std::istream &is=::std::cin)
Fixed-point value type; arbitrary precision.
Definition: sc_fxval.h:95
bool or_reduce() const
void initialize(const sc_uint_base *obj_p, int left_i, int right_i)
Definition: sc_uint_base.h:337
Arbitrary size logic vector base class.
Definition: sc_lv_base.h:91
unsigned int to_uint() const
Definition: sc_uint_base.h:817
double uint64_to_double(uint64 a)
Platform independent conversion from double uint64 to double.
Definition: scfx_ieee.h:685
sc_proxy< X >::value_type or_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1553
void scan(::std::istream &is=::std::cin)
uint64 value() const
Definition: sc_uint_base.h:224
void print(::std::ostream &os=::std::cout) const
Definition: sc_uint_base.h:417
bool operator>=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:741
bool operator<(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:732
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
Definition: sc_uint_base.h:183
SC_API const std::string to_string(sc_enc)
bool operator>(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:738
Abstract base class of all SystemC `simulation&#39; objects.
Proxy class for user-defined value classes and other classes that.
void initialize(const sc_uint_base *obj_p, int index_)
Definition: sc_uint_base.h:158
#define SC_INTWIDTH
Definition: sc_nbdefs.h:235
static sc_core::sc_vpool< sc_uint_bitref > m_pool
Definition: sc_uint_base.h:300
sc_numrep
Enumeration of number representations for character string conversion.
Definition: sc_nbdefs.h:97
const std::string to_string(sc_numrep numrep=SC_DEC) const
double to_double() const
virtual uint64 concat_get_uint64() const
Definition: sc_uint_base.h:776
Proxy class for sc_signed part selection (r-value only).
Definition: sc_signed.h:905
static const uint64 UINT64_32ONES
Definition: sc_nbdefs.h:199
Length parameter type.
virtual int concat_length(bool *xz_present_p) const
Definition: sc_uint_base.h:173
uint64 uint_type
Definition: sc_nbdefs.h:234
sc_uint_bitref & operator=(const sc_uint_bitref_r &b)
Definition: sc_uint_base.h:924
sc_uint_base(int w=sc_length_param().len())
Definition: sc_uint_base.h:571
X & operator^=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:546
static const uint64 UINT_ZERO
Definition: sc_nbdefs.h:236
bool nor_reduce() const
Definition: sc_uint_base.h:793
sc_uint_base(const sc_uint_subref_r &a)
Definition: sc_uint_base.h:583
virtual int concat_length(bool *xz_present_p) const
Definition: sc_uint_base.h:363
sc_uint_base(const sc_uint_base &a)
Definition: sc_uint_base.h:579
sc_uint_subref & range(int left, int right)
#define SC_API_TEMPLATE_DECL_
Definition: sc_cmnhdr.h:177
sc_uint_bitref(const sc_uint_bitref &init)
Definition: sc_uint_base.h:273
static sc_core::sc_vpool< sc_uint_subref > m_pool
Definition: sc_uint_base.h:517
virtual uint64 concat_get_uint64() const
Definition: sc_uint_base.h:201
sc_numrep sc_io_base(::std::ostream &, sc_numrep)
Definition: sc_nbutils.h:114
Proxy class for sc_uint bit selection (r-value only).
Definition: sc_uint_base.h:139
sc_uint_bitref & operator|=(bool b)
Definition: sc_uint_base.h:959
void print(::std::ostream &os=::std::cout) const
Definition: sc_uint_base.h:851
Top level header file for arbitrary precision signed/unsigned.
SC_API const uint_type mask_int[SC_INTWIDTH][SC_INTWIDTH]
Definition: sc_uint_base.h:121
Temporary value pool classes.
inline ::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:390
sc_uint_base * m_obj_p
Definition: sc_uint_base.h:423
const sc_bit operator~(const sc_bit &a)
Definition: sc_bit.h:316
Arbitrary size bit vector base class.
Definition: sc_bv_base.h:80
virtual ~sc_uint_base()
Definition: sc_uint_base.h:604
sc_uint_bitref & bit(int i)
bool sc_io_show_base(::std::ostream &)
Definition: sc_nbutils.h:119
sc_proxy< X >::value_type and_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1537
virtual int concat_length(bool *xz_present_p) const
Definition: sc_uint_base.h:772
sc_uint_bitref & operator[](int i)
bool operator<=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:735
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
Definition: sc_uint_base.h:175
#define SC_API
Definition: sc_cmnhdr.h:168
inline ::std::istream & operator>>(::std::istream &is, sc_bit &a)
Definition: sc_bit.h:398
sc_uint_base(const sc_generic_base< T > &a)
Definition: sc_uint_base.h:588
bool nand_reduce() const
Definition: sc_uint_base.h:788