SystemC 3.0.0
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
24 Unlike arbitrary precision, arithmetic and bitwise operations
25 are performed using the native types (hence capped at 64 bits).
26 The sc_int integer is useful when the user does not need
27 arbitrary precision and the performance is superior to
28 sc_bigint/sc_biguint.
29
30 Original Author: Amit Rao, Synopsys, Inc.
31
32 *****************************************************************************/
33
34/*****************************************************************************
35
36 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
37 changes you are making here.
38
39 Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
40 Description of Modification: - Resolved ambiguity with sc_(un)signed.
41 - Merged the code for 64- and 32-bit versions
42 via the constants in sc_nbdefs.h.
43 - Eliminated redundant file inclusions.
44
45 Name, Affiliation, Date:
46 Description of Modification:
47
48 *****************************************************************************/
49
50// $Log: sc_int_base.h,v $
51// Revision 1.3 2011/08/24 22:05:45 acg
52// Torsten Maehne: initialization changes to remove warnings.
53//
54// Revision 1.2 2011/02/18 20:19:15 acg
55// Andy Goodrich: updating Copyright notice.
56//
57// Revision 1.1.1.1 2006/12/15 20:20:05 acg
58// SystemC 2.3
59//
60// Revision 1.4 2006/05/08 17:50:01 acg
61// Andy Goodrich: Added David Long's declarations for friend operators,
62// functions, and methods, to keep the Microsoft compiler happy.
63//
64// Revision 1.3 2006/01/13 18:49:31 acg
65// Added $Log command so that CVS check in comments are reproduced in the
66// source.
67//
68
69#ifndef SC_INT_BASE_H
70#define SC_INT_BASE_H
71
81
82
83namespace sc_dt
84{
85
86class sc_concatref;
87
88// classes defined in this module
89class sc_int_bitref_r;
90class sc_int_bitref;
91class sc_int_subref_r;
92class sc_int_subref;
93class sc_int_base;
94class sc_signed_subref_r;
95class sc_unsigned_subref_r;
96
97// forward class declarations
98class sc_bv_base;
99class sc_lv_base;
100class sc_signed;
101class sc_unsigned;
102class sc_fxval;
103class sc_fxval_fast;
104class sc_fxnum;
105class sc_fxnum_fast;
106
107} // namespace sc_dt
108
109// extern template instantiations
110namespace sc_core {
111SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_int_bitref>;
112SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_int_subref>;
113} // namespace sc_core
114
115namespace sc_dt {
116
118
119// friend operator declarations
120 // relational operators
121
122 inline bool operator == ( const sc_int_base& a, const sc_int_base& b );
123
124 inline bool operator != ( const sc_int_base& a, const sc_int_base& b );
125
126 inline bool operator < ( const sc_int_base& a, const sc_int_base& b );
127
128 inline bool operator <= ( const sc_int_base& a, const sc_int_base& b );
129
130 inline bool operator > ( const sc_int_base& a, const sc_int_base& b );
131
132 inline bool operator >= ( const sc_int_base& a, const sc_int_base& b );
133
134
135// ----------------------------------------------------------------------------
136// CLASS : sc_int_bitref_r
137//
138// Proxy class for sc_int bit selection (r-value only).
139// ----------------------------------------------------------------------------
140
142{
143 friend class sc_int_base;
144
145protected:
146
147 // constructor
148
149 sc_int_bitref_r() : sc_value_base(), m_index(), m_obj_p()
150 {}
151
152 // initializer for sc_core::sc_vpool:
153
154 void initialize( const sc_int_base* obj_p, int index_ )
155 {
156 m_obj_p = (sc_int_base*)obj_p;
157 m_index = index_;
158 }
159
160public:
161
162 // copy constructor
163
165 sc_value_base(a), m_index(a.m_index), m_obj_p(a.m_obj_p)
166 {}
167
168 // destructor
169
171 {}
172
173 // capacity
174
175 int length() const
176 { return 1; }
177
178#ifdef SC_DT_DEPRECATED
179 int bitwidth() const
180 { return length(); }
181#endif
182
183 // concatenation support
184
185 virtual int concat_length( bool *xz_present_p ) const
186 { if (xz_present_p) *xz_present_p = false; return 1; }
187 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const
188 {
189 int bit_mask = 1 << SC_BIT_INDEX(low_i);
190 int word_i = SC_DIGIT_INDEX(low_i);
191
192 dst_p[word_i] &= ~bit_mask;
193 return false;
194 }
195 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const
196 {
197 bool non_zero;
198 int bit_mask = 1 << SC_BIT_INDEX(low_i);
199 int word_i = SC_DIGIT_INDEX(low_i);
200
201 if ( operator uint64() )
202 {
203 dst_p[word_i] |= bit_mask;
204 non_zero = true;
205 }
206 else
207 {
208 dst_p[word_i] &= ~bit_mask;
209 non_zero = false;
210 }
211 return non_zero;
212 }
213 virtual uint64 concat_get_uint64() const
214 { return operator uint64(); }
215
216
217
218
219 // implicit conversions
220
221 operator uint64 () const;
222 bool operator ! () const;
223 bool operator ~ () const;
224
225
226 // explicit conversions
227
228 uint64 value() const
229 { return operator uint64(); }
230
231 bool to_bool() const
232 { return operator uint64(); }
233
234
235 // other methods
236
237 void print( ::std::ostream& os = ::std::cout ) const
238 { os << to_bool(); }
239
240protected:
243
244private:
245
246 // disabled
247 sc_int_bitref_r& operator = ( const sc_int_bitref_r& );
248};
249
250
251inline
252::std::ostream&
253operator << ( ::std::ostream&, const sc_int_bitref_r& );
254
255
256// ----------------------------------------------------------------------------
257// CLASS : sc_int_bitref
258//
259// Proxy class for sc_int bit selection (r-value and l-value).
260// ----------------------------------------------------------------------------
261
263 : public sc_int_bitref_r
264{
265 friend class sc_int_base;
266 friend class sc_core::sc_vpool<sc_int_bitref>;
267
268
269 // constructor
270
272 {}
273
274
275public:
276
277 // copy constructor
278
280 {}
281
282 // assignment operators
283
284 sc_int_bitref& operator = ( const sc_int_bitref_r& b );
285 sc_int_bitref& operator = ( const sc_int_bitref& b );
286 sc_int_bitref& operator = ( bool b );
287
291
292 // concatenation methods
293
294 virtual void concat_set(int64 src, int low_i);
295 virtual void concat_set(const sc_signed& src, int low_i);
296 virtual void concat_set(const sc_unsigned& src, int low_i);
297 virtual void concat_set(uint64 src, int low_i);
298
299
300 // other methods
301
302 void scan( ::std::istream& is = ::std::cin );
303
304};
305
306
307
308inline
309::std::istream&
310operator >> ( ::std::istream&, sc_int_bitref& );
311
312
313// ----------------------------------------------------------------------------
314// CLASS : sc_int_subref_r
315//
316// Proxy class for sc_int part selection (r-value only).
317// ----------------------------------------------------------------------------
318
320{
321 friend class sc_int_base;
322 friend class sc_int_signal;
323 friend class sc_int_subref;
324
325protected:
326
327 // constructor
328
329 sc_int_subref_r() : sc_value_base(), m_left(0), m_obj_p(0), m_right(0)
330 {}
331
332 // initializer for sc_core::sc_vpool:
333
334 void initialize( const sc_int_base* obj_p, int left_i, int right_i )
335 {
336 m_obj_p = (sc_int_base*)obj_p;
337 m_left = left_i;
338 m_right = right_i;
339 }
340
341
342public:
343 // copy constructor
344
346 sc_value_base(a), m_left( a.m_left ), m_obj_p( a.m_obj_p ),
347 m_right( a.m_right )
348 {}
349
350 // destructor
351
353 {}
354
355 // capacity
356
357 int length() const
358 { return ( m_left - m_right + 1 ); }
359
360#ifdef SC_DT_DEPRECATED
361 int bitwidth() const
362 { return length(); }
363#endif
364
365 // concatenation support
366
367 virtual int concat_length(bool* xz_present_p) const
368 { if ( xz_present_p ) *xz_present_p = false; return length(); }
369 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
370 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
371 virtual uint64 concat_get_uint64() const
372 {
373 int len = length();
374 uint64 val = operator uint_type();
375 if ( len < 64 )
376 return (uint64)(val & ~((uint_type)-1 << len));
377 else
378 return (uint64)val;
379 }
380
381 // reduce methods
382
383 bool and_reduce() const;
384
385 bool nand_reduce() const
386 { return ( ! and_reduce() ); }
387
388 bool or_reduce() const;
389
390 bool nor_reduce() const
391 { return ( ! or_reduce() ); }
392
393 bool xor_reduce() const;
394
395 bool xnor_reduce() const
396 { return ( ! xor_reduce() ); }
397
398
399 // implicit conversion to uint_type
400
401 operator uint_type () const;
402
403
404 // explicit conversions
405
407 { return operator uint_type(); }
408
409
410 int to_int() const;
411 unsigned int to_uint() const;
412 long to_long() const;
413 unsigned long to_ulong() const;
414 int64 to_int64() const;
415 uint64 to_uint64() const;
416 double to_double() const;
417
418
419 // explicit conversion to character string
420
421 const std::string to_string( sc_numrep numrep = SC_DEC ) const;
422 const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
423
424
425 // other methods
426
427 void print( ::std::ostream& os = ::std::cout ) const
428 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
429
430protected:
431
435
436private:
437 const sc_int_subref_r& operator = ( const sc_int_subref_r& );
438};
439
440
441
442inline
443::std::ostream&
444operator << ( ::std::ostream&, const sc_int_subref_r& );
445
446
447// ----------------------------------------------------------------------------
448// CLASS : sc_int_subref
449//
450// Proxy class for sc_int part selection (r-value and l-value).
451// ----------------------------------------------------------------------------
452
454 : public sc_int_subref_r
455{
456 friend class sc_int_base;
457 friend class sc_core::sc_vpool<sc_int_subref>;
458
459
460protected:
461
462 // constructor
464 {}
465
466public:
467
468 // copy constructor
469
471 {}
472
473 // assignment operators
474
475 sc_int_subref& operator = ( int_type v );
476 sc_int_subref& operator = ( const sc_int_base& a );
477
478 sc_int_subref& operator = ( const sc_int_subref_r& a )
479 { return operator = ( a.operator uint_type() ); }
480
481 sc_int_subref& operator = ( const sc_int_subref& a )
482 { return operator = ( a.operator uint_type() ); }
483
484 template< class T >
485 sc_int_subref& operator = ( const sc_generic_base<T>& a )
486 { return operator = ( a->to_int64() ); }
487
488 sc_int_subref& operator = ( const char* a );
489
490 sc_int_subref& operator = ( unsigned long a )
491 { return operator = ( (int_type) a ); }
492
493 sc_int_subref& operator = ( long a )
494 { return operator = ( (int_type) a ); }
495
496 sc_int_subref& operator = ( unsigned int a )
497 { return operator = ( (int_type) a ); }
498
499 sc_int_subref& operator = ( int a )
500 { return operator = ( (int_type) a ); }
501
502 sc_int_subref& operator = ( uint64 a )
503 { return operator = ( (int_type) a ); }
504
505 sc_int_subref& operator = ( double a )
506 { return operator = ( (int_type) a ); }
507
508 sc_int_subref& operator = ( const sc_signed& );
509 sc_int_subref& operator = ( const sc_unsigned& );
510 sc_int_subref& operator = ( const sc_bv_base& );
511 sc_int_subref& operator = ( const sc_lv_base& );
512
513 // concatenation methods
514
515 virtual void concat_set(int64 src, int low_i);
516 virtual void concat_set(const sc_signed& src, int low_i);
517 virtual void concat_set(const sc_unsigned& src, int low_i);
518 virtual void concat_set(uint64 src, int low_i);
519
520 // other methods
521
522 void scan( ::std::istream& is = ::std::cin );
523
524};
525
526
527
528inline
529::std::istream&
530operator >> ( ::std::istream&, sc_int_subref& );
531
532
533// ----------------------------------------------------------------------------
534// CLASS : sc_int_base
535//
536// Base class for sc_int.
537// ----------------------------------------------------------------------------
538
540{
541 friend class sc_int_bitref_r;
542 friend class sc_int_bitref;
543 friend class sc_int_subref_r;
544 friend class sc_int_subref;
545
546
547 // support methods
548
549 void invalid_length() const;
550 void invalid_index( int i ) const;
551 void invalid_range( int l, int r ) const;
552
553 void check_length() const
554 { if( m_len <= 0 || m_len > SC_INTWIDTH ) { invalid_length(); } }
555
556 void check_index( int i ) const
557 { if( i < 0 || i >= m_len ) { invalid_index( i ); } }
558
559 void check_range( int l, int r ) const
560 { if( r < 0 || l >= m_len || l < r ) { invalid_range( l, r ); } }
561
562 void check_value() const;
563
564 void extend_sign()
565 {
566#ifdef DEBUG_SYSTEMC
567 check_value();
568#endif
569 if ( m_val & (1ull << (m_len-1)) ) {
570 m_val |= (~UINT_ZERO << (m_len-1));
571 }
572 else {
573 m_val &= ( ~UINT_ZERO >> m_ulen );
574 }
575 }
576
577public:
578
579 // constructors
580
581 explicit sc_int_base( int w = sc_length_param().len() )
582 : m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
583 { check_length(); }
584
586 : m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )
587 { check_length(); extend_sign(); }
588
590 : sc_value_base(a), m_val( a.m_val ), m_len( a.m_len ),
591 m_ulen( a.m_ulen )
592 {}
593
594 explicit sc_int_base( const sc_int_subref_r& a )
595 : m_val( a ), m_len( a.length() ),
596 m_ulen( SC_INTWIDTH - m_len )
597 { extend_sign(); }
598
599 template< class T >
600 explicit sc_int_base( const sc_generic_base<T>& a ) :
601 m_val( a->to_int64() ), m_len( a->length() ),
602 m_ulen( SC_INTWIDTH - m_len )
603 { check_length(); extend_sign(); }
604
605 explicit sc_int_base( const sc_signed& a );
606 explicit sc_int_base( const sc_unsigned& a );
607 explicit sc_int_base( const sc_bv_base& v );
608 explicit sc_int_base( const sc_lv_base& v );
609 explicit sc_int_base( const sc_uint_subref_r& v );
610 explicit sc_int_base( const sc_signed_subref_r& v );
611 explicit sc_int_base( const sc_unsigned_subref_r& v );
612
613
614
615 // destructor
616
617 virtual ~sc_int_base()
618 {}
619
620 // assignment operators
621
622 sc_int_base& operator = ( int_type v )
623 { m_val = v; extend_sign(); return *this; }
624
625 sc_int_base& operator = ( const sc_int_base& a )
626 { m_val = a.m_val; extend_sign(); return *this; }
627
628 sc_int_base& operator = ( const sc_int_subref_r& a )
629 { m_val = a; extend_sign(); return *this; }
630
631 template<class T>
632 sc_int_base& operator = ( const sc_generic_base<T>& a )
633 { m_val = a->to_int64(); extend_sign(); return *this; }
634
635 sc_int_base& operator = ( const sc_signed& a );
636 sc_int_base& operator = ( const sc_unsigned& a );
637
638 inline sc_int_base& operator = ( const sc_signed_subref_r& a );
639 inline sc_int_base& operator = ( const sc_unsigned_subref_r& 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 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 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
754 {
756 return pool.allocate();
757 }
758
759
760 // part selection
761
762 sc_int_subref& operator () ( int left, int right );
763 const sc_int_subref_r& operator () ( int left, int right ) const;
764
765 sc_int_subref& range( int left, int right );
766 const sc_int_subref_r& range( int left, int right ) const;
767
769 {
771 return pool.allocate();
772 }
773
774
775 // bit access, without bounds checking or sign extension
776
777 bool test( int i ) const
778 { return ( 0 != (m_val & (UINT_ONE << i)) ); }
779
780 void set( int i )
781 { m_val |= (UINT_ONE << i); }
782
783 void set( int i, bool v )
784 { v ? m_val |= (UINT_ONE << i) : m_val &= ~(UINT_ONE << i); }
785
786
787 // capacity
788
789 int length() const
790 { return m_len; }
791
792#ifdef SC_DT_DEPRECATED
793 int bitwidth() const
794 { return length(); }
795#endif
796
797 // concatenation support
798
799 virtual int concat_length(bool* xz_present_p) const
800 { if ( xz_present_p ) *xz_present_p = false; return length(); }
801 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
802 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
803 virtual uint64 concat_get_uint64() const
804 {
805 if ( m_len < 64 )
806 return (uint64)(m_val & ~((uint_type)-1 << m_len));
807 else
808 return (uint64)m_val;
809 }
810 virtual void concat_set(int64 src, int low_i);
811 virtual void concat_set(const sc_signed& src, int low_i);
812 virtual void concat_set(const sc_unsigned& src, int low_i);
813 virtual void concat_set(uint64 src, int low_i);
814
815
816 // reduce methods
817
818 bool and_reduce() const;
819
820 bool nand_reduce() const
821 { return ( ! and_reduce() ); }
822
823 bool or_reduce() const;
824
825 bool nor_reduce() const
826 { return ( ! or_reduce() ); }
827
828 bool xor_reduce() const;
829
830 bool xnor_reduce() const
831 { return ( ! xor_reduce() ); }
832
833
834 // implicit conversion to int_type
835
836 operator int_type() const
837 { return m_val; }
838
839
840 // explicit conversions
841
843 { return operator int_type(); }
844
845
846 int to_int() const
847 { return (int) m_val; }
848
849 unsigned int to_uint() const
850 { return (unsigned int) m_val; }
851
852 long to_long() const
853 { return (long) m_val; }
854
855 unsigned long to_ulong() const
856 { return (unsigned long) m_val; }
857
859 { return (int64) m_val; }
860
862 { return (uint64) m_val; }
863
864 double to_double() const
865 { return (double) m_val; }
866
867
868 long long_low() const
869 { return (long) (m_val & UINT64_32ONES); }
870
871 long long_high() const
872 { return (long) ((m_val >> 32) & UINT64_32ONES); }
873
874 // explicit conversion to character string
875
876 const std::string to_string( sc_numrep numrep = SC_DEC ) const;
877 const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
878
879
880 // other methods
881
882 void print( ::std::ostream& os = ::std::cout ) const
883 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
884
885 void scan( ::std::istream& is = ::std::cin );
886
887protected:
888
889 int_type m_val; // value
890 int m_len; // length
891 int m_ulen; // unused length
892};
893
894
895
896inline
897::std::ostream&
898operator << ( ::std::ostream&, const sc_int_base& );
899
900inline
901::std::istream&
902operator >> ( ::std::istream&, sc_int_base& );
903
904
905
906// ----------------------------------------------------------------------------
907// CLASS : sc_int_bitref_r
908//
909// Proxy class for sc_int bit selection (r-value only).
910// ----------------------------------------------------------------------------
911
912// implicit conversion to uint64
913
914inline
915sc_int_bitref_r::operator uint64 () const
916{
917 return m_obj_p->test( m_index );
918}
919
920inline
921bool
923{
924 return ! m_obj_p->test( m_index );
925}
926
927inline
928bool
930{
931 return ! m_obj_p->test( m_index );
932}
933
934
935
936inline
937::std::ostream&
938operator << ( ::std::ostream& os, const sc_int_bitref_r& a )
939{
940 a.print( os );
941 return os;
942}
943
944
945// ----------------------------------------------------------------------------
946// CLASS : sc_int_bitref
947//
948// Proxy class for sc_int bit selection (r-value and l-value).
949// ----------------------------------------------------------------------------
950
951// assignment operators
952
953inline
954sc_int_bitref&
956{
957 m_obj_p->set( m_index, (bool) b );
958 m_obj_p->extend_sign();
959 return *this;
960}
961
962inline
965{
966 m_obj_p->set( m_index, (bool) b );
967 m_obj_p->extend_sign();
968 return *this;
969}
970
971inline
974{
975 m_obj_p->set( m_index, b );
976 m_obj_p->extend_sign();
977 return *this;
978}
979
980
981inline
984{
985 if( ! b ) {
986 m_obj_p->set( m_index, b );
987 m_obj_p->extend_sign();
988 }
989 return *this;
990}
991
992inline
995{
996 if( b ) {
997 m_obj_p->set( m_index, b );
998 m_obj_p->extend_sign();
999 }
1000 return *this;
1001}
1002
1003inline
1006{
1007 if( b ) {
1008 m_obj_p->m_val ^= (UINT_ONE << m_index);
1009 m_obj_p->extend_sign();
1010 }
1011 return *this;
1012}
1013
1014
1015
1016inline
1017::std::istream&
1018operator >> ( ::std::istream& is, sc_int_bitref& a )
1019{
1020 a.scan( is );
1021 return is;
1022}
1023
1024
1025// ----------------------------------------------------------------------------
1026// CLASS : sc_int_subref_r
1027//
1028// Proxy class for sc_int part selection (r-value only).
1029// ----------------------------------------------------------------------------
1030
1031// implicit conversion to int_type
1032
1033inline
1034sc_int_subref_r::operator uint_type() const
1035{
1036 uint_type /*int_type*/ val = m_obj_p->m_val;
1037 int uleft = SC_INTWIDTH - (m_left + 1);
1038 int uright = uleft + m_right;
1039 return ( val << uleft >> uright );
1040}
1041
1042
1043// reduce methods
1044
1045inline
1046bool
1048{
1049 sc_int_base a( *this );
1050 return a.and_reduce();
1051}
1052
1053inline
1054bool
1056{
1057 sc_int_base a( *this );
1058 return a.or_reduce();
1059}
1060
1061inline
1062bool
1064{
1065 sc_int_base a( *this );
1066 return a.xor_reduce();
1067}
1068
1069
1070// explicit conversions
1071
1072inline
1073int
1075{
1076 int result = static_cast<int>(operator uint_type());
1077 return result;
1078}
1079
1080inline
1081unsigned int
1083{
1084 unsigned int result = static_cast<unsigned int>(operator uint_type());
1085 return result;
1086}
1087
1088inline
1089long
1091{
1092 long result = static_cast<long>(operator uint_type());
1093 return result;
1094}
1095
1096inline
1097unsigned long
1099{
1100 unsigned long result = static_cast<unsigned long>(operator uint_type());
1101 return result;
1102}
1103
1104inline
1105int64
1107{
1108 int64 result = operator uint_type();
1109 return result;
1110}
1111
1112inline
1113uint64
1115{
1116 uint64 result = operator uint_type();
1117 return result;
1118}
1119
1120inline
1121double
1123{
1124 double result = static_cast<double>(operator uint_type());
1125 return result;
1126}
1127
1128
1129// explicit conversion to character string
1130
1131inline
1132const std::string
1134{
1135 sc_uint_base a(length());
1136 a = operator uint_type();
1137 return a.to_string( numrep );
1138}
1139
1140inline
1141const std::string
1142sc_int_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
1143{
1144 sc_uint_base a(length());
1145 a = operator uint_type();
1146 return a.to_string( numrep, w_prefix );
1147}
1148
1149
1150// functional notation for the reduce methods
1151
1152inline
1153bool
1155{
1156 return a.and_reduce();
1157}
1158
1159inline
1160bool
1162{
1163 return a.nand_reduce();
1164}
1165
1166inline
1167bool
1169{
1170 return a.or_reduce();
1171}
1172
1173inline
1174bool
1176{
1177 return a.nor_reduce();
1178}
1179
1180inline
1181bool
1183{
1184 return a.xor_reduce();
1185}
1186
1187inline
1188bool
1190{
1191 return a.xnor_reduce();
1192}
1193
1194
1195
1196inline
1197::std::ostream&
1198operator << ( ::std::ostream& os, const sc_int_subref_r& a )
1199{
1200 a.print( os );
1201 return os;
1202}
1203
1204
1205// ----------------------------------------------------------------------------
1206// CLASS : sc_int_subref
1207//
1208// Proxy class for sc_int part selection (r-value and l-value).
1209// ----------------------------------------------------------------------------
1210
1211// assignment operators
1212
1213inline
1214sc_int_subref&
1216{
1217 return operator = ( a.operator int_type() );
1218}
1219
1220inline
1223{
1224 sc_int_base aa( length() );
1225 return ( *this = aa = a );
1226}
1227
1228
1229
1230inline
1231::std::istream&
1232operator >> ( ::std::istream& is, sc_int_subref& a )
1233{
1234 a.scan( is );
1235 return is;
1236}
1237
1238
1239// ----------------------------------------------------------------------------
1240// CLASS : sc_int_base
1241//
1242// Base class for sc_int.
1243// ----------------------------------------------------------------------------
1244
1245// bit selection
1246
1247inline
1248sc_int_bitref&
1250{
1251 check_index( i );
1252 sc_int_bitref* result_p = temporary_bitref();
1253 result_p->initialize(this, i);
1254 return *result_p;
1255}
1256
1257inline
1258const sc_int_bitref_r&
1260{
1261 check_index( i );
1262 sc_int_bitref* result_p = temporary_bitref();
1263 result_p->initialize(this, i);
1264 return *result_p;
1265}
1266
1267
1268inline
1271{
1272 check_index( i );
1273 sc_int_bitref* result_p = temporary_bitref();
1274 result_p->initialize(this, i);
1275 return *result_p;
1276}
1277
1278inline
1279const sc_int_bitref_r&
1280sc_int_base::bit( int i ) const
1281{
1282 check_index( i );
1283 sc_int_bitref* result_p = temporary_bitref();
1284 result_p->initialize(this, i);
1285 return *result_p;
1286}
1287
1288
1289// part selection
1290
1291inline
1293sc_int_base::operator () ( int left, int right )
1294{
1295 check_range( left, right );
1296 sc_int_subref* result_p = temporary_subref();
1297 result_p->initialize(this, left, right);
1298 return *result_p;
1299}
1300
1301inline
1302const sc_int_subref_r&
1303sc_int_base::operator () ( int left, int right ) const
1304{
1305 check_range( left, right );
1306 sc_int_subref* result_p = temporary_subref();
1307 result_p->initialize(this, left, right);
1308 return *result_p;
1309}
1310
1311
1312inline
1314sc_int_base::range( int left, int right )
1315{
1316 check_range( left, right );
1317 sc_int_subref* result_p = temporary_subref();
1318 result_p->initialize(this, left, right);
1319 return *result_p;
1320}
1321
1322inline
1323const sc_int_subref_r&
1324sc_int_base::range( int left, int right ) const
1325{
1326 check_range( left, right );
1327 sc_int_subref* result_p = temporary_subref();
1328 result_p->initialize(this, left, right);
1329 return *result_p;
1330}
1331
1332
1333// functional notation for the reduce methods
1334
1335inline
1336bool
1338{
1339 return a.and_reduce();
1340}
1341
1342inline
1343bool
1345{
1346 return a.nand_reduce();
1347}
1348
1349inline
1350bool
1352{
1353 return a.or_reduce();
1354}
1355
1356inline
1357bool
1359{
1360 return a.nor_reduce();
1361}
1362
1363inline
1364bool
1366{
1367 return a.xor_reduce();
1368}
1369
1370inline
1371bool
1373{
1374 return a.xnor_reduce();
1375}
1376
1377
1378
1379inline
1380::std::ostream&
1381operator << ( ::std::ostream& os, const sc_int_base& a )
1382{
1383 a.print( os );
1384 return os;
1385}
1386
1387inline
1388::std::istream&
1389operator >> ( ::std::istream& is, sc_int_base& a )
1390{
1391 a.scan( is );
1392 return is;
1393}
1394
1395} // namespace sc_dt
1396
1397#endif
1398
1399// Taf!
#define SC_DIGIT_INDEX(BIT_INDEX)
Definition: sc_nbdefs.h:186
#define SC_BIT_INDEX(BIT)
Definition: sc_nbdefs.h:185
#define SC_INTWIDTH
Definition: sc_nbdefs.h:260
#define SC_API_TEMPLATE_DECL_
Definition: sc_cmnhdr.h:157
#define SC_API
Definition: sc_cmnhdr.h:148
bool operator>=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:741
sc_numrep sc_io_base(systemc_ostream &stream_object, sc_numrep def_base)
Definition: sc_string.h:108
X & operator|=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:474
bool sc_io_show_base(systemc_ostream &stream_object)
Definition: sc_string.h:113
sc_proxy< X >::value_type or_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1496
sc_proxy< X >::value_type xor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1512
sc_numrep
Definition: sc_string.h:56
@ SC_DEC
Definition: sc_string.h:60
constexpr uint64 UINT_ONE
Definition: sc_nbdefs.h:262
X & operator^=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:613
constexpr uint64 UINT64_32ONES
Definition: sc_nbdefs.h:220
unsigned long long uint64
Definition: sc_nbdefs.h:216
bool operator==(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:285
bool operator<(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:732
sc_proxy< X >::value_type nor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1504
SC_API std::string to_string(sc_enc)
bool operator<=(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:735
int64 int_type
Definition: sc_nbdefs.h:258
uint64 uint_type
Definition: sc_nbdefs.h:259
X & operator&=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:340
unsigned int sc_digit
Definition: sc_nbdefs.h:161
bool operator!=(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:288
inline::std::istream & operator>>(::std::istream &is, sc_bit &a)
Definition: sc_bit.h:396
sc_proxy< X >::value_type and_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1480
SC_API const uint_type mask_int[SC_INTWIDTH][SC_INTWIDTH]
Definition: sc_uint_base.h:106
bool operator>(const sc_int_base &a, const sc_int_base &b)
Definition: sc_int_base.h:738
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:388
uint64 const sc_uint_base int b
Definition: sc_fxval.h:955
sc_proxy< X >::value_type xnor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1520
sc_proxy< X >::value_type nand_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1488
sc_bit operator~(const sc_bit &a)
Definition: sc_bit.h:312
long long int64
Definition: sc_nbdefs.h:215
sc_int_bitref_r(const sc_int_bitref_r &a)
Definition: sc_int_base.h:164
sc_int_base * m_obj_p
Definition: sc_int_base.h:242
bool operator~() const
Definition: sc_int_base.h:929
bool to_bool() const
Definition: sc_int_base.h:231
uint64 value() const
Definition: sc_int_base.h:228
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
Definition: sc_int_base.h:195
void initialize(const sc_int_base *obj_p, int index_)
Definition: sc_int_base.h:154
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:213
bool operator!() const
Definition: sc_int_base.h:922
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:237
virtual ~sc_int_bitref_r()
Definition: sc_int_base.h:170
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
Definition: sc_int_base.h:187
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:185
sc_int_bitref & operator^=(bool b)
Definition: sc_int_base.h:1005
sc_int_bitref & operator=(const sc_int_bitref_r &b)
Definition: sc_int_base.h:955
virtual void concat_set(uint64 src, int low_i)
virtual void concat_set(const sc_signed &src, int low_i)
sc_int_bitref & operator|=(bool b)
Definition: sc_int_base.h:994
void scan(::std::istream &is=::std::cin)
sc_int_bitref & operator&=(bool b)
Definition: sc_int_base.h:983
virtual void concat_set(int64 src, int low_i)
sc_int_bitref(const sc_int_bitref &a)
Definition: sc_int_base.h:279
virtual void concat_set(const sc_unsigned &src, int low_i)
uint64 to_uint64() const
Definition: sc_int_base.h:1114
sc_int_base * m_obj_p
Definition: sc_int_base.h:433
virtual ~sc_int_subref_r()
Definition: sc_int_base.h:352
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
bool xor_reduce() const
Definition: sc_int_base.h:1063
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
bool nor_reduce() const
Definition: sc_int_base.h:390
bool and_reduce() const
Definition: sc_int_base.h:1047
const std::string to_string(sc_numrep numrep=SC_DEC) const
Definition: sc_int_base.h:1133
unsigned long to_ulong() const
Definition: sc_int_base.h:1098
uint_type value() const
Definition: sc_int_base.h:406
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:371
bool nand_reduce() const
Definition: sc_int_base.h:385
bool or_reduce() const
Definition: sc_int_base.h:1055
void initialize(const sc_int_base *obj_p, int left_i, int right_i)
Definition: sc_int_base.h:334
unsigned int to_uint() const
Definition: sc_int_base.h:1082
int64 to_int64() const
Definition: sc_int_base.h:1106
sc_int_subref_r(const sc_int_subref_r &a)
Definition: sc_int_base.h:345
double to_double() const
Definition: sc_int_base.h:1122
bool xnor_reduce() const
Definition: sc_int_base.h:395
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:427
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:367
virtual void concat_set(const sc_unsigned &src, int low_i)
virtual void concat_set(uint64 src, int low_i)
sc_int_subref(const sc_int_subref &a)
Definition: sc_int_base.h:470
sc_int_subref & operator=(int_type v)
virtual void concat_set(const sc_signed &src, int low_i)
virtual void concat_set(int64 src, int low_i)
void scan(::std::istream &is=::std::cin)
sc_int_base(const sc_int_subref_r &a)
Definition: sc_int_base.h:594
long long_low() const
Definition: sc_int_base.h:868
virtual uint64 concat_get_uint64() const
Definition: sc_int_base.h:803
sc_int_base(const sc_unsigned &a)
const std::string to_string(sc_numrep numrep, bool w_prefix) const
sc_int_base(const sc_signed_subref_r &v)
virtual ~sc_int_base()
Definition: sc_int_base.h:617
sc_int_base(int_type v, int w)
Definition: sc_int_base.h:585
virtual void concat_set(const sc_signed &src, int low_i)
sc_int_base(const sc_int_base &a)
Definition: sc_int_base.h:589
sc_int_subref & operator()(int left, int right)
Definition: sc_int_base.h:1293
virtual void concat_set(uint64 src, int low_i)
void set(int i)
Definition: sc_int_base.h:780
int length() const
Definition: sc_int_base.h:789
sc_int_base(const sc_lv_base &v)
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
sc_int_base(const sc_signed &a)
int_type value() const
Definition: sc_int_base.h:842
sc_int_bitref & operator[](int i)
Definition: sc_int_base.h:1249
void scan(::std::istream &is=::std::cin)
sc_int_bitref * temporary_bitref() const
Definition: sc_int_base.h:753
virtual void concat_set(const sc_unsigned &src, int low_i)
bool test(int i) const
Definition: sc_int_base.h:777
unsigned long to_ulong() const
Definition: sc_int_base.h:855
virtual int concat_length(bool *xz_present_p) const
Definition: sc_int_base.h:799
double to_double() const
Definition: sc_int_base.h:864
bool nor_reduce() const
Definition: sc_int_base.h:825
sc_int_base(const sc_uint_subref_r &v)
sc_int_bitref & bit(int i)
Definition: sc_int_base.h:1270
uint64 to_uint64() const
Definition: sc_int_base.h:861
bool xnor_reduce() const
Definition: sc_int_base.h:830
virtual void concat_set(int64 src, int low_i)
sc_int_subref * temporary_subref() const
Definition: sc_int_base.h:768
sc_int_base(const sc_unsigned_subref_r &v)
unsigned int to_uint() const
Definition: sc_int_base.h:849
void print(::std::ostream &os=::std::cout) const
Definition: sc_int_base.h:882
int to_int() const
Definition: sc_int_base.h:846
sc_int_base(int w=sc_length_param().len())
Definition: sc_int_base.h:581
long to_long() const
Definition: sc_int_base.h:852
bool nand_reduce() const
Definition: sc_int_base.h:820
bool and_reduce() const
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
long long_high() const
Definition: sc_int_base.h:871
int64 to_int64() const
Definition: sc_int_base.h:858
sc_int_base(const sc_bv_base &v)
void set(int i, bool v)
Definition: sc_int_base.h:783
sc_int_base(const sc_generic_base< T > &a)
Definition: sc_int_base.h:600
bool xor_reduce() const
sc_int_subref & range(int left, int right)
Definition: sc_int_base.h:1314
const std::string to_string(sc_numrep numrep=SC_DEC) const
bool or_reduce() const
const std::string to_string(sc_numrep numrep=SC_DEC) const