diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Convert.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Convert.cs index 1b5a418dea..5318ad0497 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.Convert.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.Convert.cs @@ -57,7 +57,7 @@ internal static partial class SimdUtils for (int i = 0; i < source.Length; i++) { - Unsafe.Add(ref dBase, i) = Unsafe.Add(ref sBase, i) / 255f; + Unsafe.Add(ref dBase, (uint)i) = Unsafe.Add(ref sBase, (uint)i) / 255f; } } @@ -66,12 +66,13 @@ internal static partial class SimdUtils { ref float sBase = ref MemoryMarshal.GetReference(source); ref byte dBase = ref MemoryMarshal.GetReference(destination); + for (int i = 0; i < source.Length; i++) { - Unsafe.Add(ref dBase, i) = ConvertToByte(Unsafe.Add(ref sBase, i)); + Unsafe.Add(ref dBase, (uint)i) = ConvertToByte(Unsafe.Add(ref sBase, (uint)i)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static byte ConvertToByte(float f) => (byte)Numerics.Clamp((f * 255F) + 0.5F, 0, 255F); + private static byte ConvertToByte(float f) => (byte)Numerics.Clamp((f * 255f) + 0.5f, 0, 255f); } diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs index 6e45f1619c..17ccb396d6 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -761,13 +761,10 @@ internal static partial class SimdUtils { DebugGuard.IsTrue(source.Length == destination.Length, nameof(source), "Input spans must be of same length!"); - if ((Vector512.IsHardwareAccelerated && Avx512F.IsSupported) || - Avx2.IsSupported || - Sse2.IsSupported || - AdvSimd.IsSupported) + if (Vector128.IsHardwareAccelerated) { int remainder; - if (Avx512F.IsSupported) + if (Vector512.IsHardwareAccelerated && Avx512F.IsSupported) { remainder = Numerics.ModuloP2(source.Length, Vector512.Count); } @@ -805,7 +802,7 @@ internal static partial class SimdUtils ReadOnlySpan source, Span destination) { - if (Avx512F.IsSupported) + if (Vector512.IsHardwareAccelerated && Avx512F.IsSupported) { DebugVerifySpanInput(source, destination, Vector512.Count); @@ -870,7 +867,7 @@ internal static partial class SimdUtils Unsafe.Add(ref d, 3) = f3; } } - else if (Sse2.IsSupported || AdvSimd.IsSupported) + else if (Vector128.IsHardwareAccelerated) { DebugVerifySpanInput(source, destination, Vector128.Count); @@ -897,7 +894,7 @@ internal static partial class SimdUtils } else { - // Sse2, AdvSimd + // Sse2, AdvSimd, etc Vector128 b = Vector128.LoadUnsafe(ref sourceBase, si); (Vector128 s0, Vector128 s1) = Vector128.Widen(b); (i0, i1) = Vector128.Widen(s0.AsInt16()); @@ -931,13 +928,11 @@ internal static partial class SimdUtils { DebugGuard.IsTrue(source.Length == destination.Length, nameof(source), "Input spans must be of same length!"); - if ((Vector512.IsHardwareAccelerated && Avx512BW.IsSupported) || - (Vector256.IsHardwareAccelerated && Avx2.IsSupported) || - (Vector128.IsHardwareAccelerated && (Sse2.IsSupported || AdvSimd.IsSupported))) + if (Sse2.IsSupported || AdvSimd.IsSupported) { int remainder; - if (Avx512BW.IsSupported) + if (Vector512.IsHardwareAccelerated && Avx512BW.IsSupported) { remainder = Numerics.ModuloP2(source.Length, Vector512.Count); } @@ -977,7 +972,7 @@ internal static partial class SimdUtils ReadOnlySpan source, Span destination) { - if (Avx512BW.IsSupported) + if (Vector512.IsHardwareAccelerated && Avx512BW.IsSupported) { DebugVerifySpanInput(source, destination, Vector512.Count); @@ -1011,8 +1006,7 @@ internal static partial class SimdUtils Unsafe.Add(ref destinationBase, i) = b; } } - else - if (Avx2.IsSupported) + else if (Avx2.IsSupported) { DebugVerifySpanInput(source, destination, Vector256.Count); @@ -1046,7 +1040,7 @@ internal static partial class SimdUtils Unsafe.Add(ref destinationBase, i) = b; } } - else + else if (Sse2.IsSupported || AdvSimd.IsSupported) { // Sse, AdvSimd DebugVerifySpanInput(source, destination, Vector128.Count);