Skip to content

Commit b6bb006

Browse files
committed
Add support for disabling ARM intrinsics
1 parent 0db1771 commit b6bb006

File tree

2 files changed

+74
-11
lines changed

2 files changed

+74
-11
lines changed

tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities
1414
/// </summary>
1515
public static class FeatureTestRunner
1616
{
17-
private static readonly char[] SplitChars = new[] { ',', ' ' };
17+
private static readonly char[] SplitChars = { ',', ' ' };
1818

1919
/// <summary>
2020
/// Allows the deserialization of parameters passed to the feature test.
@@ -349,7 +349,7 @@ public static void RunWithHwIntrinsicsFeature<T>(
349349

350350
internal static Dictionary<HwIntrinsics, string> ToFeatureKeyValueCollection(this HwIntrinsics intrinsics)
351351
{
352-
// Loop through and translate the given values into COMPlus equivaluents
352+
// Loop through and translate the given values into COMPlus equivalents.
353353
var features = new Dictionary<HwIntrinsics, string>();
354354
foreach (string intrinsic in intrinsics.ToString("G").Split(SplitChars, StringSplitOptions.RemoveEmptyEntries))
355355
{
@@ -407,6 +407,12 @@ public enum HwIntrinsics
407407
DisableBMI1 = 1 << 14,
408408
DisableBMI2 = 1 << 15,
409409
DisableLZCNT = 1 << 16,
410-
AllowAll = 1 << 17
410+
DisableArm64AdvSimd = 1 << 17,
411+
DisableArm64Crc32 = 1 << 18,
412+
DisableArm64Dp = 1 << 19,
413+
DisableArm64Aes = 1 << 20,
414+
DisableArm64Sha1 = 1 << 21,
415+
DisableArm64Sha256 = 1 << 22,
416+
AllowAll = 1 << 23
411417
}
412418
}

tests/ImageSharp.Tests/TestUtilities/Tests/FeatureTestRunnerTests.cs

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
using System.Numerics;
88
#if SUPPORTS_RUNTIME_INTRINSICS
99
using System.Runtime.Intrinsics.X86;
10+
using Aes = System.Runtime.Intrinsics.X86.Aes;
11+
#if NET5_0_OR_GREATER
12+
using System.Runtime.Intrinsics.Arm;
13+
#endif
1014
#endif
1115
using Xunit;
1216
using Xunit.Abstractions;
@@ -16,11 +20,11 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests
1620
public class FeatureTestRunnerTests
1721
{
1822
public static TheoryData<HwIntrinsics, string[]> Intrinsics =>
19-
new TheoryData<HwIntrinsics, string[]>
23+
new()
2024
{
21-
{ HwIntrinsics.DisableAES | HwIntrinsics.AllowAll, new string[] { "EnableAES", "AllowAll" } },
22-
{ HwIntrinsics.DisableSIMD | HwIntrinsics.DisableHWIntrinsic, new string[] { "FeatureSIMD", "EnableHWIntrinsic" } },
23-
{ HwIntrinsics.DisableSSE42 | HwIntrinsics.DisableAVX, new string[] { "EnableSSE42", "EnableAVX" } }
25+
{ HwIntrinsics.DisableAES | HwIntrinsics.AllowAll, new[] { "EnableAES", "AllowAll" } },
26+
{ HwIntrinsics.DisableSIMD | HwIntrinsics.DisableHWIntrinsic, new[] { "FeatureSIMD", "EnableHWIntrinsic" } },
27+
{ HwIntrinsics.DisableSSE42 | HwIntrinsics.DisableAVX, new[] { "EnableSSE42", "EnableAVX" } }
2428
};
2529

2630
[Theory]
@@ -56,12 +60,9 @@ public void AllowsAllHwIntrinsicFeatures()
5660
}
5761

5862
[Fact]
59-
public void CanLimitHwIntrinsicSIMDFeatures()
60-
{
61-
FeatureTestRunner.RunWithHwIntrinsicsFeature(
63+
public void CanLimitHwIntrinsicSIMDFeatures() => FeatureTestRunner.RunWithHwIntrinsicsFeature(
6264
() => Assert.False(Vector.IsHardwareAccelerated),
6365
HwIntrinsics.DisableSIMD);
64-
}
6566

6667
#if SUPPORTS_RUNTIME_INTRINSICS
6768
[Fact]
@@ -121,6 +122,14 @@ static void AssertHwIntrinsicsFeatureDisabled(string intrinsic)
121122
Assert.False(Bmi1.IsSupported);
122123
Assert.False(Bmi2.IsSupported);
123124
Assert.False(Lzcnt.IsSupported);
125+
#if NET5_0_OR_GREATER
126+
Assert.False(AdvSimd.IsSupported);
127+
Assert.False(System.Runtime.Intrinsics.Arm.Aes.IsSupported);
128+
Assert.False(Crc32.IsSupported);
129+
Assert.False(Dp.IsSupported);
130+
Assert.False(Sha1.IsSupported);
131+
Assert.False(Sha256.IsSupported);
132+
#endif
124133
break;
125134
case HwIntrinsics.DisableSSE:
126135
Assert.False(Sse.IsSupported);
@@ -167,6 +176,26 @@ static void AssertHwIntrinsicsFeatureDisabled(string intrinsic)
167176
case HwIntrinsics.DisableLZCNT:
168177
Assert.False(Lzcnt.IsSupported);
169178
break;
179+
#if NET5_0_OR_GREATER
180+
case HwIntrinsics.DisableArm64AdvSimd:
181+
Assert.False(AdvSimd.IsSupported);
182+
break;
183+
case HwIntrinsics.DisableArm64Aes:
184+
Assert.False(System.Runtime.Intrinsics.Arm.Aes.IsSupported);
185+
break;
186+
case HwIntrinsics.DisableArm64Crc32:
187+
Assert.False(Crc32.IsSupported);
188+
break;
189+
case HwIntrinsics.DisableArm64Dp:
190+
Assert.False(Dp.IsSupported);
191+
break;
192+
case HwIntrinsics.DisableArm64Sha1:
193+
Assert.False(Sha1.IsSupported);
194+
break;
195+
case HwIntrinsics.DisableArm64Sha256:
196+
Assert.False(Sha256.IsSupported);
197+
break;
198+
#endif
170199
#endif
171200
}
172201
}
@@ -226,6 +255,14 @@ static void AssertHwIntrinsicsFeatureDisabled(string serializable, string intrin
226255
Assert.False(Bmi1.IsSupported);
227256
Assert.False(Bmi2.IsSupported);
228257
Assert.False(Lzcnt.IsSupported);
258+
#if NET5_0_OR_GREATER
259+
Assert.False(AdvSimd.IsSupported);
260+
Assert.False(System.Runtime.Intrinsics.Arm.Aes.IsSupported);
261+
Assert.False(Crc32.IsSupported);
262+
Assert.False(Dp.IsSupported);
263+
Assert.False(Sha1.IsSupported);
264+
Assert.False(Sha256.IsSupported);
265+
#endif
229266
break;
230267
case HwIntrinsics.DisableSSE:
231268
Assert.False(Sse.IsSupported);
@@ -272,6 +309,26 @@ static void AssertHwIntrinsicsFeatureDisabled(string serializable, string intrin
272309
case HwIntrinsics.DisableLZCNT:
273310
Assert.False(Lzcnt.IsSupported);
274311
break;
312+
#if NET5_0_OR_GREATER
313+
case HwIntrinsics.DisableArm64AdvSimd:
314+
Assert.False(AdvSimd.IsSupported);
315+
break;
316+
case HwIntrinsics.DisableArm64Aes:
317+
Assert.False(System.Runtime.Intrinsics.Arm.Aes.IsSupported);
318+
break;
319+
case HwIntrinsics.DisableArm64Crc32:
320+
Assert.False(Crc32.IsSupported);
321+
break;
322+
case HwIntrinsics.DisableArm64Dp:
323+
Assert.False(Dp.IsSupported);
324+
break;
325+
case HwIntrinsics.DisableArm64Sha1:
326+
Assert.False(Sha1.IsSupported);
327+
break;
328+
case HwIntrinsics.DisableArm64Sha256:
329+
Assert.False(Sha256.IsSupported);
330+
break;
331+
#endif
275332
#endif
276333
}
277334
}

0 commit comments

Comments
 (0)