SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_int_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_int_base.h -- A signed integer whose length is less than 64 bit.
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_int_base.h,v $
55 // Revision 1.3 2011/08/24 22:05:45 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:01 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:31 acg
69 // Added $Log command so that CVS check in comments are reproduced in the
70 // source.
71 //
72 
73 #ifndef SC_INT_BASE_H
74 #define SC_INT_BASE_H
75 
76 #include "sysc/kernel/sc_cmnhdr.h"
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_int_bitref_r;
93 class sc_int_bitref;
94 class sc_int_subref_r;
95 class sc_int_subref;
96 class sc_int_base;
97 class sc_signed_subref_r;
98 class sc_unsigned_subref_r;
99 
100 // forward class declarations
101 class sc_bv_base;
102 class sc_lv_base;
103 class sc_signed;
104 class sc_unsigned;
105 class sc_fxval;
106 class sc_fxval_fast;
107 class sc_fxnum;
108 class sc_fxnum_fast;
109 
110 } // namespace sc_dt
111 
112 // extern template instantiations
113 namespace sc_core {
114 SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_int_bitref>;
115 SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_int_subref>;
116 } // namespace sc_core
117 
118 namespace sc_dt {
119 
121 
122 // friend operator declarations
123  // relational operators
124 
125  inline bool operator == ( const sc_int_base& a, const sc_int_base& b );
126 
127  inline bool operator != ( const sc_int_base& a, const sc_int_base& b );
128 
129  inline bool operator < ( const sc_int_base& a, const sc_int_base& b );
130 
131  inline bool operator <= ( const sc_int_base& a, const sc_int_base& b );
132 
133  inline bool operator > ( const sc_int_base& a, const sc_int_base& b );
134 
135  inline bool operator >= ( const sc_int_base& a, const sc_int_base& b );
136 
137 
145 {
146  friend class sc_int_base;
147 
148 protected:
149 
150  // constructor
151 
152  sc_int_bitref_r() : sc_value_base(), m_index(), m_obj_p()
153  {}
154 
155  // initializer for sc_core::sc_vpool:
156 
157  void initialize( const sc_int_base* obj_p, int index_ )
158  {
159  m_obj_p = (sc_int_base*)obj_p;
160  m_index = index_;
161  }
162 
163 public:
164 
165  // copy constructor
166 
168  sc_value_base(a), m_index(a.m_index), m_obj_p(a.m_obj_p)
169  {}
170 
171  // destructor
172 
174  {}
175 
176  // capacity
177 
178  int length() const
179  { return 1; }
180 
181 #ifdef SC_DT_DEPRECATED
182  int bitwidth() const
183  { return length(); }
184 #endif
185 
186  // concatenation support
187 
188  virtual int concat_length( bool *xz_present_p ) const
189  { if (xz_present_p) *xz_present_p = false; return 1; }
190  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const
191  {
192  int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
193  int word_i = low_i / BITS_PER_DIGIT;
194 
195  dst_p[word_i] &= ~bit_mask;
196  return false;
197  }
198  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const
199  {
200  bool non_zero;
201  int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
202  int word_i = low_i / BITS_PER_DIGIT;
203 
204  if ( operator uint64() )
205  {
206  dst_p[word_i] |= bit_mask;
207  non_zero = true;
208  }
209  else
210  {
211  dst_p[word_i] &= ~bit_mask;
212  non_zero = false;
213  }
214  return non_zero;
215  }
216  virtual uint64 concat_get_uint64() const
217  { return operator uint64(); }
218 
219 
220 
221 
222  // implicit conversions
223 
224  operator uint64 () const;
225  bool operator ! () const;
226  bool operator ~ () const;
227 
228 
229  // explicit conversions
230 
231  uint64 value() const
232  { return operator uint64(); }
233 
234  bool to_bool() const
235  { return operator uint64(); }
236 
237 
238  // other methods
239 
240  void print( ::std::ostream& os = ::std::cout ) const
241  { os << to_bool(); }
242 
243 protected:
244  int m_index;
246 
247 private:
248 
249  // disabled
250  sc_int_bitref_r& operator = ( const sc_int_bitref_r& );
251 };
252 
253 
254 inline
255 ::std::ostream&
256 operator << ( ::std::ostream&, const sc_int_bitref_r& );
257 
258 
266  : public sc_int_bitref_r
267 {
268  friend class sc_int_base;
270 
271 
272  // constructor
273 
275  {}
276 
277 
278 public:
279 
280  // copy constructor
281 
283  {}
284 
285  // assignment operators
286 
287  sc_int_bitref& operator = ( const sc_int_bitref_r& b );
288  sc_int_bitref& operator = ( const sc_int_bitref& b );
289  sc_int_bitref& operator = ( bool b );
290 
291  sc_int_bitref& operator &= ( bool b );
292  sc_int_bitref& operator |= ( bool b );
293  sc_int_bitref& operator ^= ( bool b );
294 
295  // concatenation methods
296 
297  virtual void concat_set(int64 src, int low_i);
298  virtual void concat_set(const sc_signed& src, int low_i);
299  virtual void concat_set(const sc_unsigned& src, int low_i);
300  virtual void concat_set(uint64 src, int low_i);
301 
302 
303  // other methods
304 
305  void scan( ::std::istream& is = ::std::cin );
306 
307 public:
309 
310 };
311 
312 
313 
314 inline
315 ::std::istream&
316 operator >> ( ::std::istream&, sc_int_bitref& );
317 
318 
326 {
327  friend class sc_int_base;
328  friend class sc_int_signal;
329  friend class sc_int_subref;
330 
331 protected:
332 
333  // constructor
334 
335  sc_int_subref_r() : sc_value_base(), m_left(0), m_obj_p(0), m_right(0)
336  {}
337 
338  // initializer for sc_core::sc_vpool:
339 
340  void initialize( const sc_int_base* obj_p, int left_i, int right_i )
341  {
342  m_obj_p = (sc_int_base*)obj_p;
343  m_left = left_i;
344  m_right = right_i;
345  }
346 
347 
348 public:
349  // copy constructor
350 
352  sc_value_base(a), m_left( a.m_left ), m_obj_p( a.m_obj_p ),
353  m_right( a.m_right )
354  {}
355 
356  // destructor
357 
359  {}
360 
361  // capacity
362 
363  int length() const
364  { return ( m_left - m_right + 1 ); }
365 
366 #ifdef SC_DT_DEPRECATED
367  int bitwidth() const
368  { return length(); }
369 #endif
370 
371  // concatenation support
372 
373  virtual int concat_length(bool* xz_present_p) const
374  { if ( xz_present_p ) *xz_present_p = false; return length(); }
375  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
376  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
377  virtual uint64 concat_get_uint64() const
378  {
379  int len = length();
380  uint64 val = operator uint_type();
381  if ( len < 64 )
382  return (uint64)(val & ~((uint_type)-1 << len));
383  else
384  return (uint64)val;
385  }
386 
387  // reduce methods
388 
389  bool and_reduce() const;
390 
391  bool nand_reduce() const
392  { return ( ! and_reduce() ); }
393 
394  bool or_reduce() const;
395 
396  bool nor_reduce() const
397  { return ( ! or_reduce() ); }
398 
399  bool xor_reduce() const;
400 
401  bool xnor_reduce() const
402  { return ( ! xor_reduce() ); }
403 
404 
405  // implicit conversion to uint_type
406 
407  operator uint_type () const;
408 
409 
410  // explicit conversions
411 
412  uint_type value() const
413  { return operator uint_type(); }
414 
415 
416  int to_int() const;
417  unsigned int to_uint() const;
418  long to_long() const;
419  unsigned long to_ulong() const;
420  int64 to_int64() const;
421  uint64 to_uint64() const;
422  double to_double() const;
423 
424 
425  // explicit conversion to character string
426 
427  const std::string to_string( sc_numrep numrep = SC_DEC ) const;
428  const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
429 
430 
431  // other methods
432 
433  void print( ::std::ostream& os = ::std::cout ) const
434  { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
435 
436 protected:
437 
438  int m_left;
440  int m_right;
441 
442 private:
443  const sc_int_subref_r& operator = ( const sc_int_subref_r& );
444 };
445 
446 
447 
448 inline
449 ::std::ostream&
450 operator << ( ::std::ostream&, const sc_int_subref_r& );
451 
452 
460  : public sc_int_subref_r
461 {
462  friend class sc_int_base;
464 
465 
466 protected:
467 
468  // constructor
470  {}
471 
472 public:
473 
474  // copy constructor
475 
477  {}
478 
479  // assignment operators
480 
481  sc_int_subref& operator = ( int_type v );
482  sc_int_subref& operator = ( const sc_int_base& a );
483 
484  sc_int_subref& operator = ( const sc_int_subref_r& a )
485  { return operator = ( a.operator uint_type() ); }
486 
487  sc_int_subref& operator = ( const sc_int_subref& a )
488  { return operator = ( a.operator uint_type() ); }
489 
490  template< class T >
491  sc_int_subref& operator = ( const sc_generic_base<T>& a )
492  { return operator = ( a->to_int64() ); }
493 
494  sc_int_subref& operator = ( const char* a );
495 
496  sc_int_subref& operator = ( unsigned long a )
497  { return operator = ( (int_type) a ); }
498 
499  sc_int_subref& operator = ( long a )
500  { return operator = ( (int_type) a ); }
501 
502  sc_int_subref& operator = ( unsigned int a )
503  { return operator = ( (int_type) a ); }
504 
505  sc_int_subref& operator = ( int a )
506  { return operator = ( (int_type) a ); }
507 
508  sc_int_subref& operator = ( uint64 a )
509  { return operator = ( (int_type) a ); }
510 
511  sc_int_subref& operator = ( double a )
512  { return operator = ( (int_type) a ); }
513 
514  sc_int_subref& operator = ( const sc_signed& );
515  sc_int_subref& operator = ( const sc_unsigned& );
516  sc_int_subref& operator = ( const sc_bv_base& );
517  sc_int_subref& operator = ( const sc_lv_base& );
518 
519  // concatenation methods
520 
521  virtual void concat_set(int64 src, int low_i);
522  virtual void concat_set(const sc_signed& src, int low_i);
523  virtual void concat_set(const sc_unsigned& src, int low_i);
524  virtual void concat_set(uint64 src, int low_i);
525 
526  // other methods
527 
528  void scan( ::std::istream& is = ::std::cin );
529 
530 public:
532 
533 };
534 
535 
536 
537 inline
538 ::std::istream&
539 operator >> ( ::std::istream&, sc_int_subref& );
540 
541 
549 {
550  friend class sc_int_bitref_r;
551  friend class sc_int_bitref;
552  friend class sc_int_subref_r;
553  friend class sc_int_subref;
554 
555 
556  // support methods
557 
558  void invalid_length() const;
559  void invalid_index( int i ) const;
560  void invalid_range( int l, int r ) const;
561 
562  void check_length() const
563  { if( m_len <= 0 || m_len > SC_INTWIDTH ) { invalid_length(); } }
564 
565  void check_index( int i ) const
566  { if( i < 0 || i >= m_len ) { invalid_index( i ); } }
567 
568  void check_range( int l, int r ) const
569  { if( r < 0 || l >= m_len || l < r ) { invalid_range( l, r ); } }
570 
571  void check_value() const;
572 
573  void extend_sign()
574  {
575 #ifdef DEBUG_SYSTEMC
576  check_value();
577 #endif
578  m_val = ( m_val << m_ulen >> m_ulen );
579  }
580 
581 public:
582 
583  // constructors
584 
585  explicit sc_int_base( int w = sc_length_param().len() )
586  : m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
587  { check_length(); }
588 
589  sc_int_base( int_type v, int w )
590  : m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
591  { check_length(); extend_sign(); }
592 
594  : sc_value_base(a), m_val( a.m_val ), m_len( a.m_len ),
595  m_ulen( a.m_ulen )
596  {}
597 
598  explicit sc_int_base( const sc_int_subref_r& a )
599  : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )
600  { extend_sign(); }
601 
602  template< class T >
603  explicit sc_int_base( const sc_generic_base<T>& a ) :
604  m_val( a->to_int64() ), m_len( a->length() ),
605  m_ulen( SC_INTWIDTH - m_len )
606  { check_length(); extend_sign(); }
607 
608  explicit sc_int_base( const sc_signed& a );
609  explicit sc_int_base( const sc_unsigned& a );
610  explicit sc_int_base( const sc_bv_base& v );
611  explicit sc_int_base( const sc_lv_base& v );
612  explicit sc_int_base( const sc_uint_subref_r& v );
613  explicit sc_int_base( const sc_signed_subref_r& v );
614  explicit sc_int_base( const sc_unsigned_subref_r& v );
615 
616 
617 
618  // destructor
619 
620  virtual ~sc_int_base()
621  {}
622 
623  // assignment operators
624 
625  sc_int_base& operator = ( int_type v )
626  { m_val = v; extend_sign(); return *this; }
627 
628  sc_int_base& operator = ( const sc_int_base& a )
629  { m_val = a.m_val; extend_sign(); return *this; }
630 
631  sc_int_base& operator = ( const sc_int_subref_r& a )
632  { m_val = a; extend_sign(); return *this; }
633 
634  template<class T>
635  sc_int_base& operator = ( const sc_generic_base<T>& a )
636  { m_val = a->to_int64(); extend_sign(); return *this; }
637 
638  sc_int_base& operator = ( const sc_signed& a );
639  sc_int_base& operator = ( const sc_unsigned& a );
640 
641 #ifdef SC_INCLUDE_FX
642  sc_int_base& operator = ( const sc_fxval& a );
643  sc_int_base& operator = ( const sc_fxval_fast& a );
644  sc_int_base& operator = ( const sc_fxnum& a );
645  sc_int_base& operator = ( const sc_fxnum_fast& a );
646 #endif
647 
648  sc_int_base& operator = ( const sc_bv_base& a );
649  sc_int_base& operator = ( const sc_lv_base& a );
650 
651  sc_int_base& operator = ( const char* a );
652 
653  sc_int_base& operator = ( unsigned long a )
654  { m_val = a; extend_sign(); return *this; }
655 
656  sc_int_base& operator = ( long a )
657  { m_val = a; extend_sign(); return *this; }
658 
659  sc_int_base& operator = ( unsigned int a )
660  { m_val = a; extend_sign(); return *this; }
661 
662  sc_int_base& operator = ( int a )
663  { m_val = a; extend_sign(); return *this; }
664 
665  sc_int_base& operator = ( uint64 a )
666  { m_val = a; extend_sign(); return *this; }
667 
668  sc_int_base& operator = ( double a )
669  { m_val = (int_type) a; extend_sign(); return *this; }
670 
671 
672  // arithmetic assignment operators
673 
674  sc_int_base& operator += ( int_type v )
675  { m_val += v; extend_sign(); return *this; }
676 
677  sc_int_base& operator -= ( int_type v )
678  { m_val -= v; extend_sign(); return *this; }
679 
680  sc_int_base& operator *= ( int_type v )
681  { m_val *= v; extend_sign(); return *this; }
682 
683  sc_int_base& operator /= ( int_type v )
684  { m_val /= v; extend_sign(); return *this; }
685 
686  sc_int_base& operator %= ( int_type v )
687  { m_val %= v; extend_sign(); return *this; }
688 
689 
690  // bitwise assignment operators
691 
693  { m_val &= v; extend_sign(); return *this; }
694 
696  { m_val |= v; extend_sign(); return *this; }
697 
699  { m_val ^= v; extend_sign(); return *this; }
700 
701 
702  sc_int_base& operator <<= ( int_type v )
703  { m_val <<= v; extend_sign(); return *this; }
704 
705  sc_int_base& operator >>= ( int_type v )
706  { m_val >>= v; /* no sign extension needed */ return *this; }
707 
708 
709  // prefix and postfix increment and decrement operators
710 
711  sc_int_base& operator ++ () // prefix
712  { ++ m_val; extend_sign(); return *this; }
713 
714  const sc_int_base operator ++ ( int ) // postfix
715  { sc_int_base tmp( *this ); ++ m_val; extend_sign(); return tmp; }
716 
717  sc_int_base& operator -- () // prefix
718  { -- m_val; extend_sign(); return *this; }
719 
720  const sc_int_base operator -- ( int ) // postfix
721  { sc_int_base tmp( *this ); -- m_val; extend_sign(); return tmp; }
722 
723 
724  // relational operators
725 
726  friend bool operator == ( const sc_int_base& a, const sc_int_base& b )
727  { return a.m_val == b.m_val; }
728 
729  friend bool operator != ( const sc_int_base& a, const sc_int_base& b )
730  { return a.m_val != b.m_val; }
731 
732  friend bool operator < ( const sc_int_base& a, const sc_int_base& b )
733  { return a.m_val < b.m_val; }
734 
735  friend bool operator <= ( const sc_int_base& a, const sc_int_base& b )
736  { return a.m_val <= b.m_val; }
737 
738  friend bool operator > ( const sc_int_base& a, const sc_int_base& b )
739  { return a.m_val > b.m_val; }
740 
741  friend bool operator >= ( const sc_int_base& a, const sc_int_base& b )
742  { return a.m_val >= b.m_val; }
743 
744 
745  // bit selection
746 
747  sc_int_bitref& operator [] ( int i );
748  const sc_int_bitref_r& operator [] ( int i ) const;
749 
750  sc_int_bitref& bit( int i );
751  const sc_int_bitref_r& bit( int i ) const;
752 
753 
754  // part selection
755 
756  sc_int_subref& operator () ( int left, int right );
757  const sc_int_subref_r& operator () ( int left, int right ) const;
758 
759  sc_int_subref& range( int left, int right );
760  const sc_int_subref_r& range( int left, int right ) const;
761 
762 
763  // bit access, without bounds checking or sign extension
764 
765  bool test( int i ) const
766  { return ( 0 != (m_val & (UINT_ONE << i)) ); }
767 
768  void set( int i )
769  { m_val |= (UINT_ONE << i); }
770 
771  void set( int i, bool v )
772  { v ? m_val |= (UINT_ONE << i) : m_val &= ~(UINT_ONE << i); }
773 
774 
775  // capacity
776 
777  int length() const
778  { return m_len; }
779 
780 #ifdef SC_DT_DEPRECATED
781  int bitwidth() const
782  { return length(); }
783 #endif
784 
785  // concatenation support
786 
787  virtual int concat_length(bool* xz_present_p) const
788  { if ( xz_present_p ) *xz_present_p = false; return length(); }
789  virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
790  virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
791  virtual uint64 concat_get_uint64() const
792  {
793  if ( m_len < 64 )
794  return (uint64)(m_val & ~((uint_type)-1 << m_len));
795  else
796  return (uint64)m_val;
797  }
798  virtual void concat_set(int64 src, int low_i);
799  virtual void concat_set(const sc_signed& src, int low_i);
800  virtual void concat_set(const sc_unsigned& src, int low_i);
801  virtual void concat_set(uint64 src, int low_i);
802 
803 
804  // reduce methods
805 
806  bool and_reduce() const;
807 
808  bool nand_reduce() const
809  { return ( ! and_reduce() ); }
810 
811  bool or_reduce() const;
812 
813  bool nor_reduce() const
814  { return ( ! or_reduce() ); }
815 
816  bool xor_reduce() const;
817 
818  bool xnor_reduce() const
819  { return ( ! xor_reduce() ); }
820 
821 
822  // implicit conversion to int_type
823 
824  operator int_type() const
825  { return m_val; }
826 
827 
828  // explicit conversions
829 
830  int_type value() const
831  { return operator int_type(); }
832 
833 
834  int to_int() const
835  { return (int) m_val; }
836 
837  unsigned int to_uint() const
838  { return (unsigned int) m_val; }
839 
840  long to_long() const
841  { return (long) m_val; }
842 
843  unsigned long to_ulong() const
844  { return (unsigned long) m_val; }
845 
846  int64 to_int64() const
847  { return (int64) m_val; }
848 
850  { return (uint64) m_val; }
851 
852  double to_double() const
853  { return (double) m_val; }
854 
855 
856  long long_low() const
857  { return (long) (m_val & UINT64_32ONES); }
858 
859  long long_high() const
860  { return (long) ((m_val >> 32) & UINT64_32ONES); }
861 
862 
863  // explicit conversion to character string
864 
865  const std::string to_string( sc_numrep numrep = SC_DEC ) const;
866  const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
867 
868 
869  // other methods
870 
871  void print( ::std::ostream& os = ::std::cout ) const
872  { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
873 
874  void scan( ::std::istream& is = ::std::cin );
875 
876 protected:
877 
878  int_type m_val; // value
879  int m_len; // length
880  int m_ulen; // unused length
881 };
882 
883 
884 
885 inline
886 ::std::ostream&
887 operator << ( ::std::ostream&, const sc_int_base& );
888 
889 inline
890 ::std::istream&
891 operator >> ( ::std::istream&, sc_int_base& );
892 
893 
894 
901 // implicit conversion to uint64
902 
903 inline
904 sc_int_bitref_r::operator uint64 () const
905 {
906  return m_obj_p->test( m_index );
907 }
908 
909 inline
910 bool
912 {
913  return ! m_obj_p->test( m_index );
914 }
915 
916 inline
917 bool
919 {
920  return ! m_obj_p->test( m_index );
921 }
922 
923 
924 
925 inline
926 ::std::ostream&
927 operator << ( ::std::ostream& os, const sc_int_bitref_r& a )
928 {
929  a.print( os );
930  return os;
931 }
932 
933 
940 // assignment operators
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, (bool) b );
956  m_obj_p->extend_sign();
957  return *this;
958 }
959 
960 inline
963 {
964  m_obj_p->set( m_index, b );
965  m_obj_p->extend_sign();
966  return *this;
967 }
968 
969 
970 inline
973 {
974  if( ! b ) {
975  m_obj_p->set( m_index, b );
976  m_obj_p->extend_sign();
977  }
978  return *this;
979 }
980 
981 inline
984 {
985  if( b ) {
986  m_obj_p->set( m_index, b );
987  m_obj_p->extend_sign();
988  }
989  return *this;
990 }
991 
992 inline
995 {
996  if( b ) {
997  m_obj_p->m_val ^= (UINT_ONE << m_index);
998  m_obj_p->extend_sign();
999  }
1000  return *this;
1001 }
1002 
1003 
1004 
1005 inline
1006 ::std::istream&
1007 operator >> ( ::std::istream& is, sc_int_bitref& a )
1008 {
1009  a.scan( is );
1010  return is;
1011 }
1012 
1013 
1020 // implicit conversion to int_type
1021 
1022 inline
1023 sc_int_subref_r::operator uint_type() const
1024 {
1025  uint_type /*int_type*/ val = m_obj_p->m_val;
1026  int uleft = SC_INTWIDTH - (m_left + 1);
1027  int uright = uleft + m_right;
1028  return ( val << uleft >> uright );
1029 }
1030 
1031 
1032 // reduce methods
1033 
1034 inline
1035 bool
1037 {
1038  sc_int_base a( *this );
1039  return a.and_reduce();
1040 }
1041 
1042 inline
1043 bool
1045 {
1046  sc_int_base a( *this );
1047  return a.or_reduce();
1048 }
1049 
1050 inline
1051 bool
1053 {
1054  sc_int_base a( *this );
1055  return a.xor_reduce();
1056 }
1057 
1058 
1059 // explicit conversions
1060 
1061 inline
1062 int
1064 {
1065  int result = static_cast<int>(operator uint_type());
1066  return result;
1067 }
1068 
1069 inline
1070 unsigned int
1072 {
1073  unsigned int result = static_cast<unsigned int>(operator uint_type());
1074  return result;
1075 }
1076 
1077 inline
1078 long
1080 {
1081  long result = static_cast<long>(operator uint_type());
1082  return result;
1083 }
1084 
1085 inline
1086 unsigned long
1088 {
1089  unsigned long result = static_cast<unsigned long>(operator uint_type());
1090  return result;
1091 }
1092 
1093 inline
1094 int64
1096 {
1097  int64 result = operator uint_type();
1098  return result;
1099 }
1100 
1101 inline
1102 uint64
1104 {
1105  uint64 result = operator uint_type();
1106  return result;
1107 }
1108 
1109 inline
1110 double
1112 {
1113  double result = static_cast<double>(operator uint_type());
1114  return result;
1115 }
1116 
1117 
1118 // explicit conversion to character string
1119 
1120 inline
1121 const std::string
1123 {
1124  sc_uint_base a(length());
1125  a = operator uint_type();
1126  return a.to_string( numrep );
1127 }
1128 
1129 inline
1130 const std::string
1131 sc_int_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
1132 {
1133  sc_uint_base a(length());
1134  a = operator uint_type();
1135  return a.to_string( numrep, w_prefix );
1136 }
1137 
1138 
1139 // functional notation for the reduce methods
1140 
1141 inline
1142 bool
1144 {
1145  return a.and_reduce();
1146 }
1147 
1148 inline
1149 bool
1151 {
1152  return a.nand_reduce();
1153 }
1154 
1155 inline
1156 bool
1158 {
1159  return a.or_reduce();
1160 }
1161 
1162 inline
1163 bool
1165 {
1166  return a.nor_reduce();
1167 }
1168 
1169 inline
1170 bool
1172 {
1173  return a.xor_reduce();
1174 }
1175 
1176 inline
1177 bool
1179 {
1180  return a.xnor_reduce();
1181 }
1182 
1183 
1184 
1185 inline
1186 ::std::ostream&
1187 operator << ( ::std::ostream& os, const sc_int_subref_r& a )
1188 {
1189  a.print( os );
1190  return os;
1191 }
1192 
1193 
1200 // assignment operators
1201 
1202 inline
1205 {
1206  return operator = ( a.operator int_type() );
1207 }
1208 
1209 inline
1212 {
1213  sc_int_base aa( length() );
1214  return ( *this = aa = a );
1215 }
1216 
1217 
1218 
1219 inline
1220 ::std::istream&
1221 operator >> ( ::std::istream& is, sc_int_subref& a )
1222 {
1223  a.scan( is );
1224  return is;
1225 }
1226 
1227 
1234 // bit selection
1235 
1236 inline
1239 {
1240  check_index( i );
1241  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1242  result_p->initialize(this, i);
1243  return *result_p;
1244 }
1245 
1246 inline
1247 const sc_int_bitref_r&
1249 {
1250  check_index( i );
1251  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1252  result_p->initialize(this, i);
1253  return *result_p;
1254 }
1255 
1256 
1257 inline
1260 {
1261  check_index( i );
1262  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1263  result_p->initialize(this, i);
1264  return *result_p;
1265 }
1266 
1267 inline
1268 const sc_int_bitref_r&
1269 sc_int_base::bit( int i ) const
1270 {
1271  check_index( i );
1272  sc_int_bitref* result_p = sc_int_bitref::m_pool.allocate();
1273  result_p->initialize(this, i);
1274  return *result_p;
1275 }
1276 
1277 
1278 // part selection
1279 
1280 inline
1282 sc_int_base::operator () ( int left, int right )
1283 {
1284  check_range( left, right );
1285  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1286  result_p->initialize(this, left, right);
1287  return *result_p;
1288 }
1289 
1290 inline
1291 const sc_int_subref_r&
1292 sc_int_base::operator () ( int left, int right ) const
1293 {
1294  check_range( left, right );
1295  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1296  result_p->initialize(this, left, right);
1297  return *result_p;
1298 }
1299 
1300 
1301 inline
1303 sc_int_base::range( int left, int right )
1304 {
1305  check_range( left, right );
1306  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1307  result_p->initialize(this, left, right);
1308  return *result_p;
1309 }
1310 
1311 inline
1312 const sc_int_subref_r&
1313 sc_int_base::range( int left, int right ) const
1314 {
1315  check_range( left, right );
1316  sc_int_subref* result_p = sc_int_subref::m_pool.allocate();
1317  result_p->initialize(this, left, right);
1318  return *result_p;
1319 }
1320 
1321 
1322 // functional notation for the reduce methods
1323 
1324 inline
1325 bool
1327 {
1328  return a.and_reduce();
1329 }
1330 
1331 inline
1332 bool
1334 {
1335  return a.nand_reduce();
1336 }
1337 
1338 inline
1339 bool
1341 {
1342  return a.or_reduce();
1343 }
1344 
1345 inline
1346 bool
1348 {
1349  return a.nor_reduce();
1350 }
1351 
1352 inline
1353 bool
1355 {
1356  return a.xor_reduce();
1357 }
1358 
1359 inline
1360 bool
1362 {
1363  return a.xnor_reduce();
1364 }
1365 
1366 
1367 
1368 inline
1369 ::std::ostream&
1370 operator << ( ::std::ostream& os, const sc_int_base& a )
1371 {
1372  a.print( os );
1373  return os;
1374 }
1375 
1376 inline
1377 ::std::istream&
1378 operator >> ( ::std::istream& is, sc_int_base& a )
1379 {
1380  a.scan( is );
1381  return is;
1382 }
1383 
1384 } // namespace sc_dt
1385 
1386 #endif
1387 
1388 // Taf!
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:871
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
Definition: sc_int_base.h:190
Base class for the fixed-point types; limited precision.
Definition: sc_fxnum.h:991
bool nor_reduce() const
Definition: sc_int_base.h:396
bool test(int i) const
Definition: sc_int_base.h:765
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:433
#define BITS_PER_DIGIT
Definition: sc_nbdefs.h:143
virtual ~sc_int_subref_r()
Definition: sc_int_base.h:358
bool and_reduce() const
Definition: sc_int_base.h:1036
bool or_reduce() const
Definition: sc_int_base.h:1044
sc_int_bitref & operator^=(bool b)
Definition: sc_int_base.h:994
Proxy class for sc_uint part selection (r-value only).
Definition: sc_uint_base.h:317
bool nand_reduce() const
Definition: sc_int_base.h:808
uint64 to_uint64() const
Definition: sc_int_base.h:1103
bool operator==(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:289
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_int_base(const sc_int_subref_r &a)
Definition: sc_int_base.h:598
sc_proxy< X >::value_type nand_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1545
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:188
X & operator&=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:342
void scan(::std::istream &is=::std::cin)
Report ids for the datatypes/int code.
virtual ~sc_int_bitref_r()
Definition: sc_int_base.h:173
bool xnor_reduce() const
Definition: sc_int_base.h:401
sc_int_base * m_obj_p
Definition: sc_int_base.h:245
int64_t int64
Definition: sc_nbdefs.h:188
Proxy class for sc_unsigned part selection (r-value only).
Definition: sc_unsigned.h:811
sc_proxy< X >::value_type xnor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1577
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:240
sc_int_bitref & operator|=(bool b)
Definition: sc_int_base.h:983
bool nor_reduce() const
Definition: sc_int_base.h:813
Base class for sc_uint.
Definition: sc_uint_base.h:534
void scan(::std::istream &is=::std::cin)
bool xor_reduce() const
Definition: sc_int_base.h:1052
unsigned int to_uint() const
Definition: sc_int_base.h:1071
static sc_core::sc_vpool< sc_int_bitref > m_pool
Definition: sc_int_base.h:308
sc_proxy< X >::value_type nor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1561
static const uint64 UINT_ONE
Definition: sc_nbdefs.h:237
long long_high() const
Definition: sc_int_base.h:859
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
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
Definition: sc_int_base.h:198
void initialize(const sc_int_base *obj_p, int left_i, int right_i)
Definition: sc_int_base.h:340
uint64 to_uint64() const
Definition: sc_int_base.h:849
Abstract base class of all SystemC native variables.
Definition: sc_value_base.h:82
sc_int_base(int w=sc_length_param().len())
Definition: sc_int_base.h:585
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
Base class for SystemC bit values.
sc_int_subref_r(const sc_int_subref_r &a)
Definition: sc_int_base.h:351
unsigned int sc_digit
Definition: sc_nbdefs.h:179
int64 to_int64() const
Definition: sc_int_base.h:1095
long long_low() const
Definition: sc_int_base.h:856
uint64 const sc_uint_base int b
Definition: sc_fxval.h:1005
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:216
bool operator!=(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:292
long to_long() const
Definition: sc_int_base.h:840
Base class for sc_int.
Definition: sc_int_base.h:548
double to_double() const
Definition: sc_int_base.h:852
sc_proxy< X >::value_type xor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1569
static sc_core::sc_vpool< sc_int_subref > m_pool
Definition: sc_int_base.h:531
unsigned long to_ulong() const
Definition: sc_int_base.h:843
Proxy class for sc_int bit selection (r-value and l-value).
Definition: sc_int_base.h:265
Fixed-point value type; arbitrary precision.
Definition: sc_fxval.h:95
An unsigned integer whose length is less than 64 bits.
unsigned int to_uint() const
Definition: sc_int_base.h:837
sc_int_bitref & operator&=(bool b)
Arbitrary size logic vector base class.
Definition: sc_lv_base.h:91
int64 int_type
Definition: sc_nbdefs.h:233
bool and_reduce() const
sc_proxy< X >::value_type or_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1553
bool xnor_reduce() const
Definition: sc_int_base.h:818
bool xor_reduce() const
bool operator>=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:741
sc_int_bitref & bit(int i)
Definition: sc_int_base.h:1259
unsigned long to_ulong() const
Definition: sc_int_base.h:1087
bool operator<(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:732
sc_int_base * m_obj_p
Definition: sc_int_base.h:439
const std::string to_string(sc_numrep numrep=SC_DEC) const
Definition: sc_int_base.h:1122
SC_API const std::string to_string(sc_enc)
Proxy class for sc_int part selection (r-value and l-value).
Definition: sc_int_base.h:459
void initialize(const sc_int_base *obj_p, int index_)
Definition: sc_int_base.h:157
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.
Proxy class for sc_int bit selection (r-value only).
Definition: sc_int_base.h:144
#define SC_INTWIDTH
Definition: sc_nbdefs.h:235
sc_numrep
Enumeration of number representations for character string conversion.
Definition: sc_nbdefs.h:97
sc_int_base(int_type v, int w)
Definition: sc_int_base.h:589
const std::string to_string(sc_numrep numrep=SC_DEC) const
sc_int_base(const sc_int_base &a)
Definition: sc_int_base.h:593
bool nand_reduce() const
Definition: sc_int_base.h:391
void scan(::std::istream &is=::std::cin)
Proxy class for sc_signed part selection (r-value only).
Definition: sc_signed.h:905
int64 to_int64() const
Definition: sc_int_base.h:846
static const uint64 UINT64_32ONES
Definition: sc_nbdefs.h:199
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:791
Length parameter type.
uint_type value() const
Definition: sc_int_base.h:412
uint64 uint_type
Definition: sc_nbdefs.h:234
int_type value() const
Definition: sc_int_base.h:830
X & operator^=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:546
uint64 value() const
Definition: sc_int_base.h:231
sc_int_bitref(const sc_int_bitref &a)
Definition: sc_int_base.h:282
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:787
virtual ~sc_int_base()
Definition: sc_int_base.h:620
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:377
sc_int_bitref & operator=(const sc_int_bitref_r &b)
Definition: sc_int_base.h:944
sc_int_bitref_r(const sc_int_bitref_r &a)
Definition: sc_int_base.h:167
#define SC_API_TEMPLATE_DECL_
Definition: sc_cmnhdr.h:177
bool to_bool() const
Definition: sc_int_base.h:234
int length() const
Definition: sc_int_base.h:777
sc_int_subref(const sc_int_subref &a)
Definition: sc_int_base.h:476
sc_numrep sc_io_base(::std::ostream &, sc_numrep)
Definition: sc_nbutils.h:114
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:373
int to_int() const
Definition: sc_int_base.h:834
Top level header file for arbitrary precision signed/unsigned.
bool operator!() const
Definition: sc_int_base.h:911
bool operator~() const
Definition: sc_int_base.h:918
SC_API const uint_type mask_int[SC_INTWIDTH][SC_INTWIDTH]
Definition: sc_uint_base.h:121
Temporary value pool classes.
sc_int_base(const sc_generic_base< T > &a)
Definition: sc_int_base.h:603
sc_int_subref & range(int left, int right)
Definition: sc_int_base.h:1303
inline ::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:390
double to_double() const
Definition: sc_int_base.h:1111
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
sc_int_bitref & operator[](int i)
Definition: sc_int_base.h:1238
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
sc_int_subref & operator()(int left, int right)
Definition: sc_int_base.h:1282
bool operator<=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:735
#define SC_API
Definition: sc_cmnhdr.h:168
inline ::std::istream & operator>>(::std::istream &is, sc_bit &a)
Definition: sc_bit.h:398
bool or_reduce() const
sc_int_subref & operator=(int_type v)