From ac0d27d9bdda472c373bf312a149dbfc558d1ccc Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 20 Feb 2023 14:10:49 +1000 Subject: [PATCH] Provide Sse fallback for WithW --- .../PixelFormats/PixelBlenders/PorterDuffFunctions.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs index bc7958f85..baf7d80c0 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs @@ -500,12 +500,19 @@ internal static partial class PorterDuffFunctions [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector4 WithW(Vector4 value, Vector4 w) { - // TODO: Provide SSE fallback which uses "shuffle" - just pick XYZ from value and W from w if (Sse41.IsSupported) { return Sse41.Insert(value.AsVector128(), w.AsVector128(), 0b11_11_0000).AsVector4(); } + if (Sse.IsSupported) + { + // Create tmp as + // Then return (which is ) + Vector128 tmp = Sse.Shuffle(w.AsVector128(), value.AsVector128(), 0b00_10_00_11); + return Sse.Shuffle(value.AsVector128(), tmp, 0b00_10_01_00).AsVector4(); + } + value.W = w.W; return value; }