Logo Search packages:      
Sourcecode: maq version File versions

dword.hh

#ifndef LH3_DWORD_H
#define LH3_DWORD_H

#include "const.h"

template<class TYPE>
struct dword_t
{
      bit64_t w1;
      TYPE w2;
      inline dword_t() { w1 = 0ull; w2 = TYPE(0); }
      inline dword_t(bit16_t _w1) { w1 = _w1; w2 = TYPE(0); }
      inline dword_t(bit32_t _w1) { w1 = _w1; w2 = TYPE(0); }
      inline dword_t(bit64_t _w1) { w1 = _w1; w2 = TYPE(0); }
      inline dword_t(int _w1) { w1 = bit64_t(_w1); w2 = TYPE(0); }
      inline dword_t(bit64_t _w1, TYPE _w2) { w1 = _w1; w2 = _w2; }
      inline dword_t<TYPE> &operator >>= (int k) {
            if (k == 0) return *this;
            if (k < 64) {
                  w1 = (w1>>k) | (bit64_t(w2)<<(64-k)); w2 >>= k;
            } else {
                  w1 = bit64_t(w2)>>(k-64); w2 = TYPE(0);
            }
            return *this;
      }
      inline dword_t<TYPE> &operator <<= (int k) {
            if (k == 0) return *this;
            if (k < 64) {
                  w2 = (w2<<k) | (w1>>(64-k)); w1 <<= k;
            } else {
                  w2 = w1 << (k-64); w1 = 0ull;
            }
            return *this;
      }
      inline dword_t<TYPE> &operator &= (dword_t<TYPE> w) {
            w1 &= w.w1; w2 &= w.w2;
            return *this;
      }
      inline dword_t<TYPE> &operator |= (dword_t<TYPE> w) {
            w1 |= w.w1; w2 |= w.w2;
            return *this;
      }
      inline dword_t<TYPE> &operator |= (int w) {
            w1 |= w;
            return *this;
      }
      inline dword_t<TYPE> &operator ^= (dword_t<TYPE> w) {
            w1 ^= w.w1; w2 ^= w.w2;
            return *this;
      }
};

template<class TYPE>
inline dword_t<TYPE> operator >> (const dword_t<TYPE> &w, int k) {
      return (k == 0)? w : ((k < 64)? dword_t<TYPE>((w.w1>>k) | (bit64_t(w.w2)<<(64-k)), w.w2>>k)
                                      : dword_t<TYPE>(bit64_t(w.w2)>>(k-64), TYPE(0)));
}
template<class TYPE>
inline dword_t<TYPE> operator << (const dword_t<TYPE> &w, int k) {
      return (k == 0)? w : ((k < 64)? dword_t<TYPE>(w.w1<<k, (w.w2<<k) | (w.w1>>(64-k)))
                                      : dword_t<TYPE>(0ull, TYPE(w.w1<<(k-64))));
}
template<class TYPE>
inline dword_t<TYPE> operator & (const dword_t<TYPE> &w, const dword_t<TYPE> &ww) {
      return dword_t<TYPE>(w.w1 & ww.w1, w.w2 & ww.w2);
}
template<class TYPE>
inline int operator < (const dword_t<TYPE> &w, const dword_t<TYPE> &ww) {
      return (w.w2 < ww.w2 || (w.w2 == ww.w2 && w.w1 < ww.w1));
}
template<class TYPE>
inline dword_t<TYPE> operator | (const dword_t<TYPE> &w, const dword_t<TYPE> &ww) {
      return dword_t<TYPE>(w.w1 | ww.w1, w.w2 | ww.w2);
}
template<class TYPE>
inline dword_t<TYPE> operator ^ (const dword_t<TYPE> &w, const dword_t<TYPE> &ww) {
      return dword_t<TYPE>(w.w1 ^ ww.w1, w.w2 ^ ww.w2);
}
template<class TYPE>
inline int operator != (const dword_t<TYPE> &w, const dword_t<TYPE> &ww) {
      return (w.w1 != ww.w1 || w.w2 != ww.w2);
}
template<class TYPE>
inline int operator == (const dword_t<TYPE> &w, const dword_t<TYPE> &ww) {
      return (w.w1 == ww.w1 && w.w2 == ww.w2);
}
template<class TYPE>
inline dword_t<TYPE> operator ~ (const dword_t<TYPE> &w) {
      return dword_t<TYPE>(~w.w1, ~w.w2);
}
template<class TYPE, class T2>
inline T2 operator & (const dword_t<TYPE> &w, T2 k) {
      return T2(w.w1 & k);
}
template<class TYPE, class T2>
inline dword_t<TYPE> operator | (const dword_t<TYPE> &w, T2 k) {
      return dword_t<TYPE>(w.w1 | k, w.w2);
}

#endif

Generated by  Doxygen 1.6.0   Back to index