Skip to content

Commit 55a8c73

Browse files
Expand v128 native shuffle (float) support
1 parent 505ecce commit 55a8c73

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void Shuffle4Reduce(
6868
{
6969
if ((Vector512.IsHardwareAccelerated && Vector512_.SupportsShuffleNativeFloat) ||
7070
(Vector256.IsHardwareAccelerated && Vector256_.SupportsShuffleNativeFloat) ||
71-
(Vector128.IsHardwareAccelerated && Vector128_.SupportsShuffleNativeFloat))
71+
Vector128.IsHardwareAccelerated)
7272
{
7373
int remainder = 0;
7474
if (Vector512.IsHardwareAccelerated)
@@ -305,7 +305,7 @@ private static void Shuffle4(
305305
}
306306
}
307307
}
308-
else if (Vector128.IsHardwareAccelerated && Vector128_.SupportsShuffleNativeFloat)
308+
else if (Vector128.IsHardwareAccelerated)
309309
{
310310
ref Vector128<float> sourceBase = ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(source));
311311
ref Vector128<float> destinationBase = ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(destination));

src/ImageSharp/Common/Helpers/Vector128Utilities.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ namespace SixLabors.ImageSharp.Common.Helpers;
2424
internal static class Vector128_
2525
#pragma warning restore SA1649 // File name should match first type name
2626
{
27-
/// <summary>
28-
/// Gets a value indicating whether shuffle operations are supported.
29-
/// </summary>
30-
public static bool SupportsShuffleNativeFloat
31-
{
32-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
33-
get => Sse.IsSupported;
34-
}
35-
3627
/// <summary>
3728
/// Gets a value indicating whether shuffle operations are supported.
3829
/// </summary>
@@ -87,8 +78,14 @@ public static Vector128<float> ShuffleNative(Vector128<float> vector, [ConstantE
8778
return Sse.Shuffle(vector, vector, control);
8879
}
8980

90-
ThrowUnreachableException();
91-
return default;
81+
// Don't use InverseMMShuffle here as we want to avoid the cast.
82+
Vector128<int> indices = Vector128.Create(
83+
control & 0x3,
84+
(control >> 2) & 0x3,
85+
(control >> 4) & 0x3,
86+
(control >> 6) & 0x3);
87+
88+
return Vector128.Shuffle(vector, indices);
9289
}
9390

9491
/// <summary>

0 commit comments

Comments
 (0)