From 47a4913834d0f1e16a3340a8718c8bcdb8431f45 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Thu, 9 Apr 2020 14:11:53 -0700 Subject: =?UTF-8?q?[vcpkg]=20Correct=20UInt128=20code=20=F0=9F=98=87=20(#1?= =?UTF-8?q?0583)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [vcpkg] Correct UInt128 code 😇 `UInt128::operator<<(x, y)` should clear the bottom 64 bits of `x` if `y >= 64`; however, we don't do this, and so we duplicate `x`'s bottom bits into `x.top` instead of moving them. Similarly, we have the opposite problem for `UInt128::operator>>`. This commit fixes these latent bugs, which we weren't hitting because the thing we use them for never actually shifts more than 64 bits. --- toolsrc/include/vcpkg/base/uint128.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 toolsrc/include/vcpkg/base/uint128.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg/base/uint128.h b/toolsrc/include/vcpkg/base/uint128.h new file mode 100644 index 000000000..6b7816760 --- /dev/null +++ b/toolsrc/include/vcpkg/base/uint128.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace vcpkg { + +struct UInt128 { + UInt128() = default; + UInt128(uint64_t value) : bottom(value), top(0) {} + + UInt128& operator<<=(int by) noexcept; + UInt128& operator>>=(int by) noexcept; + UInt128& operator+=(uint64_t lhs) noexcept; + + uint64_t bottom_64_bits() const noexcept { + return bottom; + } + uint64_t top_64_bits() const noexcept { + return top; + } +private: + uint64_t bottom; + uint64_t top; +}; + +} -- cgit v1.2.3