From 633c807a08e8499eb3a3c0727fdc9e4d4bec7234 Mon Sep 17 00:00:00 2001 From: Guillaume Piolat Date: Fri, 19 Jun 2026 19:28:37 +0200 Subject: [PATCH] nu_bsf was returning a wrong value in the LDC path. Explanation: The 'llvm.cttz' intrinsic counts the trailing (least significant) zeros in a variable. This number of zeroes is already the index of the first least significant set bit. Since nu_bsf(0) is UB, no edge case. --- source/numem/core/math.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/numem/core/math.d b/source/numem/core/math.d index bd7394a..3c74f58 100644 --- a/source/numem/core/math.d +++ b/source/numem/core/math.d @@ -132,7 +132,7 @@ T nu_bsf(T)(T value) @nogc nothrow @trusted pure if (__traits(isIntegral, T)) { version(LDC) { import ldc.intrinsics : llvm_cttz; - return cast(int)(value.sizeof * 8 - 1 - llvm_cttz(value, true)); + return cast(int)(llvm_cttz(value, true)); } else { // Slow software implementation.