aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-04-09 14:11:53 -0700
committerGitHub <noreply@github.com>2020-04-09 14:11:53 -0700
commit47a4913834d0f1e16a3340a8718c8bcdb8431f45 (patch)
tree0559a0df51afaa3a87bd800d40442bd52ba2e651 /toolsrc/include
parent0304c453157e05b52b04039602a806564bd011c2 (diff)
downloadvcpkg-47a4913834d0f1e16a3340a8718c8bcdb8431f45.tar.gz
vcpkg-47a4913834d0f1e16a3340a8718c8bcdb8431f45.zip
[vcpkg] Correct UInt128 code 😇 (#10583)
* [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.
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/vcpkg/base/uint128.h26
1 files changed, 26 insertions, 0 deletions
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 <stdint.h>
+
+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;
+};
+
+}