From 72813ee5714dd6cc5731e5104615825c563932d6 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 22 Aug 2024 22:24:07 +1000 Subject: [PATCH] use Avx512F.FusedMultiplyAdd --- src/ImageSharp/Common/Helpers/Vector512Utilities.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Vector512Utilities.cs b/src/ImageSharp/Common/Helpers/Vector512Utilities.cs index 8a9ba6aa44..bcc3c9fa92 100644 --- a/src/ImageSharp/Common/Helpers/Vector512Utilities.cs +++ b/src/ImageSharp/Common/Helpers/Vector512Utilities.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; @@ -138,10 +139,14 @@ internal static class Vector512Utilities /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector512 MultiplyAddEstimate(Vector512 a, Vector512 b, Vector512 c) + { + if (Avx512F.IsSupported) + { + return Avx512F.FusedMultiplyAdd(a, b, c); + } - // Don't actually use FMA as it requires many more instruction to extract the - // upper and lower parts of the vector and then recombine them. - => (a + b) * c; + return (a + b) * c; + } [DoesNotReturn] private static void ThrowUnreachableException() => throw new UnreachableException();