From e4181796948f41016430968d4c381ac623e57294 Mon Sep 17 00:00:00 2001 From: Mathew Benson Date: Tue, 22 Aug 2023 21:11:53 +0300 Subject: [PATCH 1/4] Fix for FMT_MODULE not compiling on GCC --- include/fmt/format.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9b4f7357..7d61da40 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -369,8 +369,6 @@ class uint128_fallback { private: uint64_t lo_, hi_; - friend uint128_fallback umul128(uint64_t x, uint64_t y) noexcept; - public: constexpr uint128_fallback(uint64_t hi, uint64_t lo) : lo_(lo), hi_(hi) {} constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {} From 1f38ebbdb1282a9f57e11f69cd488d5c232a5d1e Mon Sep 17 00:00:00 2001 From: Mathew Benson Date: Tue, 22 Aug 2023 23:07:04 +0300 Subject: [PATCH 2/4] Add condition to include friend function in win32 --- include/fmt/format.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/fmt/format.h b/include/fmt/format.h index 7d61da40..e39bec68 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -369,6 +369,10 @@ class uint128_fallback { private: uint64_t lo_, hi_; +#ifdef _WIN32 + friend uint128_fallback umul128(uint64_t x, uint64_t y) noexcept; +#endif + public: constexpr uint128_fallback(uint64_t hi, uint64_t lo) : lo_(lo), hi_(hi) {} constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {} From 2b20d7be6f32c44008c521280de269cf28d8e8ce Mon Sep 17 00:00:00 2001 From: Mathew Benson Date: Thu, 24 Aug 2023 00:55:43 +0300 Subject: [PATCH 3/4] Refactor To remove friend function private access - Remove umul128 friend function from uint128_fallback class using non-const member access functions instead. --- include/fmt/format.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index e39bec68..9dda5662 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -369,10 +369,6 @@ class uint128_fallback { private: uint64_t lo_, hi_; -#ifdef _WIN32 - friend uint128_fallback umul128(uint64_t x, uint64_t y) noexcept; -#endif - public: constexpr uint128_fallback(uint64_t hi, uint64_t lo) : lo_(lo), hi_(hi) {} constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {} @@ -380,6 +376,9 @@ class uint128_fallback { constexpr uint64_t high() const noexcept { return hi_; } constexpr uint64_t low() const noexcept { return lo_; } + uint64_t& high() { return hi_; } + uint64_t& low() { return lo_; } + template ::value)> constexpr explicit operator T() const { return static_cast(lo_); @@ -1491,7 +1490,7 @@ inline uint128_fallback umul128(uint64_t x, uint64_t y) noexcept { return {static_cast(p >> 64), static_cast(p)}; #elif defined(_MSC_VER) && defined(_M_X64) auto result = uint128_fallback(); - result.lo_ = _umul128(x, y, &result.hi_); + result.low() = _umul128(x, y, &result.high()); return result; #else const uint64_t mask = static_cast(max_value()); From e78682405381969b6e6e4b0882e33399bff5cfff Mon Sep 17 00:00:00 2001 From: Mathew Benson Date: Fri, 25 Aug 2023 13:21:52 +0300 Subject: [PATCH 4/4] Refactor Improvement on umul128 function - Removal of direct access to members of uint128_fallback and instead create the values at the callsite and pass them via the constructor of uint128_fallback on the return statement. --- include/fmt/format.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9dda5662..34c9dc75 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -376,9 +376,6 @@ class uint128_fallback { constexpr uint64_t high() const noexcept { return hi_; } constexpr uint64_t low() const noexcept { return lo_; } - uint64_t& high() { return hi_; } - uint64_t& low() { return lo_; } - template ::value)> constexpr explicit operator T() const { return static_cast(lo_); @@ -1489,9 +1486,9 @@ inline uint128_fallback umul128(uint64_t x, uint64_t y) noexcept { auto p = static_cast(x) * static_cast(y); return {static_cast(p >> 64), static_cast(p)}; #elif defined(_MSC_VER) && defined(_M_X64) - auto result = uint128_fallback(); - result.low() = _umul128(x, y, &result.high()); - return result; + auto hi = uint64_t{}; + auto lo = _umul128(x, y, &hi); + return {hi, lo}; #else const uint64_t mask = static_cast(max_value());