From 05ec427fecd82bd4d3f9528936819f25391747b5 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Tue, 4 Mar 2025 08:48:08 -0800 Subject: [PATCH 1/2] Use more accurate `ReciprocalSqrt` when available Utilizes the AVX512 variant of `ReciprocalSqrt`([vrsqrt14ps](https://www.felixcloutier.com/x86/vrsqrt14ps)) that is accurate up to 14 bits of precision(rather than 12) when the host supports it. --- Solver/Intrinsics.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Solver/Intrinsics.cs b/Solver/Intrinsics.cs index 46e6bbd..3033c2f 100644 --- a/Solver/Intrinsics.cs +++ b/Solver/Intrinsics.cs @@ -114,6 +114,11 @@ internal static class Intrinsics [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector256 ReciprocalSqrt(Vector256 data) { + // Accurate to 14 bits + if (Avx512F.VL.IsSupported) + return Avx512F.VL.ReciprocalSqrt14(data); + + // Accurate to 12 bits if (Avx.IsSupported) return Avx.ReciprocalSqrt(data); From 2ac7a78c3ca3cf96b8df0faed05e979ad8b76ee8 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Tue, 4 Mar 2025 11:33:29 -0800 Subject: [PATCH 2/2] Disable `vrsqrt14ps`-usage when determinism is enabled --- Solver/Intrinsics.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Solver/Intrinsics.cs b/Solver/Intrinsics.cs index 3033c2f..14b3487 100644 --- a/Solver/Intrinsics.cs +++ b/Solver/Intrinsics.cs @@ -114,9 +114,11 @@ internal static class Intrinsics [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector256 ReciprocalSqrt(Vector256 data) { +#if !IS_DETERMINISTIC // Accurate to 14 bits if (Avx512F.VL.IsSupported) return Avx512F.VL.ReciprocalSqrt14(data); +#endif // Accurate to 12 bits if (Avx.IsSupported)