From ccc6ae19298cebb83ec7ab6374e8c1d4c5b057d0 Mon Sep 17 00:00:00 2001 From: Clint Banzhaf Date: Sun, 31 Aug 2025 15:19:02 +0200 Subject: [PATCH 1/5] update --- include/CppCore/Math/Util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/CppCore/Math/Util.h b/include/CppCore/Math/Util.h index 4c6f0a3a..d6e825ce 100644 --- a/include/CppCore/Math/Util.h +++ b/include/CppCore/Math/Util.h @@ -2656,6 +2656,13 @@ namespace CppCore CppCore::clone(r, t.v); } #if defined(CPPCORE_CPU_64BIT) + else if constexpr (sizeof(UINT1) == 16 && sizeof(UINT2) == 16 && sizeof(UINT3) == 16) + { + uint64_t* ap = (uint64_t*)&a; + uint64_t* bp = (uint64_t*)&b; + uint64_t* rp = (uint64_t*)&r; + CppCore::umul128(ap[0], ap[1], bp[0], bp[1], rp[0], rp[1]); + } else if constexpr (sizeof(UINT1) % 8 == 0 && sizeof(UINT2) % 8 == 0 && sizeof(UINT3) % 8 == 0) { // 64-Bit CPU and Multiples of 64-Bit From 9f1b487a51011c7ba35ab652b638c04968bf6405 Mon Sep 17 00:00:00 2001 From: Clint Banzhaf Date: Sun, 31 Aug 2025 17:05:54 +0200 Subject: [PATCH 2/5] update --- include/CppCore/Math/Util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/CppCore/Math/Util.h b/include/CppCore/Math/Util.h index d6e825ce..19e66f57 100644 --- a/include/CppCore/Math/Util.h +++ b/include/CppCore/Math/Util.h @@ -1285,7 +1285,7 @@ namespace CppCore #elif defined(CPPCORE_CPU_X64) && defined(CPPCORE_COMPILER_MSVC) l = _umul128(a, b, &h); #elif defined(CPPCORE_CPU_X64) && defined(CPPCORE_COMPILER_CLANG) - __asm("MULQ %4" : "=a" (l), "=d" (h) : "0" (a), "1" (b), "r" (b)); + __asm("MULQ %3" : "=a" (l), "=d" (h) : "0" (a), "r" (b)); #elif defined(CPPCORE_COMPILER_CLANG) && defined(__SIZEOF_INT128__) __uint128_t t = (__uint128_t)a * b; l = (uint64_t)t; From e535842a0bff4b6d71844926e0c313528f3a3964 Mon Sep 17 00:00:00 2001 From: Clint Banzhaf Date: Fri, 19 Sep 2025 23:33:42 +0200 Subject: [PATCH 3/5] assert divident type must be larger than divisor type --- include/CppCore/Math/Util.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/CppCore/Math/Util.h b/include/CppCore/Math/Util.h index 19e66f57..8071655f 100644 --- a/include/CppCore/Math/Util.h +++ b/include/CppCore/Math/Util.h @@ -3021,6 +3021,7 @@ namespace CppCore { static_assert(sizeof(UINT1) % 4 == 0); static_assert(sizeof(UINT2) % 4 == 0); + static_assert(sizeof(UINT1) >= sizeof(UINT2)); assert(&q != &u && &r != &v); CppCore::clear(q); #if defined(CPPCORE_CPU_X64) @@ -3038,7 +3039,7 @@ namespace CppCore uint32_t n = N; while (n != 0U && vp[n-1] == 0U) n--; - if (((M < n) | (n == 0)) != 0) + if (n == 0U) return false; if (n == 1U) { uint64_t k; @@ -3128,7 +3129,7 @@ namespace CppCore uint32_t n = N; while (n != 0U && vp[n-1] == 0U) n--; - if (((M < n) | (n == 0)) != 0) + if (n == 0U) return false; if (n == 1U) { uint32_t k; @@ -3260,6 +3261,7 @@ namespace CppCore assert(&r != &v); static_assert(sizeof(UINT1) % 4 == 0); static_assert(sizeof(UINT2) % 4 == 0); + static_assert(sizeof(UINT1) >= sizeof(UINT2)); #if defined(CPPCORE_CPU_X64) if constexpr (sizeof(UINT1) % 8 == 0 && sizeof(UINT2) % 8 == 0) { @@ -3275,7 +3277,7 @@ namespace CppCore uint32_t n = N; while (n != 0U && vp[n-1] == 0U) n--; - if (((M < n) | (n == 0U)) != 0) + if (n == 0U) return; if (n == 1U) { CppCore::clear(r); @@ -3370,7 +3372,7 @@ namespace CppCore uint32_t n = N; while (n != 0U && vp[n-1] == 0U) n--; - if (((M < n) | (n == 0)) != 0) + if (n == 0U) return; if (n == 1U) { CppCore::clear(r); From cb30ffdb1da7559b6003b7e34a0264b22daed328 Mon Sep 17 00:00:00 2001 From: Clint Banzhaf Date: Mon, 22 Sep 2025 21:05:52 +0200 Subject: [PATCH 4/5] template unions --- include/CppCore/Math/Util.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/CppCore/Math/Util.h b/include/CppCore/Math/Util.h index 8071655f..4060c9bc 100644 --- a/include/CppCore/Math/Util.h +++ b/include/CppCore/Math/Util.h @@ -534,6 +534,35 @@ namespace CppCore }; #pragma pack(pop) + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // TEMPLATE UNIONS + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /// + /// Union of two types + /// + template + union U2 + { + public: + T1 t1; + T2 t2; + INLINE U2() {} + }; + + /// + /// Union of three types + /// + template + union U3 + { + public: + T1 t1; + T2 t2; + T3 t3; + INLINE U3() {} + }; + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ADDITION OPERATIONS WITH OVERFLOW BIT //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// From a583623032174587331406433168d6a343ef4026 Mon Sep 17 00:00:00 2001 From: Clint Banzhaf Date: Tue, 18 Nov 2025 04:28:19 +0100 Subject: [PATCH 5/5] wip --- include/CppCore/Math/Util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/CppCore/Math/Util.h b/include/CppCore/Math/Util.h index 4060c9bc..b145774c 100644 --- a/include/CppCore/Math/Util.h +++ b/include/CppCore/Math/Util.h @@ -1313,12 +1313,12 @@ namespace CppCore l = _mulx_u64(a, b, (unsigned long long*)&h); #elif defined(CPPCORE_CPU_X64) && defined(CPPCORE_COMPILER_MSVC) l = _umul128(a, b, &h); - #elif defined(CPPCORE_CPU_X64) && defined(CPPCORE_COMPILER_CLANG) - __asm("MULQ %3" : "=a" (l), "=d" (h) : "0" (a), "r" (b)); #elif defined(CPPCORE_COMPILER_CLANG) && defined(__SIZEOF_INT128__) __uint128_t t = (__uint128_t)a * b; l = (uint64_t)t; h = (uint64_t)(t >> 64); + #elif defined(CPPCORE_CPU_X64) && defined(CPPCORE_COMPILER_CLANG) + __asm("MULQ %3" : "=a" (l), "=d" (h) : "0" (a), "r" (b)); #else uint32_t al = (uint32_t)a; uint32_t ah = (uint32_t)(a >> 32);