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

Generated on Wed Dec 21 2022 10:22:42 for gem5 by doxygen 1.9.1