diff options
| author | nicole mazzuca <mazzucan@outlook.com> | 2020-04-09 14:11:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-09 14:11:53 -0700 |
| commit | 47a4913834d0f1e16a3340a8718c8bcdb8431f45 (patch) | |
| tree | 0559a0df51afaa3a87bd800d40442bd52ba2e651 /toolsrc/include | |
| parent | 0304c453157e05b52b04039602a806564bd011c2 (diff) | |
| download | vcpkg-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.h | 26 |
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; +}; + +} |
