Changeset 52 for sources/src/sc_bigint.h


Ignore:
Timestamp:
Jan 22, 2013, 4:23:22 PM (11 years ago)
Author:
meunier
Message:

Code formatting in all source files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/sc_bigint.h

    r27 r52  
    11/*------------------------------------------------------------\
    2 |                                                             |
    3 | Tool    :                  systemcass                       |
    4 |                                                             |
    5 | File    :                 sc_bigint.h                      |
    6 |                                                             |
    7 | Author  :                 Buchmann Richard                  |
    8 |                                                             |
    9 | Date    :                   09_07_2004                      |
    10 |                                                             |
    11 \------------------------------------------------------------*/
     2  |                                                             |
     3  | Tool    :                  systemcass                       |
     4  |                                                             |
     5  | File    :                 sc_bigint.h                      |
     6  |                                                             |
     7  | Author  :                 Buchmann Richard                  |
     8  |                                                             |
     9  | Date    :                   09_07_2004                      |
     10  |                                                             |
     11  \------------------------------------------------------------*/
    1212#ifndef __SC_BIGINT_H__
    1313#define __SC_BIGINT_H__
     
    2626namespace sc_dt {
    2727
    28 //
    2928#define MASK32(W) ((~ (const uint32)0) >> (sizeof (uint32) * 8 - W))
    3029#define MASK64(W) ((~ (const uint64)0) >> (sizeof (uint64) * 8 - W))
    31 //
    3230
    3331template<int W> struct s_bigint_type { typedef uint64 uint_type;};
    3432#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
    35 DECLAR_BIGINT_TYPE( 1);
    36 DECLAR_BIGINT_TYPE( 2);
    37 DECLAR_BIGINT_TYPE( 3);
    38 DECLAR_BIGINT_TYPE( 4);
    39 DECLAR_BIGINT_TYPE( 5);
    40 DECLAR_BIGINT_TYPE( 6);
    41 DECLAR_BIGINT_TYPE( 7);
    42 DECLAR_BIGINT_TYPE( 8);
     33DECLAR_BIGINT_TYPE(1);
     34DECLAR_BIGINT_TYPE(2);
     35DECLAR_BIGINT_TYPE(3);
     36DECLAR_BIGINT_TYPE(4);
     37DECLAR_BIGINT_TYPE(5);
     38DECLAR_BIGINT_TYPE(6);
     39DECLAR_BIGINT_TYPE(7);
     40DECLAR_BIGINT_TYPE(8);
    4341#undef DECLAR_BIGINT_TYPE
     42
    4443#define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint16 uint_type; }
    45 DECLAR_BIGINT_TYPE( 9);
     44DECLAR_BIGINT_TYPE(9);
    4645DECLAR_BIGINT_TYPE(10);
    4746DECLAR_BIGINT_TYPE(11);
     
    5251DECLAR_BIGINT_TYPE(16);
    5352#undef DECLAR_BIGINT_TYPE
     53
    5454#define DECLAR_BIGINT_TYPE(W) template<> struct s_bigint_type<W> { typedef uint32 uint_type; }
    5555DECLAR_BIGINT_TYPE(17);
     
    7272
    7373template< int W /* = SC_INTWIDTH */>
    74 class 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); } }
    89 public:
    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; }
     74class sc_bigint {
     75    typedef sc_bigint<W> this_type;
     76    typedef typename s_int_type<W>::int_type data_type;
     77
     78    typedef data_type sc_uint_subref;
     79    typedef data_type sc_uint_subref_r;
     80
     81    union {
     82        data_type valW:W;
     83        bool valB[W];
     84        data_type val;
     85    };
     86   
     87    void check() {
     88        if (W > 64) {
     89            std::cerr << "sc_bigint with W > 64 is not supported.\n";
     90            exit (20040528);
     91        }
     92    }
     93
     94    public:
     95    sc_bigint() {
     96        check ();
     97        val = 0;
     98    }
     99
     100    sc_bigint(data_type val_) {
     101        check ();
     102        val = 0;
     103        write (val_);
     104    }
     105
     106    template <int W2> explicit sc_bigint(const sc_bigint<W2> & val_) {
     107        write (val_.read());
     108    }
     109
     110    inline const data_type & read() const {
     111        return val;
     112    }
     113
     114    inline operator const data_type & () const {
     115        return read ();
     116    }
     117
     118    //  inline void write(int64 val_) { val = val_ & MASK64(W); }
     119    //  inline void write(signed int val_)   { val = val_ & MASK32(W); }
     120   
     121    inline void write(data_type val_) {
     122        valW = val_;
     123    }
     124   
     125    template <int W2> inline void write (const sc_bigint<W2> val_) {
     126        write (val_.read ());
     127    }
     128
     129    inline void write (const sc_bigint<W> val_) {
     130        write (val_.read());
     131    }
     132
     133    template <typename T> inline sc_bigint & operator = (const T & val_) {
     134        write (val_);
     135        return *this;
     136    }
     137
     138    inline uint32 to_uint() const {
     139        return val & MASK32(W);
     140    }
     141
     142    inline int32 to_int() const {
     143        return val & MASK32(W);
     144    }
     145
     146    inline uint64 to_uint64() const {
     147        return val & MASK64(W);
     148    }
     149
     150    inline int64 to_int64() const {
     151        return val & MASK64(W);
     152    }
     153
     154    template <typename T>
     155    inline sc_bigint & operator <<= (T v) {
     156        valW <<= v;
     157        return *this;
     158    }
     159
     160    template <typename T>
     161    inline sc_bigint & operator >>= (T v) {
     162        valW >>= v;
     163        return *this;
     164    }
     165
     166    template <typename T>
     167    inline sc_bigint & operator += (T v) {
     168        valW += v;
     169        return *this;
     170    }
     171
     172    template <typename T>
     173    inline sc_bigint & operator -= (T v) {
     174        valW -= v;
     175        return *this;
     176    }
     177
     178    template <typename T>
     179    inline sc_bigint & operator *= (T v) {
     180        valW *= v;
     181        return *this;
     182    }
     183
     184    template <typename T>
     185    inline sc_bigint & operator /= (T v) {
     186        valW /= v;
     187        return *this;
     188    }
     189
     190    template <typename T>
     191    inline sc_bigint & operator %= (T v) {
     192        valW %= v;
     193        return *this;
     194    }
     195
     196    template <typename T>
     197    inline sc_bigint & operator &= (T v) {
     198        valW &= v;
     199        return *this;
     200    }
     201
     202    template <typename T>
     203    inline sc_bigint & operator |= (T v) {
     204        valW |= v;
     205        return *this;
     206    }
     207
     208    template <typename T>
     209    inline sc_bigint & operator ^= (T v) {
     210        valW ^= v;
     211        return *this;
     212    }
     213
     214    inline sc_uint_bit_ref & operator [] (int v) {
     215        return valB[v];
     216    }
     217
     218    inline sc_uint_bit_ref_r& operator [] (int v) const {
     219        return valB[v];
     220    }
     221
     222    inline sc_uint_subref range(int left, int right) {
     223        return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right;
     224    }
     225
     226    inline sc_uint_subref_r range(int left, int right) const {
     227        return (((~0) >> (sizeof (data_type) * 8 - left)) & val) >> right;
     228    }
     229
    146230};
    147231
     
    149233
    150234#endif /* __SC_BIGINT_H__ */
     235
     236
     237/*
     238# Local Variables:
     239# tab-width: 4;
     240# c-basic-offset: 4;
     241# c-file-offsets:((innamespace . 0)(inline-open . 0));
     242# indent-tabs-mode: nil;
     243# End:
     244#
     245# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     246*/
     247
Note: See TracChangeset for help on using the changeset viewer.