diff options
Diffstat (limited to 'tests/src/JIT/HardwareIntrinsics/X86/Bmi1.X64/AndNot.UInt64.cs')
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/X86/Bmi1.X64/AndNot.UInt64.cs | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Bmi1.X64/AndNot.UInt64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Bmi1.X64/AndNot.UInt64.cs new file mode 100644 index 0000000000..6563b59aa1 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Bmi1.X64/AndNot.UInt64.cs @@ -0,0 +1,242 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public static partial class Program + { + private static void AndNotUInt64() + { + var test = new ScalarBinaryOpTest__AndNotUInt64(); + + if (test.IsSupported) + { + // Validates basic functionality works, using Unsafe.ReadUnaligned + test.RunBasicScenario_UnsafeRead(); + + // Validates calling via reflection works, using Unsafe.ReadUnaligned + test.RunReflectionScenario_UnsafeRead(); + + // Validates passing a static member works + test.RunClsVarScenario(); + + // Validates passing a local works, using Unsafe.ReadUnaligned + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing the field of a local class works + test.RunClassLclFldScenario(); + + // Validates passing an instance member of a class works + test.RunClassFldScenario(); + + // Validates passing the field of a local struct works + test.RunStructLclFldScenario(); + + // Validates passing an instance member of a struct works + test.RunStructFldScenario(); + } + else + { + // Validates we throw on unsupported hardware + test.RunUnsupportedScenario(); + } + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class ScalarBinaryOpTest__AndNotUInt64 + { + private struct TestStruct + { + public UInt64 _fld1; + public UInt64 _fld2; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + testStruct._fld1 = TestLibrary.Generator.GetUInt64(); + testStruct._fld2 = TestLibrary.Generator.GetUInt64(); + + return testStruct; + } + + public void RunStructFldScenario(ScalarBinaryOpTest__AndNotUInt64 testClass) + { + var result = Bmi1.X64.AndNot(_fld1, _fld2); + testClass.ValidateResult(_fld1, _fld2, result); + } + } + + private static UInt64 _data1; + private static UInt64 _data2; + + private static UInt64 _clsVar1; + private static UInt64 _clsVar2; + + private UInt64 _fld1; + private UInt64 _fld2; + + static ScalarBinaryOpTest__AndNotUInt64() + { + _clsVar1 = TestLibrary.Generator.GetUInt64(); + _clsVar2 = TestLibrary.Generator.GetUInt64(); + } + + public ScalarBinaryOpTest__AndNotUInt64() + { + Succeeded = true; + + _fld1 = TestLibrary.Generator.GetUInt64(); + _fld2 = TestLibrary.Generator.GetUInt64(); + + _data1 = TestLibrary.Generator.GetUInt64(); + _data2 = TestLibrary.Generator.GetUInt64(); + } + + public bool IsSupported => Bmi1.X64.IsSupported && (Environment.Is64BitProcess || ((typeof(UInt64) != typeof(long)) && (typeof(UInt64) != typeof(ulong)))); + + public bool Succeeded { get; set; } + + public void RunBasicScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); + + var result = Bmi1.X64.AndNot( + Unsafe.ReadUnaligned<UInt64>(ref Unsafe.As<UInt64, byte>(ref _data1)), + Unsafe.ReadUnaligned<UInt64>(ref Unsafe.As<UInt64, byte>(ref _data2)) + ); + + ValidateResult(_data1, _data2, result); + } + + public void RunReflectionScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); + + var result = typeof(Bmi1.X64).GetMethod(nameof(Bmi1.X64.AndNot), new Type[] { typeof(UInt64), typeof(UInt64) }) + .Invoke(null, new object[] { + Unsafe.ReadUnaligned<UInt64>(ref Unsafe.As<UInt64, byte>(ref _data1)), + Unsafe.ReadUnaligned<UInt64>(ref Unsafe.As<UInt64, byte>(ref _data2)) + }); + + ValidateResult(_data1, _data2, (UInt64)result); + } + + public void RunClsVarScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); + + var result = Bmi1.X64.AndNot( + _clsVar1, + _clsVar2 + ); + + ValidateResult(_clsVar1, _clsVar2, result); + } + + public void RunLclVarScenario_UnsafeRead() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); + + var data1 = Unsafe.ReadUnaligned<UInt64>(ref Unsafe.As<UInt64, byte>(ref _data1)); + var data2 = Unsafe.ReadUnaligned<UInt64>(ref Unsafe.As<UInt64, byte>(ref _data2)); + var result = Bmi1.X64.AndNot(data1, data2); + + ValidateResult(data1, data2, result); + } + + public void RunClassLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); + + var test = new ScalarBinaryOpTest__AndNotUInt64(); + var result = Bmi1.X64.AndNot(test._fld1, test._fld2); + + ValidateResult(test._fld1, test._fld2, result); + } + + public void RunClassFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); + + var result = Bmi1.X64.AndNot(_fld1, _fld2); + ValidateResult(_fld1, _fld2, result); + } + + public void RunStructLclFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); + + var test = TestStruct.Create(); + var result = Bmi1.X64.AndNot(test._fld1, test._fld2); + + ValidateResult(test._fld1, test._fld2, result); + } + + public void RunStructFldScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); + + var test = TestStruct.Create(); + test.RunStructFldScenario(this); + } + + public void RunUnsupportedScenario() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); + + bool succeeded = false; + + try + { + RunBasicScenario_UnsafeRead(); + } + catch (PlatformNotSupportedException) + { + succeeded = true; + } + + if (!succeeded) + { + Succeeded = false; + } + } + + private void ValidateResult(UInt64 left, UInt64 right, UInt64 result, [CallerMemberName] string method = "") + { + var isUnexpectedResult = false; + + isUnexpectedResult = ((~left & right) != result); + + if (isUnexpectedResult) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Bmi1.X64)}.{nameof(Bmi1.X64.AndNot)}<UInt64>(UInt64, UInt64): AndNot failed:"); + TestLibrary.TestFramework.LogInformation($" left: {left}"); + TestLibrary.TestFramework.LogInformation($" right: {right}"); + TestLibrary.TestFramework.LogInformation($" result: {result}"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + } +} |