TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::uint128 Class Reference

#include <uint128.h>

Public Member Functions

 uint128 (const uint64 &lo)
 
 uint128 (const uint64 &hi, const uint64 &lo)
 
uint128operator+= (const uint128 &x)
 
uint128operator*= (const uint128 &x)
 
uint128operator^= (const uint128 &x)
 
uint128operator&= (const uint128 &x)
 
uint128operator|= (const uint128 &x)
 
bool operator== (const uint128 &x)
 
uint128operator>>= (const int x)
 
uint128operator<<= (const int x)
 
uint128 operator& (const uint128 &x)
 

Public Attributes

G3D::uint64 hi
 
G3D::uint64 lo
 

Detailed Description

Limited functionality 128-bit unsigned integer. This is primarily to support FNV hashing and other cryptography applications. See the GMP library for high-precision C++ math support.

Constructor & Destructor Documentation

G3D::uint128::uint128 ( const uint64 lo)
69  : hi(0), lo(lo) {
70 }
G3D::uint64 hi
Definition: uint128.h:23
G3D::uint64 lo
Definition: uint128.h:24

+ Here is the caller graph for this function:

G3D::uint128::uint128 ( const uint64 hi,
const uint64 lo 
)
66  : hi(hi), lo(lo) {
67 }
G3D::uint64 hi
Definition: uint128.h:23
G3D::uint64 lo
Definition: uint128.h:24

Member Function Documentation

uint128 G3D::uint128::operator& ( const uint128 x)
152  {
153  return uint128(hi & x.hi, lo & x.lo);
154 }
G3D::uint64 hi
Definition: uint128.h:23
uint128(const uint64 &lo)
Definition: uint128.cpp:69
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

uint128 & G3D::uint128::operator&= ( const uint128 x)
107  {
108  hi &= x.hi;
109  lo &= x.lo;
110  return *this;
111 }
G3D::uint64 hi
Definition: uint128.h:23
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37
uint128 & G3D::uint128::operator*= ( const uint128 x)
84  {
85 
86  // The low bits will get overwritten when doing the multiply, so back up both (in case &x == this)
87  const uint64 oldLo = lo;
88  const uint64 oldXLo = x.lo;
89 
90  G3D::uint64 carry;
91  multiplyAndCarry(oldLo, oldXLo, carry, lo);
92 
93  // Overflow doesn't matter here because the result is going into hi - any overflow will exceed the capacity of a 128-bit number
94  // Note: hi * x.hi will always overflow, since (x * 2^64) * (y * 2^64) = x*y*(2^128). The largest number expressable in 128 bits is
95  // 2^128 - 1.
96  hi = carry + (oldLo * x.hi) + (hi * oldXLo);
97 
98  return *this;
99 }
G3D::uint64 hi
Definition: uint128.h:23
uint64_t uint64
Definition: g3dmath.h:170
uint64_t uint64
Definition: Define.h:149
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37
void multiplyAndCarry(const uint64 &_a, const uint64 &_b, uint64 &carry, uint64 &result)
Definition: uint128.cpp:34

+ Here is the call graph for this function:

uint128 & G3D::uint128::operator+= ( const uint128 x)
72  {
73 
74  G3D::uint64 carry;
75  addAndCarry(lo, x.lo, carry, lo);
76 
77  // Adding the carry will change hi. Save the old hi bits in case this == x.
78  const uint64 xHi = x.hi;
79  hi += carry;
80  hi += xHi;
81  return *this;
82 }
static void addAndCarry(const uint64 &_a, const uint64 &_b, uint64 &carry, uint64 &result)
Definition: uint128.cpp:16
G3D::uint64 hi
Definition: uint128.h:23
uint64_t uint64
Definition: g3dmath.h:170
uint64_t uint64
Definition: Define.h:149
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

uint128 & G3D::uint128::operator<<= ( const int  x)
137  {
138 
139  //Before shifting, mask out the bits that will be shifted out of lo.
140  //Put a 1 in the last bit that will be lost in the shift, then subtract 1 to get the logical inverse of the mask.
141  //A bitwise NOT will then produce the correct mask.
142  uint64 mask = ~((((uint64)1L) << (64 - x)) - 1);
143  uint64 tmp = lo & mask;
144  lo <<= x;
145 
146  //Shift hi and add the bits shifted up from lo
147  hi = (hi << x) + (tmp >> (64 - x));
148 
149  return *this;
150 }
G3D::uint64 hi
Definition: uint128.h:23
uint64_t uint64
Definition: g3dmath.h:170
uint64_t uint64
Definition: Define.h:149
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37
bool G3D::uint128::operator== ( const uint128 x)
119  {
120  return (hi == x.hi) && (lo == x.lo);
121 }
G3D::uint64 hi
Definition: uint128.h:23
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37
uint128 & G3D::uint128::operator>>= ( const int  x)
123  {
124 
125  //Before shifting, mask out the bits that will be shifted out of hi.
126  //Put a 1 in the first bit that will not be lost in the shift, then subtract 1 to get the mask.
127  uint64 mask = ((uint64)1L << x) - 1;
128  uint64 tmp = hi & mask;
129  hi >>= x;
130 
131  //Shift lo and add the bits shifted down from hi
132  lo = (lo >> x) + (tmp << (64 - x));
133 
134  return *this;
135 }
G3D::uint64 hi
Definition: uint128.h:23
uint64_t uint64
Definition: g3dmath.h:170
uint64_t uint64
Definition: Define.h:149
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37
uint128 & G3D::uint128::operator^= ( const uint128 x)
101  {
102  hi ^= x.hi;
103  lo ^= x.lo;
104  return *this;
105 }
G3D::uint64 hi
Definition: uint128.h:23
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37
uint128 & G3D::uint128::operator|= ( const uint128 x)
113  {
114  hi |= x.hi;
115  lo |= x.lo;
116  return *this;
117 }
G3D::uint64 hi
Definition: uint128.h:23
G3D::uint64 lo
Definition: uint128.h:24
G3D::int16 x
Definition: Vector2int16.h:37

Member Data Documentation

G3D::uint64 G3D::uint128::hi
G3D::uint64 G3D::uint128::lo

The documentation for this class was generated from the following files: