diff options
author | Tanner Gooding <tagoo@outlook.com> | 2018-02-03 00:13:27 -0800 |
---|---|---|
committer | Tanner Gooding <tagoo@outlook.com> | 2018-02-03 07:48:26 -0800 |
commit | eb54e48b13fdfb7233b7bcd32b93792ba3e89f0c (patch) | |
tree | 997df9b57cef5f58d73395b3d17aea2e61123940 /tests | |
parent | 41f8b17ae1741dbcb15eaf0e7456c82548672889 (diff) | |
download | coreclr-eb54e48b13fdfb7233b7bcd32b93792ba3e89f0c.tar.gz coreclr-eb54e48b13fdfb7233b7bcd32b93792ba3e89f0c.tar.bz2 coreclr-eb54e48b13fdfb7233b7bcd32b93792ba3e89f0c.zip |
Updating the templated x86 hwintrinsic tests to validate Load and LoadAligned
Diffstat (limited to 'tests')
60 files changed, 6419 insertions, 1446 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs deleted file mode 100644 index 31614a08ec..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs +++ /dev/null @@ -1,324 +0,0 @@ -// 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. -// - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics.X86; -using System.Runtime.Intrinsics; - -namespace IntelHardwareIntrinsicTest -{ - static class Program - { - const int Pass = 100; - const int Fail = 0; - - static unsafe int Main(string[] args) - { - int testResult = Pass; - - if (Avx2.IsSupported) - { - using (TestTable<int> intTable = new TestTable<int>(new int[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new int[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new int[8])) - using (TestTable<long> longTable = new TestTable<long>(new long[4] { 1, -5, 100, 0 }, new long[4] { 22, -1, -50, 0 }, new long[4])) - using (TestTable<uint> uintTable = new TestTable<uint>(new uint[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new uint[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new uint[8])) - using (TestTable<ulong> ulongTable = new TestTable<ulong>(new ulong[4] { 1, 5, 100, 0 }, new ulong[4] { 22, 1, 50, 0 }, new ulong[4])) - using (TestTable<short> shortTable = new TestTable<short>(new short[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new short[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new short[16])) - using (TestTable<ushort> ushortTable = new TestTable<ushort>(new ushort[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[16])) - using (TestTable<sbyte> sbyteTable = new TestTable<sbyte>(new sbyte[32] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[32] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[32])) - using (TestTable<byte> byteTable = new TestTable<byte>(new byte[32] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[32] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[32])) - { - - var vi1 = Unsafe.Read<Vector256<int>>(intTable.inArray1Ptr); - var vi2 = Unsafe.Read<Vector256<int>>(intTable.inArray2Ptr); - var vi3 = Avx2.Add(vi1, vi2); - Unsafe.Write(intTable.outArrayPtr, vi3); - - if (!intTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on int:"); - foreach (var item in intTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vi3 = (Vector256<int>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vi1.GetType(), vi2.GetType() }).Invoke(null, new object[] { vi1, vi2 }); - Unsafe.Write(intTable.outArrayPtr, vi3); - - if (!intTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on int:"); - foreach (var item in intTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - var vl1 = Unsafe.Read<Vector256<long>>(longTable.inArray1Ptr); - var vl2 = Unsafe.Read<Vector256<long>>(longTable.inArray2Ptr); - var vl3 = Avx2.Add(vl1, vl2); - Unsafe.Write(longTable.outArrayPtr, vl3); - - if (!longTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on long:"); - foreach (var item in longTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vl3 = (Vector256<long>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vl1.GetType(), vl2.GetType() }).Invoke(null, new object[] { vl1, vl2 }); - Unsafe.Write(longTable.outArrayPtr, vl3); - - if (!longTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on long:"); - foreach (var item in longTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - var vui1 = Unsafe.Read<Vector256<uint>>(uintTable.inArray1Ptr); - var vui2 = Unsafe.Read<Vector256<uint>>(uintTable.inArray2Ptr); - var vui3 = Avx2.Add(vui1, vui2); - Unsafe.Write(uintTable.outArrayPtr, vui3); - - if (!uintTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on uint:"); - foreach (var item in uintTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vui3 = (Vector256<uint>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vui1.GetType(), vui2.GetType() }).Invoke(null, new object[] { vui1, vui2 }); - Unsafe.Write(uintTable.outArrayPtr, vui3); - - if (!uintTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on uint:"); - foreach (var item in uintTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - var vul1 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray1Ptr); - var vul2 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray2Ptr); - var vul3 = Avx2.Add(vul1, vul2); - Unsafe.Write(ulongTable.outArrayPtr, vul3); - - if (!ulongTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on ulong:"); - foreach (var item in ulongTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vul3 = (Vector256<ulong>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vul1.GetType(), vul2.GetType() }).Invoke(null, new object[] { vul1, vul2 }); - Unsafe.Write(ulongTable.outArrayPtr, vul3); - - if (!ulongTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on ulong:"); - foreach (var item in ulongTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - var vs1 = Unsafe.Read<Vector256<short>>(shortTable.inArray1Ptr); - var vs2 = Unsafe.Read<Vector256<short>>(shortTable.inArray2Ptr); - var vs3 = Avx2.Add(vs1, vs2); - Unsafe.Write(shortTable.outArrayPtr, vs3); - - if (!shortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on short:"); - foreach (var item in shortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vs3 = (Vector256<short>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vs1.GetType(), vs2.GetType() }).Invoke(null, new object[] { vs1, vs2 }); - Unsafe.Write(shortTable.outArrayPtr, vs3); - - if (!shortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on short:"); - foreach (var item in shortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - var vus1 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray1Ptr); - var vus2 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray2Ptr); - var vus3 = Avx2.Add(vus1, vus2); - Unsafe.Write(ushortTable.outArrayPtr, vus3); - - if (!ushortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on ushort:"); - foreach (var item in ushortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vus3 = (Vector256<ushort>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vus1.GetType(), vus2.GetType() }).Invoke(null, new object[] { vus1, vus2 }); - Unsafe.Write(ushortTable.outArrayPtr, vus3); - - if (!ushortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on ushort:"); - foreach (var item in ushortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - var vsb1 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray1Ptr); - var vsb2 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray2Ptr); - var vsb3 = Avx2.Add(vsb1, vsb2); - Unsafe.Write(sbyteTable.outArrayPtr, vsb3); - - if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on sbyte:"); - foreach (var item in sbyteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vsb3 = (Vector256<sbyte>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vsb1.GetType(), vsb2.GetType() }).Invoke(null, new object[] { vsb1, vsb2 }); - Unsafe.Write(sbyteTable.outArrayPtr, vsb3); - - if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on sbyte:"); - foreach (var item in sbyteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - var vb1 = Unsafe.Read<Vector256<byte>>(byteTable.inArray1Ptr); - var vb2 = Unsafe.Read<Vector256<byte>>(byteTable.inArray2Ptr); - var vb3 = Avx2.Add(vb1, vb2); - Unsafe.Write(byteTable.outArrayPtr, vb3); - - if (!byteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on byte:"); - foreach (var item in byteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - vb3 = (Vector256<byte>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vb1.GetType(), vb2.GetType() }).Invoke(null, new object[] { vb1, vb2 }); - Unsafe.Write(byteTable.outArrayPtr, vb3); - - if (!byteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed via reflection on byte:"); - foreach (var item in byteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - } - } - - return testResult; - } - - public unsafe struct TestTable<T> : IDisposable where T : struct - { - public T[] inArray1; - public T[] inArray2; - public T[] outArray; - - public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); - public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); - public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); - - GCHandle inHandle1; - GCHandle inHandle2; - GCHandle outHandle; - public TestTable(T[] a, T[] b, T[] c) - { - this.inArray1 = a; - this.inArray2 = b; - this.outArray = c; - - inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); - inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); - outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); - } - public bool CheckResult(Func<T, T, T, bool> check) - { - for (int i = 0; i < inArray1.Length; i++) - { - if (!check(inArray1[i], inArray2[i], outArray[i])) - { - return false; - } - } - return true; - } - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - outHandle.Free(); - } - } - - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest.template b/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest.template index a8ea21cef8..a3d275190a 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest.template +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest.template @@ -19,23 +19,41 @@ namespace JIT.HardwareIntrinsics.X86 {{ public static partial class Program {{ - private static void {1}{2}() + private static void {2}{3}() {{ - var test = new BooleanComparisonOpTest__{1}{2}(); + var test = new BooleanComparisonOpTest__{2}{3}(); if (test.IsSupported) {{ - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -56,73 +74,115 @@ namespace JIT.HardwareIntrinsics.X86 }} }} - public sealed unsafe class BooleanComparisonOpTest__{1}{2} + public sealed unsafe class BooleanComparisonOpTest__{2}{3} {{ - private const int VectorSize = {4}; - private const int ElementCount = VectorSize / sizeof({2}); + private const int VectorSize = {5}; + private const int ElementCount = VectorSize / sizeof({3}); - private static {2}[] _data1 = new {2}[ElementCount]; - private static {2}[] _data2 = new {2}[ElementCount]; + private static {3}[] _data1 = new {3}[ElementCount]; + private static {3}[] _data2 = new {3}[ElementCount]; - private static {3}<{2}> _clsVar1; - private static {3}<{2}> _clsVar2; + private static {4}<{3}> _clsVar1; + private static {4}<{3}> _clsVar2; - private {3}<{2}> _fld1; - private {3}<{2}> _fld2; + private {4}<{3}> _fld1; + private {4}<{3}> _fld2; - private BooleanComparisonOpTest__DataTable<{2}> _dataTable; + private BooleanComparisonOpTest__DataTable<{3}> _dataTable; - static BooleanComparisonOpTest__{1}{2}() + static BooleanComparisonOpTest__{2}{3}() {{ var random = new Random(); - for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _clsVar1), ref Unsafe.As<{2}, byte>(ref _data2[0]), VectorSize); - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _clsVar2), ref Unsafe.As<{2}, byte>(ref _data1[0]), VectorSize); + for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {6}; _data2[i] = {6}; }} + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _clsVar1), ref Unsafe.As<{3}, byte>(ref _data2[0]), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _clsVar2), ref Unsafe.As<{3}, byte>(ref _data1[0]), VectorSize); }} - public BooleanComparisonOpTest__{1}{2}() + public BooleanComparisonOpTest__{2}{3}() {{ Succeeded = true; var random = new Random(); - for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _fld1), ref Unsafe.As<{2}, byte>(ref _data1[0]), VectorSize); - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _fld2), ref Unsafe.As<{2}, byte>(ref _data2[0]), VectorSize); + for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {6}; _data2[i] = {6}; }} + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _fld1), ref Unsafe.As<{3}, byte>(ref _data1[0]), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _fld2), ref Unsafe.As<{3}, byte>(ref _data2[0]), VectorSize); - for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} - _dataTable = new BooleanComparisonOpTest__DataTable<{2}>(_data1, _data2); + for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {6}; _data2[i] = {6}; }} + _dataTable = new BooleanComparisonOpTest__DataTable<{3}>(_data1, _data2, VectorSize); }} public bool IsSupported => {0}.IsSupported; public bool Succeeded {{ get; set; }} - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() + {{ + var result = {0}.{2}( + Unsafe.Read<{4}<{3}>>(_dataTable.inArray1Ptr), + Unsafe.Read<{4}<{3}>>(_dataTable.inArray2Ptr) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + }} + + public void RunBasicScenario_Load() {{ - var result = {0}.{1}( - Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr), - Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr) + var result = {0}.{2}( + {1}.Load{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.Load{4}(({3}*)(_dataTable.inArray2Ptr)) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + }} + + public void RunBasicScenario_LoadAligned() + {{ + var result = {0}.{2}( + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + }} + + public void RunReflectionScenario_UnsafeRead() + {{ + var result = typeof({0}).GetMethod(nameof({0}.{2}), new Type[] {{ typeof({4}<{3}>), typeof({4}<{3}>) }}) + .Invoke(null, new object[] {{ + Unsafe.Read<{4}<{3}>>(_dataTable.inArray1Ptr), + Unsafe.Read<{4}<{3}>>(_dataTable.inArray2Ptr) + }}); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); }} - public void RunReflectionScenario() + public void RunReflectionScenario_Load() {{ - var result = typeof({0}).GetMethod(nameof({0}.{1}), new Type[] {{ typeof({3}<{2}>), typeof({3}<{2}>) }}) + var result = typeof({0}).GetMethod(nameof({0}.{2}), new Type[] {{ typeof({4}<{3}>), typeof({4}<{3}>) }}) .Invoke(null, new object[] {{ - Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr), - Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr) + {1}.Load{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.Load{4}(({3}*)(_dataTable.inArray2Ptr)) }}); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + }} + + public void RunReflectionScenario_LoadAligned() + {{ + var result = typeof({0}).GetMethod(nameof({0}.{2}), new Type[] {{ typeof({4}<{3}>), typeof({4}<{3}>) }}) + .Invoke(null, new object[] {{ + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray2Ptr)) + }}); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); }} public void RunClsVarScenario() {{ - var result = {0}.{1}( + var result = {0}.{2}( _clsVar1, _clsVar2 ); @@ -130,26 +190,44 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); }} - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() + {{ + var left = Unsafe.Read<{4}<{3}>>(_dataTable.inArray1Ptr); + var right = Unsafe.Read<{4}<{3}>>(_dataTable.inArray2Ptr); + var result = {0}.{2}(left, right); + + ValidateResult(left, right, result); + }} + + public void RunLclVarScenario_Load() {{ - var left = Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr); - var right = Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr); - var result = {0}.{1}(left, right); + var left = {1}.Load{4}(({3}*)(_dataTable.inArray1Ptr)); + var right = {1}.Load{4}(({3}*)(_dataTable.inArray2Ptr)); + var result = {0}.{2}(left, right); + + ValidateResult(left, right, result); + }} + + public void RunLclVarScenario_LoadAligned() + {{ + var left = {1}.LoadAligned{4}(({3}*)(_dataTable.inArray1Ptr)); + var right = {1}.LoadAligned{4}(({3}*)(_dataTable.inArray2Ptr)); + var result = {0}.{2}(left, right); ValidateResult(left, right, result); }} public void RunLclFldScenario() {{ - var test = new BooleanComparisonOpTest__{1}{2}(); - var result = {0}.{1}(test._fld1, test._fld2); + var test = new BooleanComparisonOpTest__{2}{3}(); + var result = {0}.{2}(test._fld1, test._fld2); ValidateResult(test._fld1, test._fld2, result); }} public void RunFldScenario() {{ - var result = {0}.{1}(_fld1, _fld2); + var result = {0}.{2}(_fld1, _fld2); ValidateResult(_fld1, _fld2, result); }} @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try {{ - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); }} catch (PlatformNotSupportedException) {{ @@ -168,10 +246,10 @@ namespace JIT.HardwareIntrinsics.X86 }} }} - private void ValidateResult({3}<{2}> left, {3}<{2}> right, bool result, [CallerMemberName] string method = "") + private void ValidateResult({4}<{3}> left, {4}<{3}> right, bool result, [CallerMemberName] string method = "") {{ - {2}[] inArray1 = new {2}[ElementCount]; - {2}[] inArray2 = new {2}[ElementCount]; + {3}[] inArray1 = new {3}[ElementCount]; + {3}[] inArray2 = new {3}[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); @@ -179,13 +257,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); }} - private void ValidateResult({2}[] left, {2}[] right, bool result, [CallerMemberName] string method = "") + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + {{ + {3}[] inArray1 = new {3}[ElementCount]; + {3}[] inArray2 = new {3}[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + }} + + private void ValidateResult({3}[] left, {3}[] right, bool result, [CallerMemberName] string method = "") {{ - if ({6}) + if ({7}) {{ Succeeded = false; - Console.WriteLine($"{{nameof({0})}}.{{nameof({0}.{1})}}<{2}>: {{method}} failed:"); + Console.WriteLine($"{{nameof({0})}}.{{nameof({0}.{2})}}<{3}>: {{method}} failed:"); Console.WriteLine($" left: ({{string.Join(", ", left)}})"); Console.WriteLine($" right: ({{string.Join(", ", right)}})"); Console.WriteLine($" result: ({{string.Join(", ", result)}})"); diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest_DataTable.cs b/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest_DataTable.cs index 56f07fb685..1315624e37 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest_DataTable.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest_DataTable.cs @@ -12,28 +12,45 @@ namespace JIT.HardwareIntrinsics.X86 { public unsafe struct BooleanComparisonOpTest__DataTable<T> : IDisposable where T : struct { + private byte[] inArray1; + private byte[] inArray2; + private GCHandle inHandle1; private GCHandle inHandle2; - public T[] inArray1; - public T[] inArray2; + private byte simdSize; - public BooleanComparisonOpTest__DataTable(T[] inArray1, T[] inArray2) + public BooleanComparisonOpTest__DataTable(T[] inArray1, T[] inArray2, int simdSize) { - this.inArray1 = inArray1; - this.inArray2 = inArray2; + this.inArray1 = new byte[simdSize * 2]; + this.inArray2 = new byte[simdSize * 2]; + + this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); + this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - this.inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); + this.simdSize = unchecked((byte)(simdSize)); + + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<T, byte>(ref inArray1[0]), this.simdSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<T, byte>(ref inArray2[0]), this.simdSize); } - public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); - public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); + public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), simdSize); + public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), simdSize); public void Dispose() { inHandle1.Free(); inHandle2.Free(); } + + private static unsafe void* Align(byte* buffer, byte expectedAlignment) + { + // Compute how bad the misalignment is, which is at most (expectedAlignment - 1). + // Then subtract that from the expectedAlignment and add it to the original address + // to compute the aligned address. + + var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment); + return (void*)(buffer + misalignment); + } } } diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx index c5850cb1d4..5848273cc3 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx @@ -20,95 +20,95 @@ using System.IO; private static readonly (string templateFileName, string[] templateData)[] SseInputs = new [] { - // TemplateName Isa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults - ("SimpleBinOpTest.template", new string[] { "Sse", "Add", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] + right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] + right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "AddScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] + right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "And", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "AndNot", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(~BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(~BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] == right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] == right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] == right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] == right[0]) != result"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] == right[0]) != result"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareGreaterThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] > right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareGreaterThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareGreaterThanOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] > right[0]) != result"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareGreaterThanUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] > right[0]) != result"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareGreaterThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] >= right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareGreaterThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareGreaterThanOrEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] >= right[0]) != result"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareGreaterThanOrEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] >= right[0]) != result"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareLessThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] < right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareLessThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareLessThanOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] < right[0]) != result"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareLessThanUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] < right[0]) != result"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareLessThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] <= right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareLessThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareLessThanOrEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] <= right[0]) != result"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareLessThanOrEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] <= right[0]) != result"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] != right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] != right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] != right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareNotEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] != right[0]) != result"}), - ("BooleanCmpOpTest.template", new string[] { "Sse", "CompareNotEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] != right[0]) != result"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotGreaterThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] > right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotGreaterThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotGreaterThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] >= right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotGreaterThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotLessThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] < right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotLessThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotLessThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] <= right[i]) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareNotLessThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareOrdered", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((!float.IsNaN(left[0]) && !float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((!float.IsNaN(left[i]) && !float.IsNaN(right[i])) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((!float.IsNaN(left[0]) && !float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareUnordered", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((float.IsNaN(left[0]) || float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((float.IsNaN(left[i]) || float.IsNaN(right[i])) ? -1 : 0)"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "CompareUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((float.IsNaN(left[0]) || float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "Divide", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] / right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] / right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "DivideScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] / right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "Max", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Max(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(Math.Max(left[i], right[i])) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "MaxScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Max(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "Min", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Min(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(Math.Min(left[i], right[i])) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "MinScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Min(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "Multiply", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] * right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] * right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "MultiplyScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] * right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "Or", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(BitConverter.SingleToInt32Bits(left[0]) | BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(BitConverter.SingleToInt32Bits(left[0]) | BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "Subtract", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] - right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] - right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "SubtractScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] - right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse", "Xor", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(BitConverter.SingleToInt32Bits(left[0]) ^ BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(BitConverter.SingleToInt32Bits(left[0]) ^ BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), + // TemplateName Isa, LoadIsa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Add", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] + right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] + right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "AddScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] + right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "And", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "AndNot", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(~BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(~BitConverter.SingleToInt32Bits(left[0]) & BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] == right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] == right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] == right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] == right[0]) != result"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] == right[0]) != result"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] > right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThanOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] > right[0]) != result"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThanUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] > right[0]) != result"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] >= right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThanOrEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] >= right[0]) != result"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareGreaterThanOrEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] >= right[0]) != result"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareLessThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] < right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareLessThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareLessThanOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] < right[0]) != result"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareLessThanUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] < right[0]) != result"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareLessThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] <= right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareLessThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareLessThanOrEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] <= right[0]) != result"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareLessThanOrEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] <= right[0]) != result"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] != right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((left[i] != right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((left[0] != right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareNotEqualOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] != right[0]) != result"}), + ("BooleanCmpOpTest.template", new string[] { "Sse", "Sse", "CompareNotEqualUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(left[0] != right[0]) != result"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotGreaterThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] > right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotGreaterThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] > right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotGreaterThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] >= right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotGreaterThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] >= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotLessThan", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] < right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotLessThanScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] < right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotLessThanOrEqual", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != (!(left[i] <= right[i]) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareNotLessThanOrEqualScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != (!(left[0] <= right[0]) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareOrdered", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((!float.IsNaN(left[0]) && !float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((!float.IsNaN(left[i]) && !float.IsNaN(right[i])) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareOrderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((!float.IsNaN(left[0]) && !float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareUnordered", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((float.IsNaN(left[0]) || float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(result[i]) != ((float.IsNaN(left[i]) || float.IsNaN(right[i])) ? -1 : 0)"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "CompareUnorderedScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(result[0]) != ((float.IsNaN(left[0]) || float.IsNaN(right[0])) ? -1 : 0)", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Divide", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] / right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] / right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "DivideScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] / right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Max", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Max(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(Math.Max(left[i], right[i])) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "MaxScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Max(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Min", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Min(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(Math.Min(left[i], right[i])) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "MinScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(Math.Min(left[0], right[0])) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Multiply", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] * right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] * right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "MultiplyScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] * right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Or", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(BitConverter.SingleToInt32Bits(left[0]) | BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(BitConverter.SingleToInt32Bits(left[0]) | BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Subtract", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] - right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] - right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "SubtractScalar", "Single", "Vector128", "16", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] - right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse", "Sse", "Xor", "Single", "Vector128", "16", "(float)(random.NextDouble())", "(BitConverter.SingleToInt32Bits(left[0]) ^ BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])", "(BitConverter.SingleToInt32Bits(left[0]) ^ BitConverter.SingleToInt32Bits(right[0])) != BitConverter.SingleToInt32Bits(result[0])"}), }; private static readonly (string templateFileName, string[] templateData)[] Sse2Inputs = new [] { - // TemplateName Isa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "Double", "Vector128", "16", "(double)(random.NextDouble())", "BitConverter.DoubleToInt64Bits(left[0] + right[0]) != BitConverter.DoubleToInt64Bits(result[0])", "BitConverter.DoubleToInt64Bits(left[i] + right[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "Byte", "Vector128", "16", "(byte)(random.Next(0, byte.MaxValue))", "(byte)(left[0] + right[0]) != result[0]", "(byte)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "Int16", "Vector128", "16", "(short)(random.Next(short.MinValue, short.MaxValue))", "(short)(left[0] + right[0]) != result[0]", "(short)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "Int32", "Vector128", "16", "(int)(random.Next(int.MinValue, int.MaxValue))", "(int)(left[0] + right[0]) != result[0]", "(int)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "Int64", "Vector128", "16", "(long)(random.Next(int.MinValue, int.MaxValue))", "(long)(left[0] + right[0]) != result[0]", "(long)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "SByte", "Vector128", "16", "(sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue))", "(sbyte)(left[0] + right[0]) != result[0]", "(sbyte)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "UInt16", "Vector128", "16", "(ushort)(random.Next(0, ushort.MaxValue))", "(ushort)(left[0] + right[0]) != result[0]", "(ushort)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "UInt32", "Vector128", "16", "(uint)(random.Next(0, int.MaxValue))", "(uint)(left[0] + right[0]) != result[0]", "(uint)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Sse2", "Add", "UInt64", "Vector128", "16", "(ulong)(random.Next(0, int.MaxValue))", "(ulong)(left[0] + right[0]) != result[0]", "(ulong)(left[i] + right[i]) != result[i]"}), + // TemplateName Isa, LoadIsa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "Double", "Vector128", "16", "(double)(random.NextDouble())", "BitConverter.DoubleToInt64Bits(left[0] + right[0]) != BitConverter.DoubleToInt64Bits(result[0])", "BitConverter.DoubleToInt64Bits(left[i] + right[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "Byte", "Vector128", "16", "(byte)(random.Next(0, byte.MaxValue))", "(byte)(left[0] + right[0]) != result[0]", "(byte)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "Int16", "Vector128", "16", "(short)(random.Next(short.MinValue, short.MaxValue))", "(short)(left[0] + right[0]) != result[0]", "(short)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "Int32", "Vector128", "16", "(int)(random.Next(int.MinValue, int.MaxValue))", "(int)(left[0] + right[0]) != result[0]", "(int)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "Int64", "Vector128", "16", "(long)(random.Next(int.MinValue, int.MaxValue))", "(long)(left[0] + right[0]) != result[0]", "(long)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "SByte", "Vector128", "16", "(sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue))", "(sbyte)(left[0] + right[0]) != result[0]", "(sbyte)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "UInt16", "Vector128", "16", "(ushort)(random.Next(0, ushort.MaxValue))", "(ushort)(left[0] + right[0]) != result[0]", "(ushort)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "UInt32", "Vector128", "16", "(uint)(random.Next(0, int.MaxValue))", "(uint)(left[0] + right[0]) != result[0]", "(uint)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Sse2", "Sse2", "Add", "UInt64", "Vector128", "16", "(ulong)(random.Next(0, int.MaxValue))", "(ulong)(left[0] + right[0]) != result[0]", "(ulong)(left[i] + right[i]) != result[i]"}), }; private static readonly (string templateFileName, string[] templateData)[] AvxInputs = new [] { - // TemplateName Isa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults - ("SimpleBinOpTest.template", new string[] { "Avx", "Add", "Double", "Vector256", "32", "(double)(random.NextDouble())", "BitConverter.DoubleToInt64Bits(left[0] + right[0]) != BitConverter.DoubleToInt64Bits(result[0])", "BitConverter.DoubleToInt64Bits(left[i] + right[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Avx", "Add", "Single", "Vector256", "32", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] + right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] + right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Avx", "Multiply", "Double", "Vector256", "32", "(double)(random.NextDouble())", "BitConverter.DoubleToInt64Bits(left[0] * right[0]) != BitConverter.DoubleToInt64Bits(result[0])", "BitConverter.DoubleToInt64Bits(left[i] * right[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), - ("SimpleBinOpTest.template", new string[] { "Avx", "Multiply", "Single", "Vector256", "32", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] * right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] * right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + // TemplateName Isa, LoadIsa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults + ("SimpleBinOpTest.template", new string[] { "Avx", "Avx", "Add", "Double", "Vector256", "32", "(double)(random.NextDouble())", "BitConverter.DoubleToInt64Bits(left[0] + right[0]) != BitConverter.DoubleToInt64Bits(result[0])", "BitConverter.DoubleToInt64Bits(left[i] + right[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Avx", "Avx", "Add", "Single", "Vector256", "32", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] + right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] + right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Avx", "Avx", "Multiply", "Double", "Vector256", "32", "(double)(random.NextDouble())", "BitConverter.DoubleToInt64Bits(left[0] * right[0]) != BitConverter.DoubleToInt64Bits(result[0])", "BitConverter.DoubleToInt64Bits(left[i] * right[i]) != BitConverter.DoubleToInt64Bits(result[i])"}), + ("SimpleBinOpTest.template", new string[] { "Avx", "Avx", "Multiply", "Single", "Vector256", "32", "(float)(random.NextDouble())", "BitConverter.SingleToInt32Bits(left[0] * right[0]) != BitConverter.SingleToInt32Bits(result[0])", "BitConverter.SingleToInt32Bits(left[i] * right[i]) != BitConverter.SingleToInt32Bits(result[i])"}), }; private static readonly (string templateFileName, string[] templateData)[] Avx2Inputs = new [] { - // TemplateName Isa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "Byte", "Vector256", "32", "(byte)(random.Next(0, byte.MaxValue))", "(byte)(left[0] + right[0]) != result[0]", "(byte)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "Int16", "Vector256", "32", "(short)(random.Next(short.MinValue, short.MaxValue))", "(short)(left[0] + right[0]) != result[0]", "(short)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "Int32", "Vector256", "32", "(int)(random.Next(int.MinValue, int.MaxValue))", "(int)(left[0] + right[0]) != result[0]", "(int)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "Int64", "Vector256", "32", "(long)(random.Next(int.MinValue, int.MaxValue))", "(long)(left[0] + right[0]) != result[0]", "(long)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "SByte", "Vector256", "32", "(sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue))", "(sbyte)(left[0] + right[0]) != result[0]", "(sbyte)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "UInt16", "Vector256", "32", "(ushort)(random.Next(0, ushort.MaxValue))", "(ushort)(left[0] + right[0]) != result[0]", "(ushort)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "UInt32", "Vector256", "32", "(uint)(random.Next(0, int.MaxValue))", "(uint)(left[0] + right[0]) != result[0]", "(uint)(left[i] + right[i]) != result[i]"}), - ("SimpleBinOpTest.template", new string[] { "Avx2", "Add", "UInt64", "Vector256", "32", "(ulong)(random.Next(0, int.MaxValue))", "(ulong)(left[0] + right[0]) != result[0]", "(ulong)(left[i] + right[i]) != result[i]"}), + // TemplateName Isa, LoadIsa, Method, BaseType, VectorType, VectorSize, NextValue, ValidateFirstResult, ValidateRemainingResults + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "Byte", "Vector256", "32", "(byte)(random.Next(0, byte.MaxValue))", "(byte)(left[0] + right[0]) != result[0]", "(byte)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "Int16", "Vector256", "32", "(short)(random.Next(short.MinValue, short.MaxValue))", "(short)(left[0] + right[0]) != result[0]", "(short)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "Int32", "Vector256", "32", "(int)(random.Next(int.MinValue, int.MaxValue))", "(int)(left[0] + right[0]) != result[0]", "(int)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "Int64", "Vector256", "32", "(long)(random.Next(int.MinValue, int.MaxValue))", "(long)(left[0] + right[0]) != result[0]", "(long)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "SByte", "Vector256", "32", "(sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue))", "(sbyte)(left[0] + right[0]) != result[0]", "(sbyte)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "UInt16", "Vector256", "32", "(ushort)(random.Next(0, ushort.MaxValue))", "(ushort)(left[0] + right[0]) != result[0]", "(ushort)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "UInt32", "Vector256", "32", "(uint)(random.Next(0, int.MaxValue))", "(uint)(left[0] + right[0]) != result[0]", "(uint)(left[i] + right[i]) != result[i]"}), + ("SimpleBinOpTest.template", new string[] { "Avx2", "Avx", "Add", "UInt64", "Vector256", "32", "(ulong)(random.Next(0, int.MaxValue))", "(ulong)(left[0] + right[0]) != result[0]", "(ulong)(left[i] + right[i]) != result[i]"}), }; private static void ProcessInputs(string isa, (string templateFileName, string[] templateData)[] inputs) @@ -146,10 +146,10 @@ namespace JIT.HardwareIntrinsics.X86 private static void ProcessInput(StreamWriter testListFile, (string templateFileName, string[] templateData) input) { - var testName = $"{input.templateData[1]}.{input.templateData[2]}"; + var testName = $"{input.templateData[2]}.{input.templateData[3]}"; // Ex: ["Add.Single"] = AddSingle - testListFile.WriteLine($@" [""{testName}""] = {input.templateData[1]}{input.templateData[2]},"); + testListFile.WriteLine($@" [""{testName}""] = {input.templateData[2]}{input.templateData[3]},"); var testFileName = Path.Combine("..", input.templateData[0], $"{testName}.cs"); var template = File.ReadAllText(input.templateFileName); @@ -163,6 +163,8 @@ private static void ProcessInput(StreamWriter testListFile, (string templateFile } ProcessInputs("Sse", SseInputs); -ProcessInputs("Sse2", Sse2Inputs); -ProcessInputs("Avx", AvxInputs); -ProcessInputs("Avx2", Avx2Inputs); + +// TODO-XArch: Re-enable after the Load and LoadAligned intrinsics are implemented for SSE2 and AVX +// ProcessInputs("Sse2", Sse2Inputs); +// ProcessInputs("Avx", AvxInputs); +// ProcessInputs("Avx2", Avx2Inputs); diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/SimpleBinOpTest.template b/tests/src/JIT/HardwareIntrinsics/X86/Shared/SimpleBinOpTest.template index 451cb9a194..feff6f688e 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/SimpleBinOpTest.template +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/SimpleBinOpTest.template @@ -19,23 +19,41 @@ namespace JIT.HardwareIntrinsics.X86 {{ public static partial class Program {{ - private static void {1}{2}() + private static void {2}{3}() {{ - var test = new SimpleBinaryOpTest__{1}{2}(); + var test = new SimpleBinaryOpTest__{2}{3}(); if (test.IsSupported) {{ - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -56,108 +74,174 @@ namespace JIT.HardwareIntrinsics.X86 }} }} - public sealed unsafe class SimpleBinaryOpTest__{1}{2} + public sealed unsafe class SimpleBinaryOpTest__{2}{3} {{ - private const int VectorSize = {4}; - private const int ElementCount = VectorSize / sizeof({2}); + private const int VectorSize = {5}; + private const int ElementCount = VectorSize / sizeof({3}); - private static {2}[] _data1 = new {2}[ElementCount]; - private static {2}[] _data2 = new {2}[ElementCount]; + private static {3}[] _data1 = new {3}[ElementCount]; + private static {3}[] _data2 = new {3}[ElementCount]; - private static {3}<{2}> _clsVar1; - private static {3}<{2}> _clsVar2; + private static {4}<{3}> _clsVar1; + private static {4}<{3}> _clsVar2; - private {3}<{2}> _fld1; - private {3}<{2}> _fld2; + private {4}<{3}> _fld1; + private {4}<{3}> _fld2; - private SimpleBinaryOpTest__DataTable<{2}> _dataTable; + private SimpleBinaryOpTest__DataTable<{3}> _dataTable; - static SimpleBinaryOpTest__{1}{2}() + static SimpleBinaryOpTest__{2}{3}() {{ var random = new Random(); - for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _clsVar1), ref Unsafe.As<{2}, byte>(ref _data2[0]), VectorSize); - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _clsVar2), ref Unsafe.As<{2}, byte>(ref _data1[0]), VectorSize); + for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {6}; _data2[i] = {6}; }} + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _clsVar1), ref Unsafe.As<{3}, byte>(ref _data2[0]), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _clsVar2), ref Unsafe.As<{3}, byte>(ref _data1[0]), VectorSize); }} - public SimpleBinaryOpTest__{1}{2}() + public SimpleBinaryOpTest__{2}{3}() {{ Succeeded = true; var random = new Random(); - for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _fld1), ref Unsafe.As<{2}, byte>(ref _data1[0]), VectorSize); - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _fld2), ref Unsafe.As<{2}, byte>(ref _data2[0]), VectorSize); + for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {6}; _data2[i] = {6}; }} + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _fld1), ref Unsafe.As<{3}, byte>(ref _data1[0]), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{4}<{3}>, byte>(ref _fld2), ref Unsafe.As<{3}, byte>(ref _data2[0]), VectorSize); - for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} - _dataTable = new SimpleBinaryOpTest__DataTable<{2}>(_data1, _data2, new {2}[ElementCount]); + for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {6}; _data2[i] = {6}; }} + _dataTable = new SimpleBinaryOpTest__DataTable<{3}>(_data1, _data2, new {3}[ElementCount], VectorSize); }} public bool IsSupported => {0}.IsSupported; public bool Succeeded {{ get; set; }} - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() + {{ + var result = {0}.{2}( + Unsafe.Read<{4}<{3}>>(_dataTable.inArray1Ptr), + Unsafe.Read<{4}<{3}>>(_dataTable.inArray2Ptr) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + }} + + public void RunBasicScenario_Load() {{ - var result = {0}.{1}( - Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr), - Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr) + var result = {0}.{2}( + {1}.Load{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.Load{4}(({3}*)(_dataTable.inArray2Ptr)) ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); }} - public void RunReflectionScenario() + public void RunBasicScenario_LoadAligned() {{ - var result = typeof({0}).GetMethod(nameof({0}.{1}), new Type[] {{ typeof({3}<{2}>), typeof({3}<{2}>) }}) + var result = {0}.{2}( + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + }} + + public void RunReflectionScenario_UnsafeRead() + {{ + var result = typeof({0}).GetMethod(nameof({0}.{2}), new Type[] {{ typeof({4}<{3}>), typeof({4}<{3}>) }}) .Invoke(null, new object[] {{ - Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr), - Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr) + Unsafe.Read<{4}<{3}>>(_dataTable.inArray1Ptr), + Unsafe.Read<{4}<{3}>>(_dataTable.inArray2Ptr) }}); - Unsafe.Write(_dataTable.outArrayPtr, ({3}<{2}>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + Unsafe.Write(_dataTable.outArrayPtr, ({4}<{3}>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + }} + + public void RunReflectionScenario_Load() + {{ + var result = typeof({0}).GetMethod(nameof({0}.{2}), new Type[] {{ typeof({4}<{3}>), typeof({4}<{3}>) }}) + .Invoke(null, new object[] {{ + {1}.Load{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.Load{4}(({3}*)(_dataTable.inArray2Ptr)) + }}); + + Unsafe.Write(_dataTable.outArrayPtr, ({4}<{3}>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + }} + + public void RunReflectionScenario_LoadAligned() + {{ + var result = typeof({0}).GetMethod(nameof({0}.{2}), new Type[] {{ typeof({4}<{3}>), typeof({4}<{3}>) }}) + .Invoke(null, new object[] {{ + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray1Ptr)), + {1}.LoadAligned{4}(({3}*)(_dataTable.inArray2Ptr)) + }}); + + Unsafe.Write(_dataTable.outArrayPtr, ({4}<{3}>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); }} public void RunClsVarScenario() {{ - var result = {0}.{1}( + var result = {0}.{2}( _clsVar1, _clsVar2 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); + }} + + public void RunLclVarScenario_UnsafeRead() + {{ + var left = Unsafe.Read<{4}<{3}>>(_dataTable.inArray1Ptr); + var right = Unsafe.Read<{4}<{3}>>(_dataTable.inArray2Ptr); + var result = {0}.{2}(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + }} + + public void RunLclVarScenario_Load() + {{ + var left = {1}.Load{4}(({3}*)(_dataTable.inArray1Ptr)); + var right = {1}.Load{4}(({3}*)(_dataTable.inArray2Ptr)); + var result = {0}.{2}(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); }} - public void RunLclVarScenario() + public void RunLclVarScenario_LoadAligned() {{ - var left = Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr); - var right = Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr); - var result = {0}.{1}(left, right); + var left = {1}.LoadAligned{4}(({3}*)(_dataTable.inArray1Ptr)); + var right = {1}.LoadAligned{4}(({3}*)(_dataTable.inArray2Ptr)); + var result = {0}.{2}(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); }} public void RunLclFldScenario() {{ - var test = new SimpleBinaryOpTest__{1}{2}(); - var result = {0}.{1}(test._fld1, test._fld2); + var test = new SimpleBinaryOpTest__{2}{3}(); + var result = {0}.{2}(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); }} public void RunFldScenario() {{ - var result = {0}.{1}(_fld1, _fld2); + var result = {0}.{2}(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); }} public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try {{ - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); }} catch (PlatformNotSupportedException) {{ @@ -174,20 +258,35 @@ namespace JIT.HardwareIntrinsics.X86 }} }} - private void ValidateResult({3}<{2}> left, {3}<{2}> right, {2}[] result, [CallerMemberName] string method = "") + private void ValidateResult({4}<{3}> left, {4}<{3}> right, void* result, [CallerMemberName] string method = "") {{ - {2}[] inArray1 = new {2}[ElementCount]; - {2}[] inArray2 = new {2}[ElementCount]; + {3}[] inArray1 = new {3}[ElementCount]; + {3}[] inArray2 = new {3}[ElementCount]; + {3}[] outArray = new {3}[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + }} + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + {{ + {3}[] inArray1 = new {3}[ElementCount]; + {3}[] inArray2 = new {3}[ElementCount]; + {3}[] outArray = new {3}[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); }} - private void ValidateResult({2}[] left, {2}[] right, {2}[] result, [CallerMemberName] string method = "") + private void ValidateResult({3}[] left, {3}[] right, {3}[] result, [CallerMemberName] string method = "") {{ - if ({6}) + if ({7}) {{ Succeeded = false; }} @@ -195,7 +294,7 @@ namespace JIT.HardwareIntrinsics.X86 {{ for (var i = 1; i < left.Length; i++) {{ - if ({7}) + if ({8}) {{ Succeeded = false; break; @@ -205,7 +304,7 @@ namespace JIT.HardwareIntrinsics.X86 if (!Succeeded) {{ - Console.WriteLine($"{{nameof({0})}}.{{nameof({0}.{1})}}<{2}>: {{method}} failed:"); + Console.WriteLine($"{{nameof({0})}}.{{nameof({0}.{2})}}<{3}>: {{method}} failed:"); Console.WriteLine($" left: ({{string.Join(", ", left)}})"); Console.WriteLine($" right: ({{string.Join(", ", right)}})"); Console.WriteLine($" result: ({{string.Join(", ", result)}})"); diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/SimpleBinOpTest_DataTable_Aligned.cs b/tests/src/JIT/HardwareIntrinsics/X86/Shared/SimpleBinOpTest_DataTable_Aligned.cs new file mode 100644 index 0000000000..f056a8fc7b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/SimpleBinOpTest_DataTable_Aligned.cs @@ -0,0 +1,62 @@ +// 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. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace JIT.HardwareIntrinsics.X86 +{ + public unsafe struct SimpleBinaryOpTest__DataTable<T> : IDisposable where T : struct + { + private byte[] inArray1; + private byte[] inArray2; + private byte[] outArray; + + private GCHandle inHandle1; + private GCHandle inHandle2; + private GCHandle outHandle; + + private byte simdSize; + + public SimpleBinaryOpTest__DataTable(T[] inArray1, T[] inArray2, T[] outArray, int simdSize) + { + this.inArray1 = new byte[simdSize * 2]; + this.inArray2 = new byte[simdSize * 2]; + this.outArray = new byte[simdSize * 2]; + + this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); + this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); + this.outHandle = GCHandle.Alloc(this.outArray, GCHandleType.Pinned); + + this.simdSize = unchecked((byte)(simdSize)); + + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<T, byte>(ref inArray1[0]), this.simdSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<T, byte>(ref inArray2[0]), this.simdSize); + } + + public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), simdSize); + public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), simdSize); + public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), simdSize); + + public void Dispose() + { + inHandle1.Free(); + inHandle2.Free(); + outHandle.Free(); + } + + private static unsafe void* Align(byte* buffer, byte expectedAlignment) + { + // Compute how bad the misalignment is, which is at most (expectedAlignment - 1). + // Then subtract that from the expectedAlignment and add it to the original address + // to compute the aligned address. + + var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment); + return (void*)(buffer + misalignment); + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.Single.cs index 030dc89b8c..c894d11fb1 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Add( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Add( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Add( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Add), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Add), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Add), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Add(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Add(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Add(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Add(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Add(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/AddScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/AddScalar.Single.cs index 325f7503b8..3e594225d6 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/AddScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/AddScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.AddScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.AddScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.AddScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.AddScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.AddScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.AddScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.AddScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.AddScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.AddScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.AddScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.AddScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/And.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/And.Single.cs index 24f3968242..984a441810 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/And.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/And.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.And( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.And( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.And( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.And), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.And), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.And), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.And(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.And(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.And(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.And(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.And(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/AndNot.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/AndNot.Single.cs index 8ebf14948f..a5c8aba655 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/AndNot.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/AndNot.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.AndNot( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.AndNot( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.AndNot( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.AndNot), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.AndNot), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.AndNot), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.AndNot(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.AndNot(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.AndNot(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.AndNot(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.AndNot(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqual.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqual.Single.cs index a5b7934570..96da10ce4e 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqual.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqual.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareEqual( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareEqual( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareEqual( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareEqual(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareEqual(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareEqual(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualOrderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualOrderedScalar.Single.cs index 19e2e024d3..cf99b9694a 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualOrderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualOrderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareEqualOrderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareEqualOrderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareEqualOrderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareEqualOrderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] == right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualScalar.Single.cs index 3a963b3267..b6ecfb7c9a 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareEqualScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareEqualScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareEqualScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareEqualScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareEqualScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareEqualScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualUnorderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualUnorderedScalar.Single.cs index 4e95e71eb5..6145e8869c 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualUnorderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareEqualUnorderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareEqualUnorderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareEqualUnorderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareEqualUnorderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareEqualUnorderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] == right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThan.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThan.Single.cs index 54bc76d030..d351fd4f8e 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThan.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThan.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThan( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThan( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThan( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareGreaterThan(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThan(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThan(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqual.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqual.Single.cs index efe221858a..777796ff89 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqual.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqual.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThanOrEqual( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThanOrEqual( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThanOrEqual( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareGreaterThanOrEqual(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThanOrEqual(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThanOrEqual(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualOrderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualOrderedScalar.Single.cs index 9c8b6e4d30..bf5c87d79d 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualOrderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualOrderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThanOrEqualOrderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThanOrEqualOrderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThanOrEqualOrderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareGreaterThanOrEqualOrderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] >= right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualScalar.Single.cs index 638bd2e7ce..f6179e3065 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThanOrEqualScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThanOrEqualScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThanOrEqualScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareGreaterThanOrEqualScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThanOrEqualScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThanOrEqualScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualUnorderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualUnorderedScalar.Single.cs index c1c4a7f707..536688be34 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualUnorderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrEqualUnorderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThanOrEqualUnorderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThanOrEqualUnorderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThanOrEqualUnorderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareGreaterThanOrEqualUnorderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] >= right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrderedScalar.Single.cs index 51dd48ca74..1dec832ed1 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanOrderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThanOrderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThanOrderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThanOrderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareGreaterThanOrderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] > right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanScalar.Single.cs index 8598471ab6..38d4e2a80d 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThanScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThanScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThanScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareGreaterThanScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThanScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareGreaterThanScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanUnorderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanUnorderedScalar.Single.cs index 9a0d11e449..ffa170253f 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanUnorderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareGreaterThanUnorderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareGreaterThanUnorderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareGreaterThanUnorderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareGreaterThanUnorderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareGreaterThanUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareGreaterThanUnorderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] > right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThan.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThan.Single.cs index 5a13fe2d6d..d5ee27689c 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThan.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThan.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThan( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThan( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThan( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareLessThan(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThan(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThan(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqual.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqual.Single.cs index 11683c9972..a38d9c5217 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqual.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqual.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThanOrEqual( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThanOrEqual( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThanOrEqual( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareLessThanOrEqual(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThanOrEqual(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThanOrEqual(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualOrderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualOrderedScalar.Single.cs index bb22aa7c5f..99a6fcf9bc 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualOrderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualOrderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThanOrEqualOrderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThanOrEqualOrderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThanOrEqualOrderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareLessThanOrEqualOrderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] <= right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualScalar.Single.cs index 89e451ddf0..7fd6641997 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThanOrEqualScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThanOrEqualScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThanOrEqualScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareLessThanOrEqualScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThanOrEqualScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThanOrEqualScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualUnorderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualUnorderedScalar.Single.cs index 35d6708b63..9ee8023738 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualUnorderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrEqualUnorderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThanOrEqualUnorderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThanOrEqualUnorderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThanOrEqualUnorderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareLessThanOrEqualUnorderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] <= right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrderedScalar.Single.cs index 9abafd999b..98a4a78845 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanOrderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThanOrderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThanOrderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThanOrderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareLessThanOrderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] < right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanScalar.Single.cs index 2a347dd934..448d1d6ba2 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThanScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThanScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThanScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareLessThanScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThanScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareLessThanScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanUnorderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanUnorderedScalar.Single.cs index a1d5fefafe..896d1d7fab 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanUnorderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareLessThanUnorderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareLessThanUnorderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareLessThanUnorderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareLessThanUnorderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareLessThanUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareLessThanUnorderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] < right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqual.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqual.Single.cs index b39660afe1..f2e83025d7 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqual.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqual.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotEqual( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotEqual( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotEqual( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotEqual(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotEqual(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotEqual(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualOrderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualOrderedScalar.Single.cs index 4e0f2adf40..75de4bfd44 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualOrderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualOrderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotEqualOrderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotEqualOrderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotEqualOrderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqualOrderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareNotEqualOrderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] != right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualScalar.Single.cs index cd0942efe9..78b4d4b87b 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotEqualScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotEqualScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotEqualScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotEqualScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotEqualScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotEqualScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualUnorderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualUnorderedScalar.Single.cs index 36b04b4c88..fc6cca61b3 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualUnorderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotEqualUnorderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,24 +110,44 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2); + _dataTable = new BooleanComparisonOpTest__DataTable<Single>(_data1, _data2, VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotEqualUnorderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) ); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotEqualUnorderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotEqualUnorderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -117,7 +155,29 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr) }); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotEqualUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); } public void RunClsVarScenario() @@ -130,7 +190,7 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, result); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); @@ -139,6 +199,24 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(left, right, result); } + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotEqualUnorderedScalar(left, right); + + ValidateResult(left, right, result); + } + public void RunLclFldScenario() { var test = new BooleanComparisonOpTest__CompareNotEqualUnorderedScalarSingle(); @@ -160,7 +238,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -179,6 +257,17 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(inArray1, inArray2, result, method); } + private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + + ValidateResult(inArray1, inArray2, result, method); + } + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") { if ((left[0] != right[0]) != result) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThan.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThan.Single.cs index 6d9bd2e086..c2c3797d71 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThan.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThan.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotGreaterThan( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotGreaterThan( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotGreaterThan( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotGreaterThan(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThan(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThan(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqual.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqual.Single.cs index 29891c9621..c23755d607 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqual.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqual.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotGreaterThanOrEqual( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotGreaterThanOrEqual( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotGreaterThanOrEqual( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotGreaterThanOrEqual(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThanOrEqual(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThanOrEqual(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqualScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqualScalar.Single.cs index 33a3687862..dca83ff945 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqualScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanOrEqualScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotGreaterThanOrEqualScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotGreaterThanOrEqualScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotGreaterThanOrEqualScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotGreaterThanOrEqualScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThanOrEqualScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThanOrEqualScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanScalar.Single.cs index f3d06f048d..61b365e0b6 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotGreaterThanScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotGreaterThanScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotGreaterThanScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotGreaterThanScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotGreaterThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotGreaterThanScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotGreaterThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThanScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotGreaterThanScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThan.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThan.Single.cs index af354e4fe7..20d6b01901 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThan.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThan.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotLessThan( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotLessThan( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotLessThan( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThan), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotLessThan(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThan(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThan(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThan(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqual.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqual.Single.cs index cfe4d4d5d4..939bfa9b51 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqual.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqual.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotLessThanOrEqual( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotLessThanOrEqual( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotLessThanOrEqual( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanOrEqual), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotLessThanOrEqual(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThanOrEqual(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThanOrEqual(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThanOrEqual(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqualScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqualScalar.Single.cs index b96ea1573a..f8edf87bb7 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqualScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanOrEqualScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotLessThanOrEqualScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotLessThanOrEqualScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotLessThanOrEqualScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanOrEqualScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotLessThanOrEqualScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThanOrEqualScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThanOrEqualScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThanOrEqualScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanScalar.Single.cs index f308dab021..02fc9885cf 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareNotLessThanScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareNotLessThanScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareNotLessThanScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareNotLessThanScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareNotLessThanScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareNotLessThanScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareNotLessThanScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThanScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareNotLessThanScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrdered.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrdered.Single.cs index 82cd875774..cf7b897746 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrdered.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrdered.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareOrdered( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareOrdered( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareOrdered( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareOrdered), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareOrdered), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareOrdered), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareOrdered(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareOrdered(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareOrdered(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareOrdered(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareOrdered(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrderedScalar.Single.cs index 42e018946a..8e64be1bf5 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareOrderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareOrderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareOrderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareOrderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareOrderedScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareOrderedScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareOrderedScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareOrderedScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareOrderedScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnordered.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnordered.Single.cs index 4348121972..70c0a8c80c 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnordered.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnordered.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareUnordered( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareUnordered( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareUnordered( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareUnordered), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareUnordered), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareUnordered), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareUnordered(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareUnordered(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareUnordered(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareUnordered(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareUnordered(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnorderedScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnorderedScalar.Single.cs index 08d3c91dd6..7466b711c1 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnorderedScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/CompareUnorderedScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.CompareUnorderedScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.CompareUnorderedScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.CompareUnorderedScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.CompareUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.CompareUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.CompareUnorderedScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareUnorderedScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.CompareUnorderedScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareUnorderedScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.CompareUnorderedScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Divide.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Divide.Single.cs index 1e756361c8..ca5d35cc63 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Divide.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Divide.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Divide( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Divide( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Divide( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Divide), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Divide), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Divide), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Divide(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Divide(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Divide(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Divide(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Divide(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/DivideScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/DivideScalar.Single.cs index 1f366ddb7b..001b209d78 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/DivideScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/DivideScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.DivideScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.DivideScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.DivideScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.DivideScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.DivideScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.DivideScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.DivideScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.DivideScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.DivideScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.DivideScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.DivideScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Max.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Max.Single.cs index 5aa37e7527..d8b3641653 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Max.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Max.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Max( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Max( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Max( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Max), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Max), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Max), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Max(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Max(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Max(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Max(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Max(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/MaxScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/MaxScalar.Single.cs index 4edbc9c088..40198d0e63 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/MaxScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/MaxScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.MaxScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.MaxScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.MaxScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.MaxScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.MaxScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.MaxScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.MaxScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.MaxScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.MaxScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.MaxScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.MaxScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Min.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Min.Single.cs index 8a4d6269a9..75413737b0 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Min.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Min.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Min( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Min( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Min( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Min), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Min), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Min), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Min(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Min(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Min(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Min(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Min(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/MinScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/MinScalar.Single.cs index 4f07b11f8e..9efe272ab5 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/MinScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/MinScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.MinScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.MinScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.MinScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.MinScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.MinScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.MinScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.MinScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.MinScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.MinScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.MinScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.MinScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Multiply.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Multiply.Single.cs index 9419c0f898..ba603f8ddd 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Multiply.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Multiply.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Multiply( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Multiply( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Multiply( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Multiply), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Multiply), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Multiply), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Multiply(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Multiply(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Multiply(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Multiply(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Multiply(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/MultiplyScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/MultiplyScalar.Single.cs index 765a464437..cc353e45a0 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/MultiplyScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/MultiplyScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.MultiplyScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.MultiplyScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.MultiplyScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.MultiplyScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.MultiplyScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.MultiplyScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.MultiplyScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.MultiplyScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.MultiplyScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Or.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Or.Single.cs index f70a5ed717..93b8539fdf 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Or.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Or.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Or( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Or( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Or( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Or), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Or), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Or), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Or(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Or(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Or(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Or(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Or(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_r.csproj index ee3966d9b2..2b0e208ecc 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_r.csproj @@ -82,7 +82,7 @@ <Compile Include="Program.Sse.cs" /> <Compile Include="..\Shared\BooleanCmpOpTest_DataTable.cs" /> <Compile Include="..\Shared\Program.cs" /> - <Compile Include="..\Shared\SimpleBinOpTest_DataTable.cs" /> + <Compile Include="..\Shared\SimpleBinOpTest_DataTable_Aligned.cs" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_ro.csproj index 946557677a..15e880b7eb 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sse_ro.csproj @@ -82,7 +82,7 @@ <Compile Include="Program.Sse.cs" /> <Compile Include="..\Shared\BooleanCmpOpTest_DataTable.cs" /> <Compile Include="..\Shared\Program.cs" /> - <Compile Include="..\Shared\SimpleBinOpTest_DataTable.cs" /> + <Compile Include="..\Shared\SimpleBinOpTest_DataTable_Aligned.cs" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Subtract.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Subtract.Single.cs index c6e0f1c7e1..7a2bda1e6a 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Subtract.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Subtract.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Subtract( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Subtract( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Subtract( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Subtract), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Subtract), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Subtract), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Subtract(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Subtract(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Subtract(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Subtract(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Subtract(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/SubtractScalar.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/SubtractScalar.Single.cs index 6f706771ff..e6a475e7a0 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/SubtractScalar.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/SubtractScalar.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.SubtractScalar( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.SubtractScalar( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.SubtractScalar( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.SubtractScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.SubtractScalar(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.SubtractScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.SubtractScalar(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.SubtractScalar(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.SubtractScalar(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Xor.Single.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Xor.Single.cs index 13a5e34be1..6af8bc33c2 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Xor.Single.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Xor.Single.cs @@ -25,17 +25,35 @@ namespace JIT.HardwareIntrinsics.X86 if (test.IsSupported) { - // Validates basic functionality works - test.RunBasicScenario(); + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); - // Validates calling via reflection works - test.RunReflectionScenario(); + // Validates basic functionality works, using Load + test.RunBasicScenario_Load(); + + // Validates basic functionality works, using LoadAligned + test.RunBasicScenario_LoadAligned(); + + // Validates calling via reflection works, using Unsafe.Read + test.RunReflectionScenario_UnsafeRead(); + + // Validates calling via reflection works, using Load + test.RunReflectionScenario_Load(); + + // Validates calling via reflection works, using LoadAligned + test.RunReflectionScenario_LoadAligned(); // Validates passing a static member works test.RunClsVarScenario(); - // Validates passing a local works - test.RunLclVarScenario(); + // Validates passing a local works, using Unsafe.Read + test.RunLclVarScenario_UnsafeRead(); + + // Validates passing a local works, using Load + test.RunLclVarScenario_Load(); + + // Validates passing a local works, using LoadAligned + test.RunLclVarScenario_LoadAligned(); // Validates passing the field of a local works test.RunLclFldScenario(); @@ -92,14 +110,14 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize); for (var i = 0; i < ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); _data2[i] = (float)(random.NextDouble()); } - _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount]); + _dataTable = new SimpleBinaryOpTest__DataTable<Single>(_data1, _data2, new Single[ElementCount], VectorSize); } public bool IsSupported => Sse.IsSupported; public bool Succeeded { get; set; } - public void RunBasicScenario() + public void RunBasicScenario_UnsafeRead() { var result = Sse.Xor( Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr), @@ -107,10 +125,32 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_Load() + { + var result = Sse.Xor( + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunBasicScenario_LoadAligned() + { + var result = Sse.Xor( + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } - public void RunReflectionScenario() + public void RunReflectionScenario_UnsafeRead() { var result = typeof(Sse).GetMethod(nameof(Sse.Xor), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) .Invoke(null, new object[] { @@ -119,7 +159,31 @@ namespace JIT.HardwareIntrinsics.X86 }); Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); - ValidateResult(_dataTable.inArray1, _dataTable.inArray2, _dataTable.outArray); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_Load() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Xor), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); + } + + public void RunReflectionScenario_LoadAligned() + { + var result = typeof(Sse).GetMethod(nameof(Sse.Xor), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) }) + .Invoke(null, new object[] { + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)), + Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)) + }); + + Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Single>)(result)); + ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); } public void RunClsVarScenario() @@ -130,17 +194,37 @@ namespace JIT.HardwareIntrinsics.X86 ); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_clsVar1, _clsVar2, _dataTable.outArray); + ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr); } - public void RunLclVarScenario() + public void RunLclVarScenario_UnsafeRead() { var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr); var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr); var result = Sse.Xor(left, right); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(left, right, _dataTable.outArray); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_Load() + { + var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Xor(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); + } + + public void RunLclVarScenario_LoadAligned() + { + var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)); + var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr)); + var result = Sse.Xor(left, right); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(left, right, _dataTable.outArrayPtr); } public void RunLclFldScenario() @@ -149,7 +233,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Xor(test._fld1, test._fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(test._fld1, test._fld2, _dataTable.outArray); + ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); } public void RunFldScenario() @@ -157,7 +241,7 @@ namespace JIT.HardwareIntrinsics.X86 var result = Sse.Xor(_fld1, _fld2); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(_fld1, _fld2, _dataTable.outArray); + ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); } public void RunUnsupportedScenario() @@ -166,7 +250,7 @@ namespace JIT.HardwareIntrinsics.X86 try { - RunBasicScenario(); + RunBasicScenario_UnsafeRead(); } catch (PlatformNotSupportedException) { @@ -174,15 +258,30 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector128<Single> left, Vector128<Single> right, Single[] result, [CallerMemberName] string method = "") + private void ValidateResult(Vector128<Single> left, Vector128<Single> right, void* result, [CallerMemberName] string method = "") { Single[] inArray1 = new Single[ElementCount]; Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); + + ValidateResult(inArray1, inArray2, outArray, method); + } + + private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[ElementCount]; + Single[] inArray2 = new Single[ElementCount]; + Single[] outArray = new Single[ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize); - ValidateResult(inArray1, inArray2, result, method); + ValidateResult(inArray1, inArray2, outArray, method); } private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "") |