Index: net/base/int128.h |
diff --git a/net/base/int128.h b/net/base/int128.h |
index b17801be575825ae4e6039a53a4d78419feacb56..57501fb8c8387087ede3d217763768885c9f0c00 100644 |
--- a/net/base/int128.h |
+++ b/net/base/int128.h |
@@ -5,24 +5,26 @@ |
#ifndef NET_BASE_INT128_H_ |
#define NET_BASE_INT128_H_ |
+#include <stdint.h> |
+ |
#include <iosfwd> |
-#include "base/basictypes.h" |
+ |
#include "net/base/net_export.h" |
struct uint128_pod; |
// An unsigned 128-bit integer type. Thread-compatible. |
class uint128 { |
-public: |
+ public: |
uint128(); // Sets to 0, but don't trust on this behavior. |
- uint128(uint64 top, uint64 bottom); |
+ uint128(uint64_t top, uint64_t bottom); |
uint128(int bottom); |
- uint128(uint32 bottom); // Top 96 bits = 0 |
- uint128(uint64 bottom); // hi_ = 0 |
+ uint128(uint32_t bottom); // Top 96 bits = 0 |
+ uint128(uint64_t bottom); // hi_ = 0 |
uint128(const uint128 &val); |
uint128(const uint128_pod &val); |
- void Initialize(uint64 top, uint64 bottom); |
+ void Initialize(uint64_t top, uint64_t bottom); |
uint128& operator=(const uint128& b); |
@@ -41,23 +43,23 @@ public: |
uint128& operator++(); |
uint128& operator--(); |
- friend uint64 Uint128Low64(const uint128& v); |
- friend uint64 Uint128High64(const uint128& v); |
+ friend uint64_t Uint128Low64(const uint128& v); |
+ friend uint64_t Uint128High64(const uint128& v); |
// We add "std::" to avoid including all of port.h. |
friend NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& o, |
const uint128& b); |
-private: |
+ private: |
// Little-endian memory order optimizations can benefit from |
// having lo_ first, hi_ last. |
// See util/endian/endian.h and Load128/Store128 for storing a uint128. |
- uint64 lo_; |
- uint64 hi_; |
+ uint64_t lo_; |
+ uint64_t hi_; |
// Not implemented, just declared for catching automatic type conversions. |
- uint128(uint8); |
- uint128(uint16); |
+ uint128(uint8_t); |
+ uint128(uint16_t); |
uint128(float v); |
uint128(double v); |
}; |
@@ -70,8 +72,8 @@ struct uint128_pod { |
// of static instances, which is the primary reason for this struct in the |
// first place. This does not seem to defeat any optimizations wrt |
// operations involving this struct. |
- uint64 hi; |
- uint64 lo; |
+ uint64_t hi; |
+ uint64_t lo; |
}; |
NET_EXPORT_PRIVATE extern const uint128_pod kuint128max; |
@@ -83,8 +85,12 @@ NET_EXPORT_PRIVATE extern std::ostream& operator<<(std::ostream& o, |
// Methods to access low and high pieces of 128-bit value. |
// Defined externally from uint128 to facilitate conversion |
// to native 128-bit types when compilers support them. |
-inline uint64 Uint128Low64(const uint128& v) { return v.lo_; } |
-inline uint64 Uint128High64(const uint128& v) { return v.hi_; } |
+inline uint64_t Uint128Low64(const uint128& v) { |
+ return v.lo_; |
+} |
+inline uint64_t Uint128High64(const uint128& v) { |
+ return v.hi_; |
+} |
// TODO: perhaps it would be nice to have int128, a signed 128-bit type? |
@@ -105,17 +111,18 @@ inline uint128& uint128::operator=(const uint128& b) { |
} |
inline uint128::uint128(): lo_(0), hi_(0) { } |
-inline uint128::uint128(uint64 top, uint64 bottom) : lo_(bottom), hi_(top) { } |
+inline uint128::uint128(uint64_t top, uint64_t bottom) |
+ : lo_(bottom), hi_(top) {} |
inline uint128::uint128(const uint128 &v) : lo_(v.lo_), hi_(v.hi_) { } |
inline uint128::uint128(const uint128_pod &v) : lo_(v.lo), hi_(v.hi) { } |
-inline uint128::uint128(uint64 bottom) : lo_(bottom), hi_(0) { } |
-inline uint128::uint128(uint32 bottom) : lo_(bottom), hi_(0) { } |
+inline uint128::uint128(uint64_t bottom) : lo_(bottom), hi_(0) {} |
+inline uint128::uint128(uint32_t bottom) : lo_(bottom), hi_(0) {} |
inline uint128::uint128(int bottom) : lo_(bottom), hi_(0) { |
if (bottom < 0) { |
--hi_; |
} |
} |
-inline void uint128::Initialize(uint64 top, uint64 bottom) { |
+inline void uint128::Initialize(uint64_t top, uint64_t bottom) { |
hi_ = top; |
lo_ = bottom; |
} |
@@ -139,9 +146,9 @@ CMP128(<=) |
// Unary operators |
inline uint128 operator-(const uint128& val) { |
- const uint64 hi_flip = ~Uint128High64(val); |
- const uint64 lo_flip = ~Uint128Low64(val); |
- const uint64 lo_add = lo_flip + 1; |
+ const uint64_t hi_flip = ~Uint128High64(val); |
+ const uint64_t lo_flip = ~Uint128Low64(val); |
+ const uint64_t lo_add = lo_flip + 1; |
if (lo_add < lo_flip) { |
return uint128(hi_flip + 1, lo_add); |
} |
@@ -186,14 +193,15 @@ LOGICASSIGN128(^=) |
// Shift operators. |
inline uint128 operator<<(const uint128& val, int amount) { |
- // uint64 shifts of >= 64 are undefined, so we will need some special-casing. |
+ // uint64_t shifts of >= 64 are undefined, so we will need some |
+ // special-casing. |
if (amount < 64) { |
if (amount == 0) { |
return val; |
} |
- uint64 new_hi = (Uint128High64(val) << amount) | |
- (Uint128Low64(val) >> (64 - amount)); |
- uint64 new_lo = Uint128Low64(val) << amount; |
+ uint64_t new_hi = |
+ (Uint128High64(val) << amount) | (Uint128Low64(val) >> (64 - amount)); |
+ uint64_t new_lo = Uint128Low64(val) << amount; |
return uint128(new_hi, new_lo); |
} else if (amount < 128) { |
return uint128(Uint128Low64(val) << (amount - 64), 0); |
@@ -203,14 +211,15 @@ inline uint128 operator<<(const uint128& val, int amount) { |
} |
inline uint128 operator>>(const uint128& val, int amount) { |
- // uint64 shifts of >= 64 are undefined, so we will need some special-casing. |
+ // uint64_t shifts of >= 64 are undefined, so we will need some |
+ // special-casing. |
if (amount < 64) { |
if (amount == 0) { |
return val; |
} |
- uint64 new_hi = Uint128High64(val) >> amount; |
- uint64 new_lo = (Uint128Low64(val) >> amount) | |
- (Uint128High64(val) << (64 - amount)); |
+ uint64_t new_hi = Uint128High64(val) >> amount; |
+ uint64_t new_lo = |
+ (Uint128Low64(val) >> amount) | (Uint128High64(val) << (64 - amount)); |
return uint128(new_hi, new_lo); |
} else if (amount < 128) { |
return uint128(0, Uint128High64(val) >> (amount - 64)); |
@@ -220,7 +229,8 @@ inline uint128 operator>>(const uint128& val, int amount) { |
} |
inline uint128& uint128::operator<<=(int amount) { |
- // uint64 shifts of >= 64 are undefined, so we will need some special-casing. |
+ // uint64_t shifts of >= 64 are undefined, so we will need some |
+ // special-casing. |
if (amount < 64) { |
if (amount != 0) { |
hi_ = (hi_ << amount) | (lo_ >> (64 - amount)); |
@@ -237,7 +247,8 @@ inline uint128& uint128::operator<<=(int amount) { |
} |
inline uint128& uint128::operator>>=(int amount) { |
- // uint64 shifts of >= 64 are undefined, so we will need some special-casing. |
+ // uint64_t shifts of >= 64 are undefined, so we will need some |
+ // special-casing. |
if (amount < 64) { |
if (amount != 0) { |
lo_ = (lo_ >> amount) | (hi_ << (64 - amount)); |
@@ -267,7 +278,7 @@ inline uint128 operator*(const uint128& lhs, const uint128& rhs) { |
inline uint128& uint128::operator+=(const uint128& b) { |
hi_ += b.hi_; |
- uint64 lolo = lo_ + b.lo_; |
+ uint64_t lolo = lo_ + b.lo_; |
if (lolo < lo_) |
++hi_; |
lo_ = lolo; |
@@ -283,19 +294,19 @@ inline uint128& uint128::operator-=(const uint128& b) { |
} |
inline uint128& uint128::operator*=(const uint128& b) { |
- uint64 a96 = hi_ >> 32; |
- uint64 a64 = hi_ & 0xffffffffu; |
- uint64 a32 = lo_ >> 32; |
- uint64 a00 = lo_ & 0xffffffffu; |
- uint64 b96 = b.hi_ >> 32; |
- uint64 b64 = b.hi_ & 0xffffffffu; |
- uint64 b32 = b.lo_ >> 32; |
- uint64 b00 = b.lo_ & 0xffffffffu; |
+ uint64_t a96 = hi_ >> 32; |
+ uint64_t a64 = hi_ & 0xffffffffu; |
+ uint64_t a32 = lo_ >> 32; |
+ uint64_t a00 = lo_ & 0xffffffffu; |
+ uint64_t b96 = b.hi_ >> 32; |
+ uint64_t b64 = b.hi_ & 0xffffffffu; |
+ uint64_t b32 = b.lo_ >> 32; |
+ uint64_t b00 = b.lo_ & 0xffffffffu; |
// multiply [a96 .. a00] x [b96 .. b00] |
// terms higher than c96 disappear off the high side |
// terms c96 and c64 are safe to ignore carry bit |
- uint64 c96 = a96 * b00 + a64 * b32 + a32 * b64 + a00 * b96; |
- uint64 c64 = a64 * b00 + a32 * b32 + a00 * b64; |
+ uint64_t c96 = a96 * b00 + a64 * b32 + a32 * b64 + a00 * b96; |
+ uint64_t c64 = a64 * b00 + a32 * b32 + a00 * b64; |
this->hi_ = (c96 << 32) + c64; |
this->lo_ = 0; |
// add terms after this one at a time to capture carry |