From 2923fafc3d2ee825a3ad98cfaa6d5520586b7e93 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 1 Mar 2025 00:29:36 +0100 Subject: [PATCH] [util] Add 48-bit integer type --- src/util/util_bit.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/util/util_bit.h b/src/util/util_bit.h index 6f6727005..f1dfe6724 100644 --- a/src/util/util_bit.h +++ b/src/util/util_bit.h @@ -632,4 +632,25 @@ namespace dxvk::bit { return float(n) / float(1u << F); } + + /** + * \brief 48-bit integer storage type + */ + struct uint48_t { + uint48_t() = default; + + explicit uint48_t(uint64_t n) + : a(uint16_t(n)), b(uint16_t(n >> 16)), c(uint16_t(n >> 32)) { } + + uint16_t a; + uint16_t b; + uint16_t c; + + explicit operator uint64_t () const { + // GCC generates worse code if we promote to uint64 directly + uint32_t lo = uint32_t(a) | (uint32_t(b) << 16); + return uint64_t(lo) | (uint64_t(c) << 32); + } + }; + }