From 3e794e6b1d7153e24ce28b4a291fc34008de19e5 Mon Sep 17 00:00:00 2001 From: Harry Gillanders Date: Mon, 29 Jun 2026 17:13:15 +0100 Subject: [PATCH] Fix #11047: Sufficiently big BigUint multiplications fail during CTFE --- std/internal/math/biguintcore.d | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/std/internal/math/biguintcore.d b/std/internal/math/biguintcore.d index b2c2b890e2c..13270b07a84 100644 --- a/std/internal/math/biguintcore.d +++ b/std/internal/math/biguintcore.d @@ -197,8 +197,16 @@ else alias multibyteSquare = std.internal.math.biguintnoasm.multibyteSquare; // Half the size of the data cache. @nogc nothrow pure @safe size_t getCacheLimit() { - import core.cpuid : dataCaches; - return dataCaches[0].size * 1024 / 2; + if (__ctfe) + { + // Chosen arbitrarily. + return 8192; + } + else + { + import core.cpuid : dataCaches; + return dataCaches[0].size * 1024 / 2; + } } enum size_t FASTDIVLIMIT = 100; // crossover to recursive division @@ -1267,6 +1275,12 @@ public: assert(BigUint.mulInt(a,b) == 15); } +// https://github.com/dlang/phobos/issues/11047 +@safe pure nothrow unittest +{ + enum ctfeLargeMultiplication = BigUint.mul(BigUint(ulong(1)) << ulong(33), BigUint(ulong(1)) << ulong(32)); +} + // Remove leading zeros from x, to restore the BigUint invariant inout(BigDigit) [] removeLeadingZeros(return scope inout(BigDigit) [] x) pure nothrow @safe {