Skip to content

Commit 5125a04

Browse files
Rename utils, organize BlockF8x8
1 parent 29a5635 commit 5125a04

22 files changed

+624
-578
lines changed

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

Lines changed: 97 additions & 97 deletions
Large diffs are not rendered by default.

src/ImageSharp/Common/Helpers/Vector128Utilities.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ namespace SixLabors.ImageSharp.Common.Helpers;
1919
/// </list>
2020
/// Should only be used if the intrinsics are available.
2121
/// </summary>
22-
internal static class Vector128Utilities
22+
#pragma warning disable SA1649 // File name should match first type name
23+
internal static class Vector128_
24+
#pragma warning restore SA1649 // File name should match first type name
2325
{
2426
/// <summary>
2527
/// Gets a value indicating whether shuffle operations are supported.
@@ -314,8 +316,8 @@ public static Vector128<short> PackSignedSaturate(Vector128<int> left, Vector128
314316
return Vector128.Narrow(lefClamped, rightClamped);
315317
}
316318

317-
/// <summary
318-
/// >Restricts a vector between a minimum and a maximum value.
319+
/// <summary>
320+
/// Restricts a vector between a minimum and a maximum value.
319321
/// </summary>
320322
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
321323
/// <param name="value">The vector to restrict.</param>

src/ImageSharp/Common/Helpers/Vector256Utilities.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace SixLabors.ImageSharp.Common.Helpers;
1717
/// </list>
1818
/// Should only be used if the intrinsics are available.
1919
/// </summary>
20-
internal static class Vector256Utilities
20+
#pragma warning disable SA1649 // File name should match first type name
21+
internal static class Vector256_
22+
#pragma warning restore SA1649 // File name should match first type name
2123
{
2224
/// <summary>
2325
/// Gets a value indicating whether shuffle byte operations are supported.
@@ -152,6 +154,18 @@ public static Vector256<float> MultiplyAdd(
152154
return va + (vm0 * vm1);
153155
}
154156

157+
/// <summary>
158+
/// Restricts a vector between a minimum and a maximum value.
159+
/// </summary>
160+
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
161+
/// <param name="value">The vector to restrict.</param>
162+
/// <param name="min">The minimum value.</param>
163+
/// <param name="max">The maximum value.</param>
164+
/// <returns>The restricted <see cref="Vector256{T}"/>.</returns>
165+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
166+
public static Vector256<T> Clamp<T>(Vector256<T> value, Vector256<T> min, Vector256<T> max)
167+
=> Vector256.Min(Vector256.Max(value, min), max);
168+
155169
[DoesNotReturn]
156170
private static void ThrowUnreachableException() => throw new UnreachableException();
157171
}

src/ImageSharp/Common/Helpers/Vector512Utilities.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace SixLabors.ImageSharp.Common.Helpers;
1717
/// </list>
1818
/// Should only be used if the intrinsics are available.
1919
/// </summary>
20-
internal static class Vector512Utilities
20+
#pragma warning disable SA1649 // File name should match first type name
21+
internal static class Vector512_
22+
#pragma warning restore SA1649 // File name should match first type name
2123
{
2224
/// <summary>
2325
/// Gets a value indicating whether shuffle float operations are supported.
@@ -126,6 +128,13 @@ public static Vector512<float> RoundToNearestInteger(Vector512<float> vector)
126128
return Avx512F.RoundScale(vector, 0b0000_1000);
127129
}
128130

131+
if (Avx.IsSupported)
132+
{
133+
Vector256<float> lower = Avx.RoundToNearestInteger(vector.GetLower());
134+
Vector256<float> upper = Avx.RoundToNearestInteger(vector.GetUpper());
135+
return Vector512.Create(lower, upper);
136+
}
137+
129138
Vector512<float> sign = vector & Vector512.Create(-0F);
130139
Vector512<float> val_2p23_f32 = sign | Vector512.Create(8388608F);
131140

@@ -152,9 +161,28 @@ public static Vector512<float> MultiplyAdd(
152161
return Avx512F.FusedMultiplyAdd(vm0, vm1, va);
153162
}
154163

164+
if (Fma.IsSupported)
165+
{
166+
Vector256<float> lower = Fma.MultiplyAdd(vm0.GetLower(), vm1.GetLower(), va.GetLower());
167+
Vector256<float> upper = Fma.MultiplyAdd(vm0.GetUpper(), vm1.GetUpper(), va.GetUpper());
168+
return Vector512.Create(lower, upper);
169+
}
170+
155171
return va + (vm0 * vm1);
156172
}
157173

174+
/// <summary>
175+
/// Restricts a vector between a minimum and a maximum value.
176+
/// </summary>
177+
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
178+
/// <param name="value">The vector to restrict.</param>
179+
/// <param name="min">The minimum value.</param>
180+
/// <param name="max">The maximum value.</param>
181+
/// <returns>The restricted <see cref="Vector512{T}"/>.</returns>
182+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
183+
public static Vector512<T> Clamp<T>(Vector512<T> value, Vector512<T> min, Vector512<T> max)
184+
=> Vector512.Min(Vector512.Max(value, min), max);
185+
158186
[DoesNotReturn]
159187
private static void ThrowUnreachableException() => throw new UnreachableException();
160188
}

src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)