source: sources/src/sc_bigint.h @ 27

Last change on this file since 27 was 27, checked in by buchmann, 15 years ago

SystemCASS now uses autoconf/automake to build the API. Regression tests still
use the old Makefiles.
(thanks to Nicolas Pouillon)

The library directory no longer is "lib-arch-system". The directory now is "lib-linux". Everyone needs to pay attention about SYSTEMCASS environment variable.

Changes:

  • system header includes
  • Add includes to config.h (generated by autoconf/automake)
  • test:
    • linux preprocessor macro instead of _WIN32
    • CONFIG_DEBUG instead of DEBUG

Removes:

  • Makefile
  • guess_endianness.cc
  • guess_os.sh
  • assert.h (we now use standard assert.h)
  • Options.def
File size: 5.2 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :                 sc_bigint.h                      |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                                                             |
9| Date    :                   09_07_2004                      |
10|                                                             |
11\------------------------------------------------------------*/
12#ifndef __SC_BIGINT_H__
13#define __SC_BIGINT_H__
14
15#include <sc_bit.h>
16#include <sc_logic.h>
17#include <sc_bv.h>
18
19// ----------------------------------------------------------------------------
20//  CLASS : sc_bigint<W>
21//
22// ----------------------------------------------------------------------------
23
24#include "sc_nbdefs.h"
25
26namespace sc_dt {
27
28//
29#define MASK32(W) ((~ (const uint32)0) >> (sizeof (uint32) * 8 - W))
30#define MASK64(W) ((~ (const uint64)0) >> (sizeof (uint64) * 8 - W))
31//
32
33template<int W> struct s_bigint_type { typedef uint64 uint_type;};
34#define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint16 uint_type; }// not declared as uint16 because << operator threats like a character
35DECLAR_BIGINT_TYPE( 1);
36DECLAR_BIGINT_TYPE( 2);
37DECLAR_BIGINT_TYPE( 3);
38DECLAR_BIGINT_TYPE( 4);
39DECLAR_BIGINT_TYPE( 5);
40DECLAR_BIGINT_TYPE( 6);
41DECLAR_BIGINT_TYPE( 7);
42DECLAR_BIGINT_TYPE( 8);
43#undef DECLAR_BIGINT_TYPE
44#define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint16 uint_type; }
45DECLAR_BIGINT_TYPE( 9);
46DECLAR_BIGINT_TYPE(10);
47DECLAR_BIGINT_TYPE(11);
48DECLAR_BIGINT_TYPE(12);
49DECLAR_BIGINT_TYPE(13);
50DECLAR_BIGINT_TYPE(14);
51DECLAR_BIGINT_TYPE(15);
52DECLAR_BIGINT_TYPE(16);
53#undef DECLAR_BIGINT_TYPE
54#define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint32 uint_type; }
55DECLAR_BIGINT_TYPE(17);
56DECLAR_BIGINT_TYPE(18);
57DECLAR_BIGINT_TYPE(19);
58DECLAR_BIGINT_TYPE(20);
59DECLAR_BIGINT_TYPE(21);
60DECLAR_BIGINT_TYPE(22);
61DECLAR_BIGINT_TYPE(23);
62DECLAR_BIGINT_TYPE(24);
63DECLAR_BIGINT_TYPE(25);
64DECLAR_BIGINT_TYPE(26);
65DECLAR_BIGINT_TYPE(27);
66DECLAR_BIGINT_TYPE(28);
67DECLAR_BIGINT_TYPE(29);
68DECLAR_BIGINT_TYPE(30);
69DECLAR_BIGINT_TYPE(31);
70DECLAR_BIGINT_TYPE(32);
71#undef DECLAR_BIGINT_TYPE
72
73template< int W /* = SC_INTWIDTH */>
74class sc_bigint
75{
76  typedef sc_bigint<W>                     this_type;
77  typedef typename s_int_type<W>::int_type  data_type;
78
79  typedef data_type sc_uint_subref;
80  typedef data_type sc_uint_subref_r;
81
82        union {
83          data_type valW:W;
84    bool      valB[W];
85                data_type val;
86        };
87        void check () 
88        { if (W > 64) { std::cerr << "sc_bigint with W > 64 is not supported.\n"; exit (20040528); } }
89public:
90  sc_bigint() { check (); val = 0; }
91  sc_bigint(data_type val_) { check (); val = 0; write (val_); }
92  template <int W2> explicit sc_bigint (const sc_bigint<W2> &val_) { write (val_.read());}
93
94  inline const data_type& read() const { return val; }
95  inline operator const data_type& () const { return read (); }
96//  inline void write(int64 val_) { val = val_ & MASK64(W); }
97//  inline void write(signed int val_)   { val = val_ & MASK32(W); }
98  inline void write(data_type val_)   { valW = val_; }
99  template <int W2> inline void write (const sc_bigint<W2> val_) { write (val_.read ()); }
100  inline void write (const sc_bigint<W> val_) { write (val_.read()); };
101        template <typename T> inline sc_bigint& operator = (const T& val_) { write (val_); return *this; }
102
103  inline uint32         to_uint   () const {return val & MASK32(W);};
104  inline int32          to_int    () const {return val & MASK32(W);};
105  inline uint64         to_uint64 () const {return val & MASK64(W);};
106  inline int64          to_int64  () const {return val & MASK64(W);};
107
108  template <typename T>
109  inline sc_bigint& operator <<= (T v)
110  { valW <<= v; return *this; }
111  template <typename T>
112  inline sc_bigint& operator >>= (T v)
113  { valW >>= v; return *this; }
114  template <typename T>
115  inline sc_bigint& operator += (T v)
116  { valW += v; return *this; }
117  template <typename T>
118  inline sc_bigint& operator -= (T v)
119  { valW -= v; return *this; }
120  template <typename T>
121  inline sc_bigint& operator *= (T v)
122  { valW *= v; return *this; }
123  template <typename T>
124  inline sc_bigint& operator /= (T v)
125  { valW /= v; return *this; }
126  template <typename T>
127  inline sc_bigint& operator %= (T v)
128  { valW %= v; return *this; }
129  template <typename T>
130  inline sc_bigint& operator &= (T v)
131  { valW &= v; return *this; }
132  template <typename T>
133  inline sc_bigint& operator |= (T v)
134  { valW |= v; return *this; }
135  template <typename T>
136  inline sc_bigint& operator ^= (T v)
137  { valW ^= v; return *this; }
138  inline sc_uint_bit_ref& operator [] (int v)
139  { return valB[v]; }
140  inline sc_uint_bit_ref_r& operator [] (int v) const
141  { return valB[v]; }
142  inline sc_uint_subref range (int left, int right)
143  { return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; }
144  inline sc_uint_subref_r range (int left, int right) const
145  { return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right; }
146};
147
148} /* end of sc_dt namespace */
149
150#endif /* __SC_BIGINT_H__ */
Note: See TracBrowser for help on using the repository browser.