SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_signed.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_signed.h -- Arbitrary precision signed arithmetic.
23
24 This file includes the definitions of sc_signed_bitref,
25 sc_signed_subref, and sc_signed classes. The first two classes are
26 proxy classes to reference one bit and a range of bits of a
27 sc_signed number, respectively.
28
29 An sc_signed number has the sign-magnitude representation
30 internally. However, its interface guarantees a 2's-complement
31 representation. The sign-magnitude representation is chosen
32 because of its efficiency: The sc_signed and sc_unsigned types are
33 optimized for arithmetic rather than bitwise operations. For
34 arithmetic operations, the sign-magnitude representation performs
35 better.
36
37 The implementations of sc_signed and sc_unsigned classes are
38 almost identical: Most of the member and friend functions are
39 defined in sc_nbcommon.cpp and sc_nbfriends.cpp so that they can
40 be shared by both of these classes. These functions are chosed by
41 defining a few macros before including them such as IF_SC_SIGNED
42 and CLASS_TYPE. Our implementation choices are mostly dictated by
43 performance considerations in that we tried to provide the most
44 efficient sc_signed and sc_unsigned types without compromising
45 their interface.
46
47 For the behavior of operators, we have two semantics: the old and
48 new. The most important difference between these two semantics is
49 that the old semantics is closer to C/C++ semantics in that the
50 result type of a binary operator on unsigned and signed arguments
51 is unsigned; the new semantics, on the other hand, requires the
52 result type be signed. The new semantics is required by the VSIA
53 C/C++ data types standard. We have implemented the new semantics.
54
55 Original Author: Ali Dasdan, Synopsys, Inc.
56
57 *****************************************************************************/
58
59/*****************************************************************************
60
61 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
62 changes you are making here.
63
64 Name, Affiliation, Date:
65 Description of Modification:
66
67 *****************************************************************************/
68
69// $Log: sc_signed.h,v $
70// Revision 1.3 2011/08/24 22:05:46 acg
71// Torsten Maehne: initialization changes to remove warnings.
72//
73// Revision 1.2 2011/02/18 20:19:15 acg
74// Andy Goodrich: updating Copyright notice.
75//
76// Revision 1.1.1.1 2006/12/15 20:20:05 acg
77// SystemC 2.3
78//
79// Revision 1.5 2006/05/08 17:50:01 acg
80// Andy Goodrich: Added David Long's declarations for friend operators,
81// functions, and methods, to keep the Microsoft compiler happy.
82//
83// Revision 1.4 2006/03/13 20:25:27 acg
84// Andy Goodrich: Addition of function declarations, e.g., xor_signed_friend()
85// to keep gcc 4.x happy.
86//
87// Revision 1.3 2006/01/13 18:49:32 acg
88// Added $Log command so that CVS check in comments are reproduced in the
89// source.
90//
91
92#ifndef SC_SIGNED_H
93#define SC_SIGNED_H
94
95
105
106
107namespace sc_dt
108{
109
110// classes defined in this module
111class sc_signed_bitref_r;
112class sc_signed_bitref;
113class sc_signed_subref_r;
114class sc_signed_subref;
115class sc_concatref;
116class sc_signed;
117
118// forward class declarations
119class sc_bv_base;
120class sc_lv_base;
121class sc_int_base;
122class sc_uint_base;
123class sc_int_subref_r;
124class sc_uint_subref_r;
125class sc_signed;
126class sc_unsigned;
127class sc_unsigned_subref_r;
128class sc_fxval;
129class sc_fxval_fast;
130class sc_fxnum;
131class sc_fxnum_fast;
132
133// Operators that need to be declared so they can be friends:
134
135#define SCFP inline
136#include "sc_signed_friends.h"
137#undef SCFP
138
139 // Unary arithmetic operators
140
144
145 // Bitwise NOT operator (unary).
146
148
149// ----------------------------------------------------------------------------
150// CLASS : sc_signed_bitref_r
151//
152// Proxy class for sc_signed bit selection (r-value only).
153// ----------------------------------------------------------------------------
154
156{
157 friend class sc_signed;
158
159protected:
160
161 // constructor and initialization:
162
163 sc_signed_bitref_r() : sc_value_base(), m_index(0), m_obj_p(0)
164 {}
165
166 void initialize( const sc_signed* obj_p, int index_ )
167 {
168 m_obj_p = ( const_cast<sc_signed*>( obj_p ) );
169 m_index = index_;
170 }
171
172public:
173
174 // destructor
175
177 {}
178
179 // copy constructor
180
182 : sc_value_base(a), m_index( a.m_index ), m_obj_p( a.m_obj_p )
183 {}
184
185 // capacity
186
187 int length() const
188 { return 1; }
189
190
191 // implicit conversion to bool
192
193 operator uint64 () const;
194 bool operator ! () const;
195 bool operator ~ () const;
196
197
198 // explicit conversions
199
200 bool value() const
201 { return operator uint64(); }
202
203 bool to_bool() const
204 { return operator uint64(); }
205
206 // concatenation support
207
208 virtual int concat_length(bool* xz_present_p) const
209 { if ( xz_present_p ) *xz_present_p = false; return 1; }
210 virtual uint64 concat_get_uint64() const
211 { return (uint64)operator uint64(); }
212 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const
213 {
214 int bit_mask = 1 << SC_BIT_INDEX(low_i);
215 int word_i = SC_DIGIT_INDEX(low_i);
216 dst_p[word_i] &= ~bit_mask;
217 return false;
218 }
219 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const
220 {
221 int bit_mask = 1 << SC_BIT_INDEX(low_i);
222 bool result; // True if non-zero.
223 int word_i = SC_DIGIT_INDEX(low_i);
224 if ( operator uint64() )
225 {
226 dst_p[word_i] |= bit_mask;
227 result = true;
228 }
229 else
230 {
231 dst_p[word_i] &= ~bit_mask;
232 result = false;
233 }
234 return result;
235 }
236
237
238 // other methods
239
240 void print( ::std::ostream& os = ::std::cout ) const
241 { os << to_bool(); }
242
243protected:
244
245 int m_index; // Bit to be selected.
246 sc_signed* m_obj_p; // Target of this bit selection.
247
248private: // disabled
249 const sc_signed_bitref_r& operator = ( const sc_signed_bitref_r& );
250};
251
252
253
254inline
255::std::ostream&
256operator<<( ::std::ostream&, const sc_signed_bitref_r& );
257
258
259// ----------------------------------------------------------------------------
260// CLASS : sc_signed_bitref
261//
262// Proxy class for sc_signed bit selection (r-value and l-value).
263// ----------------------------------------------------------------------------
264
266 : public sc_signed_bitref_r
267{
268 friend class sc_signed;
270
271protected: // constructor
272
274 {}
275
276public:
277
278 // copy constructor
279
281 : sc_signed_bitref_r( a )
282 {}
283
284 // assignment operators
285
286 const sc_signed_bitref& operator = ( const sc_signed_bitref_r& );
287 const sc_signed_bitref& operator = ( const sc_signed_bitref& );
288 const sc_signed_bitref& operator = ( bool );
289
293
294 // concatenation methods
295
296 virtual void concat_set(int64 src, int low_i);
297 virtual void concat_set(const sc_signed& src, int low_i);
298 virtual void concat_set(const sc_unsigned& src, int low_i);
299 virtual void concat_set(uint64 src, int low_i);
300
301
302 // other methods
303
304 void scan( ::std::istream& is = ::std::cin );
305
306};
307
308
309
310inline
311::std::istream&
312operator>>( ::std::istream&, sc_signed_bitref& );
313
314
315// ----------------------------------------------------------------------------
316// CLASS : sc_signed_subref_r
317//
318// Proxy class for sc_signed part selection (r-value only).
319// ----------------------------------------------------------------------------
320
322{
323 friend class sc_signed;
324 friend class sc_signed_signal;
325 friend class sc_unsigned;
326
327protected:
328
329 // constructor
330
331 sc_signed_subref_r() : sc_value_base(), m_left(0), m_obj_p(0), m_right(0)
332 {}
333
334 void initialize( const sc_signed* obj_p, int left_, int right_ )
335 {
336 m_obj_p = ( const_cast<sc_signed*>( obj_p ));
337 m_left = left_;
338 m_right = right_;
339 }
340
341
342public:
343
344 // destructor
345
347 {}
348
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
357 // capacity
358
359 int length() const
360 { return m_left >= m_right ? (m_left-m_right+1) : (m_right-m_left+1 ); }
361
362
363 // implicit conversion to sc_unsigned
364
365 operator sc_unsigned () const;
366
367 // explicit conversions
368
369 double to_double() const;
370 inline int to_int() const;
371 inline unsigned int to_uint() const;
372 inline long to_long() const;
373 inline unsigned long to_ulong() const;
374 inline int64 to_int64() const;
375 inline uint64 to_uint64() const;
376
377
378 // explicit conversion to character string
379
380 const std::string to_string( sc_numrep numrep = SC_DEC ) const;
381 const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
382
383 // shift operators
384
385 inline sc_unsigned operator<<( int v ) const;
386 inline sc_unsigned operator<<(const sc_signed& v) const;
387 inline sc_unsigned operator<<(const sc_unsigned& v) const;
388
389 inline sc_unsigned operator>>( int v ) const;
390 inline sc_unsigned operator>>(const sc_signed& v) const;
391 inline sc_unsigned operator>>(const sc_unsigned& v) const;
392
393 // concatenation support
394
395 virtual int concat_length(bool* xz_present_p) const
396 {
397 if ( xz_present_p ) *xz_present_p = false;
398 return m_left - m_right + 1;
399 }
400 virtual uint64 concat_get_uint64() const;
401 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
402 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
403
404 // reduce methods
405
406 bool and_reduce() const;
407 bool nand_reduce() const;
408 bool or_reduce() const;
409 bool nor_reduce() const;
410 bool xor_reduce() const ;
411 bool xnor_reduce() const;
412
413 // other methods
414
415 void print( ::std::ostream& os = ::std::cout ) const
416 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
417 protected:
419
420protected:
421
422 int m_left; // Left-most bit in this part selection.
423 sc_signed* m_obj_p; // Target of this part selection.
424 int m_right; // Right-most bit in this part selection.
425
426private: // disabled
427 const sc_signed_subref_r& operator = ( const sc_signed_subref_r& );
428
429};
430
431
432// functional notation for the reduce methods
433
434inline bool and_reduce( const sc_signed_subref_r& a ) {
435 return a.and_reduce();
436}
437
438inline bool nand_reduce( const sc_signed_subref_r& a ) {
439 return a.nand_reduce();
440}
441
442inline bool or_reduce( const sc_signed_subref_r& a ) {
443 return a.or_reduce();
444}
445
446inline bool nor_reduce( const sc_signed_subref_r& a ) {
447 return a.nor_reduce();
448}
449
450inline bool xor_reduce( const sc_signed_subref_r& a ) {
451 return a.xor_reduce();
452}
453
454inline bool xnor_reduce( const sc_signed_subref_r& a ) {
455 return a.xnor_reduce();
456}
457
458
459inline
460::std::ostream&
461operator<<( ::std::ostream&, const sc_signed_subref_r& );
462
463
464// ----------------------------------------------------------------------------
465// CLASS : sc_signed_subref
466//
467// Proxy class for sc_signed part selection (r-value and l-value).
468// ----------------------------------------------------------------------------
469
471 : public sc_signed_subref_r
472{
473 friend class sc_signed;
475
476
477 // constructor
478
480 {}
481
482public:
483
484 // copy constructor
485
487 : sc_signed_subref_r( a )
488 {}
489
490
491 // assignment operators
492
493 const sc_signed_subref& operator = ( const sc_signed_subref_r& a );
494 const sc_signed_subref& operator = ( const sc_signed_subref& a );
495 const sc_signed_subref& operator = ( const sc_signed& a );
496
497 const sc_signed_subref& operator = ( const sc_unsigned_subref_r& a );
498 const sc_signed_subref& operator = ( const sc_unsigned& a );
499
500 template< class T >
501 const sc_signed_subref& operator = ( const sc_generic_base<T>& a )
502 {
503 sc_unsigned temp( length() );
504 a->to_sc_unsigned(temp);
505 return operator = (temp);
506 }
507
508 const sc_signed_subref& operator = ( const char* a );
509 const sc_signed_subref& operator = ( unsigned long a );
510 const sc_signed_subref& operator = ( long a );
511 const sc_signed_subref& operator = ( unsigned int a )
512 { return operator = ( (unsigned long) a ); }
513
514 const sc_signed_subref& operator = ( int a )
515 { return operator = ( (long) a ); }
516
517 const sc_signed_subref& operator = ( uint64 a );
518 const sc_signed_subref& operator = ( int64 a );
519 const sc_signed_subref& operator = ( double a );
520 const sc_signed_subref& operator = ( const sc_int_base& a );
521 const sc_signed_subref& operator = ( const sc_uint_base& a );
522 const sc_signed_subref& operator = ( const sc_bv_base& );
523 const sc_signed_subref& operator = ( const sc_lv_base& );
524
525 // concatenation methods
526
527 virtual void concat_set(int64 src, int low_i);
528 virtual void concat_set(const sc_signed& src, int low_i);
529 virtual void concat_set(const sc_unsigned& src, int low_i);
530 virtual void concat_set(uint64 src, int low_i);
531
532 // other methods
533
534 void scan( ::std::istream& is = ::std::cin );
535
536};
537
538
539
540inline
541::std::istream&
542operator>>( ::std::istream&, sc_signed_subref& );
543
544
545// ----------------------------------------------------------------------------
546// CLASS : sc_signed
547//
548// Arbitrary precision signed number.
549// ----------------------------------------------------------------------------
550
552{
553 friend class sc_concatref;
554 friend class sc_signed_bitref_r;
555 friend class sc_signed_bitref;
556 friend class sc_signed_subref_r;
557 friend class sc_signed_subref;
558 friend class sc_unsigned;
559 friend class sc_unsigned_subref;
561 template<int W> friend class sc_bigint;
562 template<int W> friend class sc_biguint;
563 template<int W> friend class sc_int;
564 template<int W> friend class sc_uint;
565 // Needed for types using sc_signed.
566 typedef bool elemtype;
567
568public:
569 enum { SIGNED=1 };
570
571public:
572
573 // constructors
574
575 explicit inline sc_signed( int nb = sc_length_param().len() );
576#if !defined(SC_BIGINT_CONFIG_BASE_CLASS_HAS_STORAGE)
577 explicit inline sc_signed( int nb, sc_digit* digit_p );
578#endif // !defined(SC_BIGINT_CONFIG_BASE_CLASS_HAS_STORAGE)
579 sc_signed( const sc_signed& v );
580 sc_signed( const sc_unsigned& v );
581 template<class T>
582 explicit sc_signed( const sc_generic_base<T>& v );
583 explicit sc_signed( const sc_bv_base& v );
584 explicit sc_signed( const sc_lv_base& v );
585 explicit sc_signed( const sc_int_subref_r& v );
586 explicit sc_signed( const sc_uint_subref_r& v );
587 explicit sc_signed( const sc_signed_subref_r& v );
588 explicit sc_signed( const sc_unsigned_subref_r& v );
589
590 // assignment operators
591
592 const sc_signed& operator = (const sc_signed& v);
593 inline const sc_signed& operator = (const sc_signed_subref_r& a );
594
595 template< class T >
596 inline const sc_signed& operator = ( const sc_generic_base<T>& a )
597 { a->to_sc_signed(*this); return *this; }
598
599 const sc_signed& operator = (const sc_unsigned& v);
600 inline const sc_signed& operator = (const sc_unsigned_subref_r& a );
601
602 const sc_signed& operator = (const char* v);
603 const sc_signed& operator = (int64 v);
604 const sc_signed& operator = (uint64 v);
605 const sc_signed& operator = (long v);
606 const sc_signed& operator = (unsigned long v);
607
608 const sc_signed& operator = (int v)
609 { return operator=((long) v); }
610
611 const sc_signed& operator = (unsigned int v)
612 { return operator=((unsigned long) v); }
613
614 const sc_signed& operator = (double v);
615 const sc_signed& operator = (const sc_int_base& v);
616 const sc_signed& operator = (const sc_uint_base& v);
617
618 const sc_signed& operator = ( const sc_bv_base& );
619 const sc_signed& operator = ( const sc_lv_base& );
620
621#ifdef SC_INCLUDE_FX
622 const sc_signed& operator = ( const sc_fxval& );
623 const sc_signed& operator = ( const sc_fxval_fast& );
624 const sc_signed& operator = ( const sc_fxnum& );
625 const sc_signed& operator = ( const sc_fxnum_fast& );
626#endif
627
628
629 // destructor:
630
631 virtual ~sc_signed()
632 {
633 if ( digit_is_allocated() ) { delete [] digit; }
634 }
635
636 // Concatenation support:
637
639 { return digit; }
640 virtual int concat_length(bool* xz_present_p) const
641 { if ( xz_present_p ) *xz_present_p = false; return nbits; }
642 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
643 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
644 virtual uint64 concat_get_uint64() const;
645 virtual void concat_set(int64 src, int low_i);
646 virtual void concat_set(const sc_signed& src, int low_i);
647 virtual void concat_set(const sc_unsigned& src, int low_i);
648 virtual void concat_set(uint64 src, int low_i);
649
650
651
652 // Increment operators.
653 sc_signed& operator ++ ();
654 inline sc_signed operator ++ (int);
655
656 // Decrement operators.
657 sc_signed& operator -- ();
658 inline sc_signed operator -- (int);
659
660 void invalid_init( const char* type_name, int nb ) const;
661
662 // bit selection
663
664 inline void check_index( int i ) const
665 { if ( i < 0 || i >= nbits ) invalid_index(i); }
666
667 void invalid_index( int i ) const;
668
670 {
672 return pool.allocate();
673 }
674
675 sc_signed_bitref& operator [] ( int i )
676 {
677 check_index(i);
678 sc_signed_bitref* result_p = temporary_bitref();
679 result_p->initialize( this, i );
680 return *result_p;
681 }
682
683 const sc_signed_bitref_r& operator [] ( int i ) const
684 {
685 check_index(i);
686 sc_signed_bitref* result_p = temporary_bitref();
687 result_p->initialize( this, i );
688 return *result_p;
689 }
690
692 {
693 check_index(i);
694 sc_signed_bitref* result_p = temporary_bitref();
695 result_p->initialize( this, i );
696 return *result_p;
697 }
698
699 const sc_signed_bitref_r& bit( int i ) const
700 {
701 check_index(i);
702 sc_signed_bitref* result_p = temporary_bitref();
703 result_p->initialize( this, i );
704 return *result_p;
705 }
706
707
708 // part selection
709
710 // Subref operators. Help access the range of bits from the ith to
711 // jth. These indices have arbitrary precedence with respect to each
712 // other, i.e., we can have i <= j or i > j. Note the equivalence
713 // between range(i, j) and operator(i, j). Also note that
714 // operator(i, i) returns a signed number that corresponds to the
715 // bit operator[i], so these two forms are not the same.
716
717 inline void check_range( int l, int r ) const
718 {
719 if ( l < r )
720 {
721 if ( l < 0 || r >= nbits ) invalid_range(l,r);
722 }
723 else
724 {
725 if ( r < 0 || l >= nbits ) invalid_range(l,r);
726 }
727 }
728
729 void invalid_range( int l, int r ) const;
730
732 {
734 return pool.allocate();
735 }
736
737 sc_signed_subref& range( int i, int j )
738 {
739 check_range( i, j );
740 sc_signed_subref* result_p = temporary_subref();
741 result_p->initialize( this, i, j );
742 return *result_p;
743 }
744
745 const sc_signed_subref_r& range( int i, int j ) const
746 {
747 check_range( i, j );
748 sc_signed_subref* result_p = temporary_subref();
749 result_p->initialize( this, i, j );
750 return *result_p;
751 }
752
753 sc_signed_subref& operator () ( int i, int j )
754 {
755 check_range( i, j );
756 sc_signed_subref* result_p = temporary_subref();
757 result_p->initialize( this, i, j );
758 return *result_p;
759 }
760
761 const sc_signed_subref_r& operator () ( int i, int j ) const
762 {
763 check_range( i, j );
764 sc_signed_subref* result_p = temporary_subref();
765 result_p->initialize( this, i, j );
766 return *result_p;
767 }
768
769
770 // explicit conversions
771
772 double to_double() const;
773 inline int to_int() const;
774 inline unsigned int to_uint() const;
775 inline long to_long() const;
776 inline unsigned long to_ulong() const;
777 inline int64 to_int64() const;
778 inline uint64 to_uint64() const;
779
780 //inline operator bool() const { return to_uint64(); }
781
782#ifdef SC_DT_DEPRECATED
783 int to_signed() const
784 { return to_int(); }
785
786 unsigned int to_unsigned() const
787 { return to_uint(); }
788#endif
789
790 // explicit conversion to character string
791
792 const std::string to_string( sc_numrep numrep = SC_DEC ) const;
793 const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
794
795
796 // Print functions. dump prints the internals of the class.
797
798 void print( ::std::ostream& os = ::std::cout ) const
799 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
800
801 void scan( ::std::istream& is = ::std::cin );
802
803 void dump( ::std::ostream& os = ::std::cout ) const;
804
805
806 // Functions to find various properties.
807 int length() const { return nbits; } // Bit width.
808 bool iszero() const; // Is the number zero?
809 bool sign() const; // Sign.
810
811 // reduce methods
812
813 bool and_reduce() const;
814
815 bool nand_reduce() const
816 { return ( ! and_reduce() ); }
817
818 bool or_reduce() const;
819
820 bool nor_reduce() const
821 { return ( ! or_reduce() ); }
822
823 bool xor_reduce() const;
824
825 bool xnor_reduce() const
826 { return ( ! xor_reduce() ); }
827
828 // Functions to access individual bits.
829
830 // Set the ith bit with 1.
831 inline
832 void
833 set(int i)
834 {
835 if (check_if_outside(i))
836 return;
837
838 int bit_num = SC_BIT_INDEX(i);
839 int digit_num = SC_DIGIT_INDEX(i);
840
841 digit[digit_num] |= one_and_zeros(bit_num);
842 digit[digit_num] = SC_MASK_DIGIT(digit[digit_num]);
843 }
844
845
846 // Set the ith bit with 0, i.e., clear the ith bit.
847 inline
848 void
849 clear(int i)
850 {
851 if (check_if_outside(i))
852 return;
853
854 int bit_num = SC_BIT_INDEX(i);
855 int digit_num = SC_DIGIT_INDEX(i);
856
857 digit[digit_num] &= ~(one_and_zeros(bit_num));
858 digit[digit_num] = SC_MASK_DIGIT(digit[digit_num]);
859 }
860
861
862 // Return true if the bit i is 1, false otherwise. If i is outside the
863 // bounds, return 1/0 according to the sign of the number by assuming
864 // that the number has infinite length.
865
866 inline
867 bool
868 test(int i) const
869 {
870 if (check_if_outside(i)) {
871 if ( (int)digit[get_hod()] < 0 )
872 return 1;
873 else
874 return 0;
875 }
876 int bit_num = SC_BIT_INDEX(i);
877 int digit_num = SC_DIGIT_INDEX(i);
878
879 return ((digit[digit_num] & one_and_zeros(bit_num)) != 0);
880 }
881
882 void set(int i, bool v) // Set the ith bit to v.
883 { if (v) set(i); else clear(i); }
884 void invert(int i) // Negate the ith bit.
885 { if (test(i)) clear(i); else set(i); }
886
887 bool is_negative() const
888 { return (int)digit[ndigits-1] < 0; }
889
890 // Make the number equal to its mirror image.
891 void reverse();
892
893 // Get/set a packed bit representation of the number.
894 void get_packed_rep(sc_digit *buf) const;
896
897 /*
898 The comparison of the old and new semantics are as follows:
899
900 Let s = sc_signed,
901 u = sc_unsigned,
902 un = { uint64, unsigned long, unsigned int },
903 sn = { int64, long, int, char* }, and
904 OP = { +, -, *, /, % }.
905
906 Old semantics: New semantics:
907 u OP u -> u u OP u -> u
908 s OP u -> u s OP u -> s
909 u OP s -> u u OP s -> s
910 s OP s -> s s OP s -> s
911
912 u OP un = un OP u -> u u OP un = un OP u -> u
913 u OP sn = sn OP u -> u u OP sn = sn OP u -> s
914
915 s OP un = un OP s -> s s OP un = un OP s -> s
916 s OP sn = sn OP s -> s s OP sn = sn OP s -> s
917
918 In the new semantics, the result is u if both operands are u; the
919 result is s otherwise. The only exception is subtraction. The result
920 of a subtraction is always s.
921
922 The old semantics is like C/C++ semantics on integer types; the
923 new semantics is due to the VSIA C/C++ data types standard.
924 */
925
926 // FRIEND DECLARATIONS:
927
928# define SCFP friend
929# include "sc_signed_friends.h"
930# undef SCFP
931
932 // SELF-REFERENCING OPERATORS:
933
934 inline sc_signed& operator += (const sc_signed& v);
935 inline sc_signed& operator += (const sc_unsigned& v);
936 inline sc_signed& operator += (int64 v);
937 inline sc_signed& operator += (uint64 v);
938 inline sc_signed& operator += (long v);
939 inline sc_signed& operator += (unsigned long v);
940 inline sc_signed& operator += (int v);
941 inline sc_signed& operator += (unsigned int v);
942 inline sc_signed& operator += (const sc_int_base& v);
943 inline sc_signed& operator += (const sc_uint_base& v);
944
945 inline sc_signed& operator -= (const sc_signed& v);
946 inline sc_signed& operator -= (const sc_unsigned& v);
947 inline sc_signed& operator -= (int64 v);
948 inline sc_signed& operator -= (uint64 v);
949 inline sc_signed& operator -= (long v);
950 inline sc_signed& operator -= (unsigned long v);
951 inline sc_signed& operator -= (int v);
952 inline sc_signed& operator -= (unsigned int v);
953 inline sc_signed& operator -= (const sc_int_base& v);
954 inline sc_signed& operator -= (const sc_uint_base& v);
955
956 inline sc_signed& operator *= (const sc_signed& v);
957 inline sc_signed& operator *= (const sc_unsigned& v);
958 inline sc_signed& operator *= (int64 v);
959 inline sc_signed& operator *= (uint64 v);
960 inline sc_signed& operator *= (long v);
961 inline sc_signed& operator *= (unsigned long v);
962 inline sc_signed& operator *= (int v);
963 inline sc_signed& operator *= (unsigned int v);
964 inline sc_signed& operator *= (const sc_int_base& v);
965 inline sc_signed& operator *= (const sc_uint_base& v);
966
967 inline sc_signed& operator /= (const sc_signed& v);
968 inline sc_signed& operator /= (const sc_unsigned& v);
969 inline sc_signed& operator /= (int64 v);
970 inline sc_signed& operator /= (uint64 v);
971 inline sc_signed& operator /= (long v);
972 inline sc_signed& operator /= (unsigned long v);
973 inline sc_signed& operator /= (int v);
974 inline sc_signed& operator /= (unsigned int v);
975 inline sc_signed& operator /= (const sc_int_base& v);
976 inline sc_signed& operator /= (const sc_uint_base& v);
977
978 inline sc_signed& operator %= (const sc_signed& v);
979 inline sc_signed& operator %= (const sc_unsigned& v);
980 inline sc_signed& operator %= (int64 v);
981 inline sc_signed& operator %= (uint64 v);
982 inline sc_signed& operator %= (long v);
983 inline sc_signed& operator %= (unsigned long v);
984 inline sc_signed& operator %= (int v);
985 inline sc_signed& operator %= (unsigned int v);
986 inline sc_signed& operator %= (const sc_int_base& v);
987 inline sc_signed& operator %= (const sc_uint_base& v);
988
993 inline sc_signed& operator &= (long v);
994 inline sc_signed& operator &= (unsigned long v);
995 inline sc_signed& operator &= (int v);
996 inline sc_signed& operator &= (unsigned int v);
999
1004 inline sc_signed& operator |= (long v);
1005 inline sc_signed& operator |= (unsigned long v);
1006 inline sc_signed& operator |= (int v);
1007 inline sc_signed& operator |= (unsigned int v);
1010
1015 inline sc_signed& operator ^= (long v);
1016 inline sc_signed& operator ^= (unsigned long v);
1017 inline sc_signed& operator ^= (int v);
1018 inline sc_signed& operator ^= (unsigned int v);
1021
1022 // SHIFT OPERATORS:
1023
1024 // LEFT SHIFT operators:
1025
1026 inline
1028 operator<<(int v) const
1029 {
1030 if (v <= 0)
1031 return sc_signed(*this);
1032
1033 int nb = nbits + v;
1034 int nd = DIV_CEIL(nb);
1035 sc_signed result(nb, false);
1036
1037 vector_shift_left( ndigits, digit, nd, result.digit, v );
1038 result.adjust_hod();
1039
1040 return result;
1041 }
1042
1043 sc_signed operator<<(const sc_unsigned& v ) const;
1044 sc_signed operator<<( const sc_signed& v ) const { return operator<<( v.to_int() ); }
1045 sc_signed operator<<( int64 v ) const { return operator<<( (int)v ); }
1046 sc_signed operator<<( uint64 v ) const { return operator<<( (int)v ); }
1047 sc_signed operator<<( long v ) const { return operator<<( (int)v ); }
1048 sc_signed operator<<( unsigned long v ) const { return operator<<( (int)v ); }
1049 sc_signed operator<<( unsigned int v ) const { return operator<<( (int)v ); }
1050
1052 operator<<=(int v)
1053 {
1054 if (v <= 0)
1055 return *this;
1056
1057 vector_shift_left( ndigits, digit, v );
1058 adjust_hod();
1059
1060 return *this;
1061 }
1062 const sc_signed& operator<<=(const sc_unsigned& v);
1063 const sc_signed& operator<<=(const sc_signed& v) { return operator<<=( v.to_int() ); }
1064 const sc_signed& operator<<=(int64 v) { return operator<<=((int) v); }
1065 const sc_signed& operator<<=(uint64 v) { return operator<<=((int) v); }
1066 const sc_signed& operator<<=(long v) { return operator<<=((int) v); }
1067 const sc_signed& operator<<=(unsigned long v) { return operator<<=((int) v); }
1068 const sc_signed& operator<<=(unsigned int v) { return operator<<=((int) v); }
1069
1070 // RIGHT SHIFT operators:
1071
1072 inline
1073 sc_signed
1074 operator>>(int v) const
1075 {
1076 if (v <= 0) {
1077 return sc_signed(*this);
1078 }
1079 int nb = nbits - v;
1080
1081 // If we shift off the end return the sign bit.
1082
1083 if ( 0 >= nb ) {
1084 sc_signed result(1, false);
1085 result.digit[0] = 0 > (int)digit[ndigits-1] ? -1 : 0;
1086 return result;
1087 }
1088
1089 // Return a value that is the width of the shifted value:
1090
1091 sc_signed result(nb, false);
1092 if ( nbits < 33 ) {
1093 result.digit[0] = (int)digit[0] >> v;
1094 }
1095 else if ( nbits < 65 ) {
1096 int64 tmp = digit[1];
1097 tmp = (tmp << 32) | digit[0];
1098 tmp = tmp >> v;
1099 result.digit[0] = (sc_digit)tmp;
1100 if ( nb > 32 ) {
1101 result.digit[1] = (tmp >>32);
1102 }
1103 }
1104 else {
1105 vector_extract(digit, result.digit, nbits-1, v);
1106 }
1107 result.adjust_hod();
1108 return result;
1109 }
1110
1111 sc_signed operator>>(const sc_unsigned& v) const;
1112 sc_signed operator>>(const sc_signed& v) const { return operator>>( v.to_int() ); }
1113 sc_signed operator>>(int64 v) const { return operator>>( (int)v ); }
1114 sc_signed operator>>(uint64 v) const { return operator>>( (int)v ); }
1115 sc_signed operator>>(long v) const { return operator>>( (int)v ); }
1116 sc_signed operator>>(unsigned long v) const { return operator>>( (int)v ); }
1117 sc_signed operator>>(unsigned int v) const { return operator>>( (int)v ); }
1118
1119 inline
1120 const sc_signed&
1122 {
1123 if (v <= 0)
1124 return *this;
1125
1126 vector_shift_right(ndigits, digit, v, (int)digit[ndigits-1]<0 ? DIGIT_MASK:0);
1127
1128 return *this;
1129 }
1130 const sc_signed& operator>>=(const sc_unsigned& v);
1131 const sc_signed& operator>>=(const sc_signed& v) { return operator>>=( v.to_int() ); }
1132 const sc_signed& operator>>=(int64 v) { return operator>>=( (int)v ); }
1133 const sc_signed& operator>>=(uint64 v) { return operator>>=( (int)v ); }
1134 const sc_signed& operator>>=(long v) { return operator>>=( (int)v ); }
1135 const sc_signed& operator>>=(unsigned long v) { return operator>>=( (int)v ); }
1136 const sc_signed& operator>>=(unsigned int v) { return operator>>=( (int)v ); }
1137
1138 // Unary arithmetic operators
1139
1143
1144 // Bitwise NOT operator (unary).
1145
1146 friend SC_API sc_signed operator ~ (const sc_signed& u);
1147
1148protected:
1149
1150 int nbits; // number of bits in use.
1151 int ndigits; // number words in 'digits'
1152 sc_digit *digit; // storage for our value.
1153 sc_digit base_vec[SC_BASE_VEC_DIGITS>0?SC_BASE_VEC_DIGITS:1]; // make small values faster.
1154
1155#if !defined(SC_BIGINT_CONFIG_BASE_CLASS_HAS_STORAGE)
1156 bool m_free; // true if should free 'digit'.
1157public:
1158 inline bool digit_is_allocated() const { return m_free; }
1159#else
1160public:
1161 inline bool digit_is_allocated() const { return digit != (sc_digit*)base_vec; }
1162#endif
1163
1164#if defined(SC_BIGINT_CONFIG_TEMPLATE_CLASS_HAS_NO_BASE_CLASS)
1165
1166#define SC_SIGNED_TEMPS_N (1 << 15) // SC_SIGNED_TEMPS_N must be a power of 2.
1167
1168public: // Temporary object support:
1169 static sc_signed m_temporaries[SC_SIGNED_TEMPS_N];
1170 static size_t m_temporaries_i;
1171
1172 static inline sc_signed& allocate_temporary( int nb, sc_digit* digits_p )
1173 {
1174
1175 sc_signed* result_p = &m_temporaries[m_temporaries_i];
1176 m_temporaries_i = (m_temporaries_i + 1) & (SC_SIGNED_TEMPS_N-1);
1177 result_p->digit = digits_p;
1178 result_p->nbits = num_bits(nb);
1179 result_p->ndigits = DIV_CEIL(result_p->nbits);
1180 result_p->m_free = false;
1181 return *result_p;
1182 }
1183#endif // defined(SC_BIGINT_CONFIG_TEMPLATE_CLASS_HAS_NO_BASE_CLASS)
1184
1185protected:
1186
1187 inline void adjust_hod()
1188 {
1189 int shift = std::numeric_limits<sc_digit>::digits-1-SC_BIT_INDEX(nbits-1);
1190 shift = shift > 0 ? shift : 0;
1191 unsigned long long tmp = (std::make_signed<sc_digit>::type) (digit[ndigits-1] << shift);
1192 digit[ndigits-1] = (sc_digit)(tmp >> shift);
1193 }
1194
1195
1196public: // back door access:
1197 inline int get_actual_length() const { return nbits; }
1198 inline sc_digit* get_digits() const { return digit; }
1199 inline sc_digit* get_digits() { return digit; }
1200 inline int get_digits_n() const { return ndigits; }
1201 inline int get_hod() const { return ndigits-1; }
1202
1203private:
1204
1205 // Private constructors:
1206
1207 // Constructor for sc_signed<W>:
1208
1209 explicit sc_signed( int nb, bool zero );
1210
1211 // Create a copy of v with sign s.
1212 sc_signed(const sc_signed& v, small_type s);
1213 sc_signed(const sc_unsigned& v, small_type s);
1214
1215 // Private member functions. The called functions are inline functions.
1216
1217 static int num_bits(int nb) { return nb; }
1218
1219 bool check_if_outside(int bit_num) const;
1220
1221 void makezero() { vector_zero( 0, ndigits, digit ); }
1222
1223};
1224
1225// functional notation for the reduce methods
1226
1227inline bool and_reduce( const sc_signed& a ) { return a.and_reduce(); }
1228
1229inline bool nand_reduce( const sc_signed& a ) { return a.nand_reduce(); }
1230
1231inline bool or_reduce( const sc_signed& a ) { return a.or_reduce(); }
1232
1233inline bool nor_reduce( const sc_signed& a ) { return a.nor_reduce(); }
1234
1235inline bool xor_reduce( const sc_signed& a ) { return a.xor_reduce(); }
1236
1237inline bool xnor_reduce( const sc_signed& a ) { return a.xnor_reduce(); }
1238
1239
1240
1241inline
1242::std::ostream&
1243operator<<( ::std::ostream&, const sc_signed& );
1244
1245inline
1246::std::istream&
1247operator>>( ::std::istream&, sc_signed& );
1248
1249
1250
1251inline
1252::std::ostream&
1253operator<<( ::std::ostream& os, const sc_signed_bitref_r& a )
1254{
1255 a.print( os );
1256 return os;
1257}
1258
1259
1260inline
1261::std::istream&
1262operator>>( ::std::istream& is, sc_signed_bitref& a )
1263{
1264 a.scan( is );
1265 return is;
1266}
1267
1268
1269// ----------------------------------------------------------------------------
1270// CLASS : sc_signed_subref_r
1271//
1272// Proxy class for sc_signed part selection (r-value only).
1273// ----------------------------------------------------------------------------
1274
1275
1276// reduce methods
1277
1279{
1280 const sc_signed* target_p = m_obj_p;
1281 for ( int i = m_right; i <= m_left; i++ )
1282 if ( !target_p->test(i) ) return false;
1283 return true;
1284}
1285
1287{
1288 return !and_reduce();
1289}
1290
1292{
1293 const sc_signed* target_p = m_obj_p;
1294 for ( int i = m_right; i <= m_left; i++ )
1295 if ( target_p->test(i) ) return true;
1296 return false;
1297}
1298
1300{
1301 return !or_reduce();
1302}
1303
1305{
1306 int odd;
1307 const sc_signed* target_p = m_obj_p;
1308 odd = 0;
1309 for ( int i = m_right; i <= m_left; i++ )
1310 if ( target_p->test(i) ) odd = ~odd;
1311 return odd ? true : false;
1312}
1313
1315{
1316 return !xor_reduce();
1317}
1318
1319inline
1320::std::ostream&
1321operator<<( ::std::ostream& os, const sc_signed_subref_r& a )
1322{
1323 a.print( os );
1324 return os;
1325}
1326
1327
1328// ----------------------------------------------------------------------------
1329// CLASS : sc_signed_subref
1330//
1331// Proxy class for sc_signed part selection (r-value and l-value).
1332// ----------------------------------------------------------------------------
1333
1334// assignment operators
1335
1336inline
1337const sc_signed_subref&
1339{
1340 sc_signed aa( length() );
1341 return ( *this = aa = a );
1342}
1343
1344
1345
1346
1347inline
1348::std::istream&
1349operator>>( ::std::istream& is, sc_signed_subref& a )
1350{
1351 a.scan( is );
1352 return is;
1353}
1354
1355
1356
1357// ----------------------------------------------------------------------------
1358// CLASS : sc_signed
1359//
1360// Arbitrary precision signed number.
1361// ----------------------------------------------------------------------------
1362
1363template<class T>
1365{
1366 int nb = v->length();
1367 if( nb > 0 ) {
1368 nbits = num_bits( nb );
1369 } else {
1370 char msg[BUFSIZ];
1371 std::snprintf(msg, sizeof(msg),
1372 "sc_unsigned( sc_generic_base<T> ) : nb = %d is not valid", nb);
1374 }
1376 if ( ndigits > SC_BASE_VEC_DIGITS ) {
1377 digit = new sc_digit[ndigits];
1378 SC_FREE_DIGIT(true)
1379 }
1380 else {
1381 digit = base_vec;
1382 SC_FREE_DIGIT(false)
1383 }
1384 makezero();
1385 v->to_sc_signed(*this);
1386}
1387
1388
1389
1390inline
1391::std::ostream&
1392operator<<( ::std::ostream& os, const sc_signed& a )
1393{
1394 a.print( os );
1395 return os;
1396}
1397
1398inline
1399::std::istream&
1400operator>>( ::std::istream& is, sc_signed& a )
1401{
1402 a.scan( is );
1403 return is;
1404}
1405
1406inline
1407uint64
1409{
1410 int right = m_right;
1411 if ( right > m_left ) { return to_uint64_reversed(); }
1412 sc_digit* digits = m_obj_p->get_raw();
1413 int adjust = right + 63;
1414 int left = ( adjust < m_left ) ? adjust : m_left;
1415 int left_hob;
1416 int left_i = SC_DIGIT_INDEX(left);
1417 sc_digit mask;
1418 int right_i = SC_DIGIT_INDEX(right);
1419 int right_lob;
1420 unsigned long long result;
1421 switch( left_i - right_i )
1422 {
1423 case 0: // all in same word.
1424 mask = ~((sc_digit)-2<<(left-right));
1425 right_lob = SC_BIT_INDEX(right);
1426 result = (digits[right_i] >> right_lob) & mask;
1427 break;
1428 case 1: // in two words
1429 left_hob = SC_BIT_INDEX(left);
1430 right_lob = SC_BIT_INDEX(right);
1431 mask = ~(((sc_digit)-2)<<left_hob);
1432 result = digits[left_i]&mask;
1433 result = (result << (BITS_PER_DIGIT-right_lob)) |
1434 (digits[right_i]>>right_lob);
1435 break;
1436 default: // in three words
1437 left_hob = SC_BIT_INDEX(left);
1438 right_lob = SC_BIT_INDEX(right);
1439 mask = ~(((sc_digit)-2)<<left_hob);
1440 result = (digits[left_i]&mask);
1441 result = (result << BITS_PER_DIGIT) | digits[right_i+1];
1442 result = (result << (BITS_PER_DIGIT-right_lob)) |
1443 (digits[right_i]>>right_lob);
1444 break;
1445 }
1446 return result;
1447}
1448
1449inline
1450int64
1452{
1453 return (int64)to_uint64();
1454}
1455
1456inline
1457int
1459{
1460 return (int)to_uint64();
1461}
1462
1463inline
1464unsigned int
1466{
1467 return (unsigned int)to_uint64();
1468}
1469
1470inline
1471long
1473{
1474 return (long)to_uint64();
1475}
1476
1477inline
1478unsigned long
1480{
1481 return (unsigned long)to_uint64();
1482}
1483
1484// +----------------------------------------------------------------------------
1485// |"sc_signed::to_XXXX"
1486// |
1487// | These functions return an object instance's value as the requested
1488// | native C++ type.
1489// |
1490// | Notes:
1491// | (1) These are set up for BITS_PER_DIGIT == 32.
1492// | Result:
1493// | Native C++ type containing the object instance's value.
1494// +----------------------------------------------------------------------------
1495inline
1496int
1498{
1499 int result;
1500
1501 result = (int)digit[0];
1502 return result;
1503}
1504
1505inline
1506unsigned int
1508{
1509 unsigned int result = (unsigned int)digit[0];
1510 return result;
1511}
1512
1513inline
1514int64
1516{
1517 int64 result;
1518
1519 if ( ndigits == 1 ) {
1520 result = to_int();
1521 }
1522 else {
1523 result = ( (int64)digit[1] << BITS_PER_DIGIT ) | digit[0];
1524 }
1525 return result;
1526}
1527
1528inline
1529uint64
1531{
1532 uint64 result;
1533
1534 if ( ndigits == 1 ) {
1535 result = to_uint();
1536 }
1537 else {
1538 result = ( (uint64)digit[1] << BITS_PER_DIGIT ) | digit[0];
1539 }
1540 return result;
1541}
1542
1543inline
1544long
1546{
1547 long result = ( sizeof(long) < 5 ) ? to_int() : (long)to_int64();
1548 return result;
1549}
1550
1551
1552inline
1553unsigned long
1555{
1556 unsigned long result =
1557 ( sizeof(unsigned long) < 5 ) ? to_uint() : (unsigned long)to_uint64();
1558 return result;
1559}
1560
1561#if !defined(SC_BIGINT_CONFIG_BASE_CLASS_HAS_STORAGE)
1562// +----------------------------------------------------------------------------
1563// |"sc_signed::sc_signed"
1564// |
1565// | This is the object constructor from sc_bigint<W>. It uses the supplied
1566// | value buffer, that will already have been initialized.
1567// |
1568// | Arguments:
1569// | nb = number of bits the object instance needs to support.
1570// | digits_p = storage from sc_bigint<W> to use as our storage.
1571// +----------------------------------------------------------------------------
1572inline
1573sc_signed::sc_signed( int nb, sc_digit* digits_p ) :
1574 nbits(nb), ndigits( DIV_CEIL(nb) )
1575{
1576# if defined(SC_BIGINT_CONFIG_TEMPLATE_CLASS_HAS_STORAGE)
1577 if ( ndigits <= SC_BASE_VEC_DIGITS ) {
1578 digit = base_vec;
1579 }
1580 else {
1581 digit = digits_p;
1582 }
1583 SC_FREE_DIGIT(false)
1584# else // TEMPLATE_CLASS_HAS_NO_BASE_CLASS
1585 digit = digits_p;
1586 SC_FREE_DIGIT(false)
1587# endif
1588}
1589#endif // !defined(SC_BIGINT_CONFIG_BASE_CLASS_HAS_STORAGE)
1590
1591// +----------------------------------------------------------------------------
1592// |"sc_signed::sc_signed"
1593// |
1594// | This is the object constructor for sc_bigint<W>.
1595// |
1596// | Arguments:
1597// | nb = number of bits the object instance needs to support.
1598// | zero = true if the object's digits should be zeroed.
1599// +----------------------------------------------------------------------------
1600inline
1601sc_signed::sc_signed( int nb, bool zero ) :
1602 nbits(nb), ndigits( DIV_CEIL(nb) )
1603{
1604 if ( ndigits <= SC_BASE_VEC_DIGITS ) {
1605 digit = base_vec;
1606 SC_FREE_DIGIT(false)
1607 }
1608 else {
1609 digit = new sc_digit[ndigits];
1610 SC_FREE_DIGIT(true)
1611 }
1612 if ( zero ) {
1613 makezero();
1614 }
1615}
1616
1617// +----------------------------------------------------------------------------
1618// |"sc_signed::sc_signed"
1619// |
1620// | This is the explicit object instance constructor.
1621// |
1622// | Arguments:
1623// | nb = number of bits the object instance needs to support.
1624// +----------------------------------------------------------------------------
1625inline
1627 sc_value_base(), nbits(), ndigits(), digit()
1628{
1629 if( nb > 0 ) {
1630 nbits = num_bits( nb );
1631 } else {
1632 char msg[BUFSIZ];
1633 std::snprintf(msg, sizeof(msg), "%s::%s( int nb ) : nb = %d is not valid",
1634 "sc_signed", "sc_signed", nb );
1636 }
1638 if ( ndigits > ( (int)(sizeof(base_vec)/sizeof(sc_digit)) ) ) {
1639 digit = new sc_digit[ndigits];
1640 SC_FREE_DIGIT(true)
1641 }
1642 else {
1643 digit = base_vec;
1644 SC_FREE_DIGIT(false)
1645 }
1646 makezero();
1647}
1648
1649} // namespace sc_dt
1650
1651#endif
#define SC_DIGIT_INDEX(BIT_INDEX)
Definition: sc_nbdefs.h:186
#define DIGIT_MASK
Definition: sc_nbdefs.h:168
#define DIV_CEIL(x)
Definition: sc_nbdefs.h:212
#define SC_BIT_INDEX(BIT)
Definition: sc_nbdefs.h:185
#define SC_MASK_DIGIT(v)
Definition: sc_nbdefs.h:187
#define BITS_PER_DIGIT
Definition: sc_nbdefs.h:164
#define SC_FREE_DIGIT(FLAG)
Definition: sc_nbdefs.h:119
#define SC_BASE_VEC_DIGITS
Definition: sc_nbdefs.h:127
#define SC_API
Definition: sc_cmnhdr.h:148
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report.h:217
const char SC_ID_INIT_FAILED_[]
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
int small_type
Definition: sc_nbdefs.h:137
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
const sc_big_op_info< WL, true, WR, true >::add_result operator+(const sc_bigint< WL > &left, const sc_bigint< WR > &right)
Definition: sc_big_ops.h:125
sc_numrep
Definition: sc_string.h:56
@ SC_DEC
Definition: sc_string.h:60
X & operator^=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:613
sc_carry one_and_zeros(int n)
Definition: sc_nbutils.h:115
unsigned long long uint64
Definition: sc_nbdefs.h:216
void vector_extract(const sc_digit *source_p, sc_digit *destination_p, const int high_bit, const int low_bit)
const sc_big_op_info< WL, true, WR, true >::sub_result operator-(const sc_bigint< WL > &left, const sc_bigint< WR > &right)
Definition: sc_big_ops.h:884
void vector_zero(int from_i, int to_i, sc_digit *target_p)
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)
sc_lv_base reverse(const sc_proxy< X > &x)
Definition: sc_lv_base.h:852
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
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
void vector_shift_left(const int from_digits_n, const sc_digit *from_p, const int to_digits_n, sc_digit *to_p, const int shift_n)
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:388
void vector_shift_right(const int target_n, sc_digit *target_p, int bits_n, const sc_digit fill)
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
virtual ~sc_signed_bitref_r()
Definition: sc_signed.h:176
virtual int concat_length(bool *xz_present_p) const
Definition: sc_signed.h:208
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
Definition: sc_signed.h:212
void initialize(const sc_signed *obj_p, int index_)
Definition: sc_signed.h:166
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
Definition: sc_signed.h:219
sc_signed_bitref_r(const sc_signed_bitref_r &a)
Definition: sc_signed.h:181
virtual uint64 concat_get_uint64() const
Definition: sc_signed.h:210
void print(::std::ostream &os=::std::cout) const
Definition: sc_signed.h:240
virtual void concat_set(uint64 src, int low_i)
virtual void concat_set(int64 src, int low_i)
sc_signed_bitref(const sc_signed_bitref &a)
Definition: sc_signed.h:280
void scan(::std::istream &is=::std::cin)
virtual void concat_set(const sc_signed &src, int low_i)
virtual void concat_set(const sc_unsigned &src, int low_i)
double to_double() const
virtual int concat_length(bool *xz_present_p) const
Definition: sc_signed.h:395
unsigned long to_ulong() const
Definition: sc_signed.h:1479
virtual uint64 concat_get_uint64() const
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
const std::string to_string(sc_numrep numrep=SC_DEC) const
const std::string to_string(sc_numrep numrep, bool w_prefix) const
void initialize(const sc_signed *obj_p, int left_, int right_)
Definition: sc_signed.h:334
bool nand_reduce() const
Definition: sc_signed.h:1286
int64 to_int64() const
Definition: sc_signed.h:1451
virtual ~sc_signed_subref_r()
Definition: sc_signed.h:346
bool xnor_reduce() const
Definition: sc_signed.h:1314
void print(::std::ostream &os=::std::cout) const
Definition: sc_signed.h:415
uint64 to_uint64() const
Definition: sc_signed.h:1408
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
unsigned int to_uint() const
Definition: sc_signed.h:1465
sc_signed_subref_r(const sc_signed_subref_r &a)
Definition: sc_signed.h:351
uint64 to_uint64_reversed() const
const sc_signed_subref & operator=(const sc_signed_subref_r &a)
virtual void concat_set(const sc_unsigned &src, int low_i)
virtual void concat_set(uint64 src, int low_i)
virtual void concat_set(const sc_signed &src, int low_i)
void scan(::std::istream &is=::std::cin)
sc_signed_subref(const sc_signed_subref &a)
Definition: sc_signed.h:486
virtual void concat_set(int64 src, int low_i)
const std::string to_string(sc_numrep numrep, bool w_prefix) const
sc_signed operator>>(int64 v) const
Definition: sc_signed.h:1113
void check_range(int l, int r) const
Definition: sc_signed.h:717
void invalid_range(int l, int r) const
const sc_signed & operator<<=(unsigned int v)
Definition: sc_signed.h:1068
void clear(int i)
Definition: sc_signed.h:849
sc_signed operator>>(const sc_signed &v) const
Definition: sc_signed.h:1112
sc_signed operator>>(int v) const
Definition: sc_signed.h:1074
const sc_signed & operator>>=(const sc_signed &v)
Definition: sc_signed.h:1131
int get_actual_length() const
Definition: sc_signed.h:1197
void print(::std::ostream &os=::std::cout) const
Definition: sc_signed.h:798
void set(int i)
Definition: sc_signed.h:833
const sc_signed & operator>>=(int v)
Definition: sc_signed.h:1121
const sc_signed & operator<<=(uint64 v)
Definition: sc_signed.h:1065
void invalid_index(int i) const
virtual void concat_set(const sc_unsigned &src, int low_i)
sc_signed operator>>(unsigned int v) const
Definition: sc_signed.h:1117
sc_signed_subref & range(int i, int j)
Definition: sc_signed.h:737
sc_signed_subref * temporary_subref() const
Definition: sc_signed.h:731
bool test(int i) const
Definition: sc_signed.h:868
sc_signed operator<<(unsigned int v) const
Definition: sc_signed.h:1049
unsigned int to_uint() const
Definition: sc_signed.h:1507
const sc_signed_subref_r & range(int i, int j) const
Definition: sc_signed.h:745
bool digit_is_allocated() const
Definition: sc_signed.h:1158
bool is_negative() const
Definition: sc_signed.h:887
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const
void set(int i, bool v)
Definition: sc_signed.h:882
sc_signed operator<<(unsigned long v) const
Definition: sc_signed.h:1048
int get_hod() const
Definition: sc_signed.h:1201
bool and_reduce() const
const sc_signed & operator>>=(unsigned long v)
Definition: sc_signed.h:1135
sc_signed operator>>(unsigned long v) const
Definition: sc_signed.h:1116
bool nor_reduce() const
Definition: sc_signed.h:820
sc_digit * digit
Definition: sc_signed.h:1152
const sc_signed & operator>>=(uint64 v)
Definition: sc_signed.h:1133
void set_packed_rep(sc_digit *buf)
int64 to_int64() const
Definition: sc_signed.h:1515
sc_digit * get_digits() const
Definition: sc_signed.h:1198
long to_long() const
Definition: sc_signed.h:1545
const sc_signed & operator<<=(const sc_signed &v)
Definition: sc_signed.h:1063
const sc_signed & operator>>=(int64 v)
Definition: sc_signed.h:1132
void invalid_init(const char *type_name, int nb) const
int to_int() const
Definition: sc_signed.h:1497
bool sign() const
sc_signed operator<<(long v) const
Definition: sc_signed.h:1047
sc_signed operator<<(const sc_signed &v) const
Definition: sc_signed.h:1044
virtual int concat_length(bool *xz_present_p) const
Definition: sc_signed.h:640
unsigned long to_ulong() const
Definition: sc_signed.h:1554
sc_signed operator<<(uint64 v) const
Definition: sc_signed.h:1046
virtual uint64 concat_get_uint64() const
const sc_signed & operator>>=(unsigned int v)
Definition: sc_signed.h:1136
bool xnor_reduce() const
Definition: sc_signed.h:825
virtual ~sc_signed()
Definition: sc_signed.h:631
sc_signed operator>>(uint64 v) const
Definition: sc_signed.h:1114
const sc_signed_bitref_r & bit(int i) const
Definition: sc_signed.h:699
bool iszero() const
void invert(int i)
Definition: sc_signed.h:884
uint64 to_uint64() const
Definition: sc_signed.h:1530
void scan(::std::istream &is=::std::cin)
int get_digits_n() const
Definition: sc_signed.h:1200
void dump(::std::ostream &os=::std::cout) const
int length() const
Definition: sc_signed.h:807
sc_signed operator<<(int64 v) const
Definition: sc_signed.h:1045
virtual void concat_set(uint64 src, int low_i)
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const
sc_signed operator>>(long v) const
Definition: sc_signed.h:1115
sc_digit base_vec[SC_BASE_VEC_DIGITS >0?SC_BASE_VEC_DIGITS:1]
Definition: sc_signed.h:1153
bool nand_reduce() const
Definition: sc_signed.h:815
sc_digit * get_raw() const
Definition: sc_signed.h:638
const sc_signed & operator<<=(int64 v)
Definition: sc_signed.h:1064
sc_signed_bitref * temporary_bitref() const
Definition: sc_signed.h:669
sc_digit * get_digits()
Definition: sc_signed.h:1199
const sc_signed & operator<<=(long v)
Definition: sc_signed.h:1066
const std::string to_string(sc_numrep numrep=SC_DEC) const
virtual void concat_set(int64 src, int low_i)
bool xor_reduce() const
void get_packed_rep(sc_digit *buf) const
sc_signed(int nb=sc_length_param().len())
Definition: sc_signed.h:1626
virtual void concat_set(const sc_signed &src, int low_i)
const sc_signed & operator>>=(long v)
Definition: sc_signed.h:1134
void check_index(int i) const
Definition: sc_signed.h:664
const sc_signed & operator<<=(unsigned long v)
Definition: sc_signed.h:1067
bool or_reduce() const
sc_signed_bitref & bit(int i)
Definition: sc_signed.h:691