Skip to content

Commit ac0d27d

Browse files
Provide Sse fallback for WithW
1 parent 78eb2f1 commit ac0d27d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,19 @@ public static Vector256<float> Xor(Vector256<float> destination, Vector256<float
500500
[MethodImpl(MethodImplOptions.AggressiveInlining)]
501501
private static Vector4 WithW(Vector4 value, Vector4 w)
502502
{
503-
// TODO: Provide SSE fallback which uses "shuffle" - just pick XYZ from value and W from w
504503
if (Sse41.IsSupported)
505504
{
506505
return Sse41.Insert(value.AsVector128(), w.AsVector128(), 0b11_11_0000).AsVector4();
507506
}
508507

508+
if (Sse.IsSupported)
509+
{
510+
// Create tmp as <w[3], w[0], value[2], value[0]>
511+
// Then return <value[0], value[1], tmp[2], tmp[0]> (which is <value[0], value[1], value[2], w[3]>)
512+
Vector128<float> tmp = Sse.Shuffle(w.AsVector128(), value.AsVector128(), 0b00_10_00_11);
513+
return Sse.Shuffle(value.AsVector128(), tmp, 0b00_10_01_00).AsVector4();
514+
}
515+
509516
value.W = w.W;
510517
return value;
511518
}

0 commit comments

Comments
 (0)