summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanner Gooding <tagoo@outlook.com>2018-03-18 10:06:34 -0700
committerTanner Gooding <tagoo@outlook.com>2018-03-19 11:31:47 -0700
commitcd680d44f44269b4ed77a5a1233ac98caddf294c (patch)
treecc0cc1c53c39a334b8b11ea6ccfc3861cdea2427
parentc691fe9c8a1960a7f9a78fe218763530462452e5 (diff)
downloadcoreclr-cd680d44f44269b4ed77a5a1233ac98caddf294c.tar.gz
coreclr-cd680d44f44269b4ed77a5a1233ac98caddf294c.tar.bz2
coreclr-cd680d44f44269b4ed77a5a1233ac98caddf294c.zip
Fixing the x86 ScalarUnOpTest template to no longer write out of bounds
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx18
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest.template98
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest_DataTable.cs15
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Byte.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Double.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int16.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int32.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int64.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.SByte.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt16.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt32.cs102
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt64.cs102
12 files changed, 279 insertions, 770 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx
index e56264306e..a52a09503c 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx
@@ -164,15 +164,15 @@ private static readonly (string templateFileName, Dictionary<string, string> tem
("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Or", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)(random.Next(0, ushort.MaxValue))", ["NextValueOp2"] = "(ushort)(random.Next(0, ushort.MaxValue))", ["ValidateFirstResult"] = "(ushort)(left[0] | right[0]) != result[0]", ["ValidateRemainingResults"] = "(ushort)(left[i] | right[i]) != result[i]"}),
("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Or", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(uint)(random.Next(0, int.MaxValue))", ["NextValueOp2"] = "(uint)(random.Next(0, int.MaxValue))", ["ValidateFirstResult"] = "(uint)(left[0] | right[0]) != result[0]", ["ValidateRemainingResults"] = "(uint)(left[i] | right[i]) != result[i]"}),
("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "Or", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ulong)(random.Next(0, int.MaxValue))", ["NextValueOp2"] = "(ulong)(random.Next(0, int.MaxValue))", ["ValidateFirstResult"] = "(ulong)(left[0] | right[0]) != result[0]", ["ValidateRemainingResults"] = "(ulong)(left[i] | right[i]) != result[i]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(byte)(random.Next(byte.MinValue, byte.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "SByte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(short)(random.Next(short.MinValue, short.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)(random.Next(ushort.MinValue, ushort.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(int)(random.Next(int.MinValue, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(uint)(random.Next(0, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(long)(random.Next(int.MinValue, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ulong)(random.Next(0, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
- ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "random.NextDouble()", ["ValidateFirstResult"] = "result[0] != firstOp[0]", ["ValidateRemainingResults"] = "result[i] != firstOp[0]"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(byte)(Random.Next(byte.MinValue, byte.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "SByte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(sbyte)(Random.Next(sbyte.MinValue, sbyte.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(short)(Random.Next(short.MinValue, short.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)(Random.Next(ushort.MinValue, ushort.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(int)(Random.Next(int.MinValue, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(uint)(Random.Next(0, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(long)(Random.Next(int.MinValue, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ulong)(Random.Next(0, int.MaxValue))", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
+ ("ScalarUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "SetAllVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "Random.NextDouble()", ["ValidateFirstResult"] = "result[0] != firstOp", ["ValidateRemainingResults"] = "result[i] != firstOp"}),
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShiftLeftLogical", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(short)(random.Next(0, short.MaxValue))", ["ValidateFirstResult"] = "(short)(firstOp[0] << 1) != result[0]", ["ValidateRemainingResults"] = "(short)(firstOp[i] << 1) != result[i]"}),
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShiftLeftLogical", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(ushort)(random.Next(0, ushort.MaxValue))", ["ValidateFirstResult"] = "(ushort)(firstOp[0] << 1) != result[0]", ["ValidateRemainingResults"] = "(ushort)(firstOp[i] << 1) != result[i]"}),
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Sse2", ["LoadIsa"] = "Sse2", ["Method"] = "ShiftLeftLogical", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Int32", ["Imm"] = "1", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "(int)(random.Next(0, int.MaxValue))", ["ValidateFirstResult"] = "(int)(firstOp[0] << 1) != result[0]", ["ValidateRemainingResults"] = "(int)(firstOp[i] << 1) != result[i]"}),
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest.template b/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest.template
index 51fdcadeb1..69e1d7342e 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest.template
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest.template
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void {Method}{RetBaseType}()
{
- bool skipIf32Bit = typeof({Op1BaseType}) == typeof(Int64) ? true :
- typeof({Op1BaseType}) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof({Op1BaseType}) == typeof(Int64)) ||
+ (typeof({Op1BaseType}) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if ({LoadIsa}.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = {LargestVectorSize};
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType});
- private static {Op1BaseType}[] _data = new {Op1BaseType}[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static {Op1BaseType} _clsVar;
private {Op1BaseType} _fld;
- private SimpleScalarUnaryOpTest__DataTable<{RetBaseType}, {Op1BaseType}> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<{RetBaseType}> _dataTable;
static SimpleScalarUnaryOpTest__{Method}{RetBaseType}()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = {NextValueOp1};
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref _clsVar), ref Unsafe.As<{Op1BaseType}, byte>(ref _data[0]), (uint)Marshal.SizeOf<{Op1BaseType}>());
+ _clsVar = {NextValueOp1};
}
public SimpleScalarUnaryOpTest__{Method}{RetBaseType}()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = {NextValueOp1};
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref _fld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data[0]), (uint)Marshal.SizeOf<{Op1BaseType}>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = {NextValueOp1};
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<{RetBaseType}, {Op1BaseType}>(_data, new {RetBaseType}[RetElementCount], LargestVectorSize);
+ _fld = {NextValueOp1};
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<{RetBaseType}>(new {RetBaseType}[RetElementCount], LargestVectorSize);
}
public bool IsSupported => {Isa}.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = {NextValueOp1};
var result = {Isa}.{Method}(
- Unsafe.Read<{Op1BaseType}>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1BaseType}) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<{Op1BaseType}>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = {NextValueOp1};
var method = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1BaseType}) });
- {Op1BaseType} parameter = ({Op1BaseType}) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<{Op1BaseType}>(_dataTable.inArrayPtr);
+ var firstOp = {NextValueOp1};
var result = {Isa}.{Method}(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,27 +168,14 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult({Op1BaseType} firstOp, void* result, [CallerMemberName] string method = "")
{
- {Op1BaseType}[] inArray = new {Op1BaseType}[Op1ElementCount];
- {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- {Op1BaseType}[] inArray = new {Op1BaseType}[Op1ElementCount];
{RetBaseType}[] outArray = new {RetBaseType}[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult({Op1BaseType}[] firstOp, {RetBaseType}[] result, [CallerMemberName] string method = "")
+ private void ValidateResult({Op1BaseType} firstOp, {RetBaseType}[] result, [CallerMemberName] string method = "")
{
if ({ValidateFirstResult})
{
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest_DataTable.cs b/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest_DataTable.cs
index 55795e4bc5..b510aed999 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest_DataTable.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/ScalarUnOpTest_DataTable.cs
@@ -11,39 +11,28 @@ using System.Runtime.Intrinsics.X86;
namespace JIT.HardwareIntrinsics.X86
{
- public unsafe struct SimpleScalarUnaryOpTest__DataTable<TResult, TOp1> : IDisposable
+ public unsafe struct SimpleScalarUnaryOpTest__DataTable<TResult> : IDisposable
where TResult : struct
- where TOp1 : struct
{
- private static byte inArrayElementSize;
- public byte[] inArray;
public byte[] outArray;
- private GCHandle inHandle;
private GCHandle outHandle;
private byte simdSize;
- public SimpleScalarUnaryOpTest__DataTable(TOp1[] inArray, TResult[] outArray, int simdSize)
+ public SimpleScalarUnaryOpTest__DataTable(TResult[] outArray, int simdSize)
{
- inArrayElementSize = (byte) Marshal.SizeOf<TOp1>();
- this.inArray = new byte[inArrayElementSize * 2];
this.outArray = new byte[simdSize * 2];
- this.inHandle = GCHandle.Alloc(this.inArray, GCHandleType.Pinned);
this.outHandle = GCHandle.Alloc(this.outArray, GCHandleType.Pinned);
this.simdSize = unchecked((byte)(simdSize));
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArrayPtr), ref Unsafe.As<TOp1, byte>(ref inArray[0]), (uint)(2 * inArrayElementSize));
}
- public void* inArrayPtr => inHandle.AddrOfPinnedObject().ToPointer();
public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), simdSize);
public void Dispose()
{
- inHandle.Free();
outHandle.Free();
}
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Byte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Byte.cs
index f15bb93361..010cd2629a 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Byte.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Byte.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128Byte()
{
- bool skipIf32Bit = typeof(Byte) == typeof(Int64) ? true :
- typeof(Byte) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(Byte) == typeof(Int64)) ||
+ (typeof(Byte) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte);
- private static Byte[] _data = new Byte[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static Byte _clsVar;
private Byte _fld;
- private SimpleScalarUnaryOpTest__DataTable<Byte, Byte> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<Byte> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128Byte()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (byte)(random.Next(byte.MinValue, byte.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref _clsVar), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Marshal.SizeOf<Byte>());
+ _clsVar = (byte)(Random.Next(byte.MinValue, byte.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128Byte()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (byte)(random.Next(byte.MinValue, byte.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref _fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Marshal.SizeOf<Byte>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (byte)(random.Next(byte.MinValue, byte.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<Byte, Byte>(_data, new Byte[RetElementCount], LargestVectorSize);
+ _fld = (byte)(Random.Next(byte.MinValue, byte.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<Byte>(new Byte[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (byte)(Random.Next(byte.MinValue, byte.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<Byte>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Byte) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<Byte>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (byte)(Random.Next(byte.MinValue, byte.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Byte) });
- Byte parameter = (Byte) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Byte>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<Byte>(_dataTable.inArrayPtr);
+ var firstOp = (byte)(Random.Next(byte.MinValue, byte.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(Byte firstOp, void* result, [CallerMemberName] string method = "")
{
- Byte[] inArray = new Byte[Op1ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray = new Byte[Op1ElementCount];
Byte[] outArray = new Byte[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Byte>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(Byte[] firstOp, Byte[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(Byte firstOp, Byte[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Double.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Double.cs
index 6637fcadcb..190d30661c 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Double.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Double.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128Double()
{
- bool skipIf32Bit = typeof(Double) == typeof(Int64) ? true :
- typeof(Double) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(Double) == typeof(Int64)) ||
+ (typeof(Double) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double);
- private static Double[] _data = new Double[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static Double _clsVar;
private Double _fld;
- private SimpleScalarUnaryOpTest__DataTable<Double, Double> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<Double> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128Double()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = random.NextDouble();
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref _clsVar), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Marshal.SizeOf<Double>());
+ _clsVar = Random.NextDouble();
}
public SimpleScalarUnaryOpTest__SetAllVector128Double()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = random.NextDouble();
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref _fld), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Marshal.SizeOf<Double>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = random.NextDouble();
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<Double, Double>(_data, new Double[RetElementCount], LargestVectorSize);
+ _fld = Random.NextDouble();
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<Double>(new Double[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = Random.NextDouble();
var result = Sse2.SetAllVector128(
- Unsafe.Read<Double>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Double) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<Double>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = Random.NextDouble();
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Double) });
- Double parameter = (Double) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Double>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<Double>(_dataTable.inArrayPtr);
+ var firstOp = Random.NextDouble();
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(Double firstOp, void* result, [CallerMemberName] string method = "")
{
- Double[] inArray = new Double[Op1ElementCount];
- Double[] outArray = new Double[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Double[] inArray = new Double[Op1ElementCount];
Double[] outArray = new Double[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Double>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(Double[] firstOp, Double[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(Double firstOp, Double[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int16.cs
index 8e84495663..43d9a83388 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int16.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int16.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128Int16()
{
- bool skipIf32Bit = typeof(Int16) == typeof(Int64) ? true :
- typeof(Int16) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(Int16) == typeof(Int64)) ||
+ (typeof(Int16) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16);
- private static Int16[] _data = new Int16[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static Int16 _clsVar;
private Int16 _fld;
- private SimpleScalarUnaryOpTest__DataTable<Int16, Int16> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<Int16> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128Int16()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (short)(random.Next(short.MinValue, short.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref _clsVar), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Marshal.SizeOf<Int16>());
+ _clsVar = (short)(Random.Next(short.MinValue, short.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128Int16()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (short)(random.Next(short.MinValue, short.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref _fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Marshal.SizeOf<Int16>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (short)(random.Next(short.MinValue, short.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<Int16, Int16>(_data, new Int16[RetElementCount], LargestVectorSize);
+ _fld = (short)(Random.Next(short.MinValue, short.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<Int16>(new Int16[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (short)(Random.Next(short.MinValue, short.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<Int16>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Int16) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<Int16>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (short)(Random.Next(short.MinValue, short.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Int16) });
- Int16 parameter = (Int16) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int16>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<Int16>(_dataTable.inArrayPtr);
+ var firstOp = (short)(Random.Next(short.MinValue, short.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(Int16 firstOp, void* result, [CallerMemberName] string method = "")
{
- Int16[] inArray = new Int16[Op1ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray = new Int16[Op1ElementCount];
Int16[] outArray = new Int16[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int16>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(Int16 firstOp, Int16[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int32.cs
index 92ee749a71..9ebad56657 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int32.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int32.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128Int32()
{
- bool skipIf32Bit = typeof(Int32) == typeof(Int64) ? true :
- typeof(Int32) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(Int32) == typeof(Int64)) ||
+ (typeof(Int32) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32);
- private static Int32[] _data = new Int32[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static Int32 _clsVar;
private Int32 _fld;
- private SimpleScalarUnaryOpTest__DataTable<Int32, Int32> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<Int32> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128Int32()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (int)(random.Next(int.MinValue, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref _clsVar), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Marshal.SizeOf<Int32>());
+ _clsVar = (int)(Random.Next(int.MinValue, int.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128Int32()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (int)(random.Next(int.MinValue, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref _fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Marshal.SizeOf<Int32>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (int)(random.Next(int.MinValue, int.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<Int32, Int32>(_data, new Int32[RetElementCount], LargestVectorSize);
+ _fld = (int)(Random.Next(int.MinValue, int.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<Int32>(new Int32[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (int)(Random.Next(int.MinValue, int.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<Int32>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Int32) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<Int32>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (int)(Random.Next(int.MinValue, int.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Int32) });
- Int32 parameter = (Int32) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int32>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<Int32>(_dataTable.inArrayPtr);
+ var firstOp = (int)(Random.Next(int.MinValue, int.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(Int32 firstOp, void* result, [CallerMemberName] string method = "")
{
- Int32[] inArray = new Int32[Op1ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray = new Int32[Op1ElementCount];
Int32[] outArray = new Int32[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int32>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(Int32[] firstOp, Int32[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(Int32 firstOp, Int32[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int64.cs
index e476cada0e..c97deb51c0 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int64.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.Int64.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128Int64()
{
- bool skipIf32Bit = typeof(Int64) == typeof(Int64) ? true :
- typeof(Int64) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(Int64) == typeof(Int64)) ||
+ (typeof(Int64) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int64>>() / sizeof(Int64);
- private static Int64[] _data = new Int64[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static Int64 _clsVar;
private Int64 _fld;
- private SimpleScalarUnaryOpTest__DataTable<Int64, Int64> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<Int64> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128Int64()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (long)(random.Next(int.MinValue, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref _clsVar), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Marshal.SizeOf<Int64>());
+ _clsVar = (long)(Random.Next(int.MinValue, int.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128Int64()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (long)(random.Next(int.MinValue, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref _fld), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Marshal.SizeOf<Int64>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (long)(random.Next(int.MinValue, int.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<Int64, Int64>(_data, new Int64[RetElementCount], LargestVectorSize);
+ _fld = (long)(Random.Next(int.MinValue, int.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<Int64>(new Int64[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (long)(Random.Next(int.MinValue, int.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<Int64>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Int64) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<Int64>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (long)(Random.Next(int.MinValue, int.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(Int64) });
- Int64 parameter = (Int64) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<Int64>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<Int64>(_dataTable.inArrayPtr);
+ var firstOp = (long)(Random.Next(int.MinValue, int.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(Int64 firstOp, void* result, [CallerMemberName] string method = "")
{
- Int64[] inArray = new Int64[Op1ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray = new Int64[Op1ElementCount];
Int64[] outArray = new Int64[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<Int64>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(Int64[] firstOp, Int64[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(Int64 firstOp, Int64[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.SByte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.SByte.cs
index 56d17d0141..355d90bd96 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.SByte.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.SByte.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128SByte()
{
- bool skipIf32Bit = typeof(SByte) == typeof(Int64) ? true :
- typeof(SByte) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(SByte) == typeof(Int64)) ||
+ (typeof(SByte) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte);
- private static SByte[] _data = new SByte[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static SByte _clsVar;
private SByte _fld;
- private SimpleScalarUnaryOpTest__DataTable<SByte, SByte> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<SByte> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128SByte()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref _clsVar), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Marshal.SizeOf<SByte>());
+ _clsVar = (sbyte)(Random.Next(sbyte.MinValue, sbyte.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128SByte()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref _fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Marshal.SizeOf<SByte>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (sbyte)(random.Next(sbyte.MinValue, sbyte.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<SByte, SByte>(_data, new SByte[RetElementCount], LargestVectorSize);
+ _fld = (sbyte)(Random.Next(sbyte.MinValue, sbyte.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<SByte>(new SByte[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (sbyte)(Random.Next(sbyte.MinValue, sbyte.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<SByte>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(SByte) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<SByte>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (sbyte)(Random.Next(sbyte.MinValue, sbyte.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(SByte) });
- SByte parameter = (SByte) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<SByte>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<SByte>(_dataTable.inArrayPtr);
+ var firstOp = (sbyte)(Random.Next(sbyte.MinValue, sbyte.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(SByte firstOp, void* result, [CallerMemberName] string method = "")
{
- SByte[] inArray = new SByte[Op1ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray = new SByte[Op1ElementCount];
SByte[] outArray = new SByte[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<SByte>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(SByte[] firstOp, SByte[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(SByte firstOp, SByte[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt16.cs
index c78aa95716..b11e3362de 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt16.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt16.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128UInt16()
{
- bool skipIf32Bit = typeof(UInt16) == typeof(Int64) ? true :
- typeof(UInt16) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(UInt16) == typeof(Int64)) ||
+ (typeof(UInt16) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16);
- private static UInt16[] _data = new UInt16[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static UInt16 _clsVar;
private UInt16 _fld;
- private SimpleScalarUnaryOpTest__DataTable<UInt16, UInt16> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<UInt16> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128UInt16()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (ushort)(random.Next(ushort.MinValue, ushort.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref _clsVar), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Marshal.SizeOf<UInt16>());
+ _clsVar = (ushort)(Random.Next(ushort.MinValue, ushort.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128UInt16()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (ushort)(random.Next(ushort.MinValue, ushort.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref _fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Marshal.SizeOf<UInt16>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (ushort)(random.Next(ushort.MinValue, ushort.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<UInt16, UInt16>(_data, new UInt16[RetElementCount], LargestVectorSize);
+ _fld = (ushort)(Random.Next(ushort.MinValue, ushort.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<UInt16>(new UInt16[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (ushort)(Random.Next(ushort.MinValue, ushort.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<UInt16>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(UInt16) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<UInt16>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (ushort)(Random.Next(ushort.MinValue, ushort.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(UInt16) });
- UInt16 parameter = (UInt16) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt16>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<UInt16>(_dataTable.inArrayPtr);
+ var firstOp = (ushort)(Random.Next(ushort.MinValue, ushort.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(UInt16 firstOp, void* result, [CallerMemberName] string method = "")
{
- UInt16[] inArray = new UInt16[Op1ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray = new UInt16[Op1ElementCount];
UInt16[] outArray = new UInt16[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(UInt16 firstOp, UInt16[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt32.cs
index ce75515c71..548cf6e4a1 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt32.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt32.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128UInt32()
{
- bool skipIf32Bit = typeof(UInt32) == typeof(Int64) ? true :
- typeof(UInt32) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(UInt32) == typeof(Int64)) ||
+ (typeof(UInt32) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32);
- private static UInt32[] _data = new UInt32[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static UInt32 _clsVar;
private UInt32 _fld;
- private SimpleScalarUnaryOpTest__DataTable<UInt32, UInt32> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<UInt32> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128UInt32()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (uint)(random.Next(0, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref _clsVar), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Marshal.SizeOf<UInt32>());
+ _clsVar = (uint)(Random.Next(0, int.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128UInt32()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (uint)(random.Next(0, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref _fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Marshal.SizeOf<UInt32>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (uint)(random.Next(0, int.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<UInt32, UInt32>(_data, new UInt32[RetElementCount], LargestVectorSize);
+ _fld = (uint)(Random.Next(0, int.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<UInt32>(new UInt32[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (uint)(Random.Next(0, int.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<UInt32>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(UInt32) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<UInt32>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (uint)(Random.Next(0, int.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(UInt32) });
- UInt32 parameter = (UInt32) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt32>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<UInt32>(_dataTable.inArrayPtr);
+ var firstOp = (uint)(Random.Next(0, int.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(UInt32 firstOp, void* result, [CallerMemberName] string method = "")
{
- UInt32[] inArray = new UInt32[Op1ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray = new UInt32[Op1ElementCount];
UInt32[] outArray = new UInt32[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(UInt32[] firstOp, UInt32[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(UInt32 firstOp, UInt32[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt64.cs
index fb6ec17c6b..3881ae6726 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt64.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/SetAllVector128.UInt64.cs
@@ -21,8 +21,8 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void SetAllVector128UInt64()
{
- bool skipIf32Bit = typeof(UInt64) == typeof(Int64) ? true :
- typeof(UInt64) == typeof(UInt64) ? true : false;
+ bool skipIf32Bit = (typeof(UInt64) == typeof(Int64)) ||
+ (typeof(UInt64) == typeof(UInt64));
if (skipIf32Bit && !Environment.Is64BitProcess)
{
@@ -33,23 +33,17 @@ namespace JIT.HardwareIntrinsics.X86
if (test.IsSupported)
{
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
+ // Validates basic functionality works
+ test.RunBasicScenario();
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Sse2.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario();
- }
+ // Validates calling via reflection works
+ test.RunReflectionScenario();
// Validates passing a static member works
test.RunClsVarScenario();
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
+ // Validates passing a local works
+ test.RunLclVarScenario();
// Validates passing the field of a local works
test.RunLclFldScenario();
@@ -74,81 +68,52 @@ namespace JIT.HardwareIntrinsics.X86
{
private static readonly int LargestVectorSize = 16;
- private static readonly int Op1ElementCount = 2;
private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt64>>() / sizeof(UInt64);
- private static UInt64[] _data = new UInt64[Op1ElementCount];
+ private static readonly Random Random = new Random();
private static UInt64 _clsVar;
private UInt64 _fld;
- private SimpleScalarUnaryOpTest__DataTable<UInt64, UInt64> _dataTable;
+ private SimpleScalarUnaryOpTest__DataTable<UInt64> _dataTable;
static SimpleScalarUnaryOpTest__SetAllVector128UInt64()
{
- var random = new Random();
-
- for (int i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (ulong)(random.Next(0, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref _clsVar), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Marshal.SizeOf<UInt64>());
+ _clsVar = (ulong)(Random.Next(0, int.MaxValue));
}
public SimpleScalarUnaryOpTest__SetAllVector128UInt64()
{
Succeeded = true;
- var random = new Random();
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (ulong)(random.Next(0, int.MaxValue));
- }
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref _fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Marshal.SizeOf<UInt64>());
-
- for (var i = 0; i < Op1ElementCount; i++)
- {
- _data[i] = (ulong)(random.Next(0, int.MaxValue));
- }
-
- _dataTable = new SimpleScalarUnaryOpTest__DataTable<UInt64, UInt64>(_data, new UInt64[RetElementCount], LargestVectorSize);
+ _fld = (ulong)(Random.Next(0, int.MaxValue));
+ _dataTable = new SimpleScalarUnaryOpTest__DataTable<UInt64>(new UInt64[RetElementCount], LargestVectorSize);
}
public bool IsSupported => Sse2.IsSupported;
public bool Succeeded { get; set; }
- public void RunBasicScenario_UnsafeRead()
+ public void RunBasicScenario()
{
+ var firstOp = (ulong)(Random.Next(0, int.MaxValue));
var result = Sse2.SetAllVector128(
- Unsafe.Read<UInt64>(_dataTable.inArrayPtr)
+ firstOp
);
Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(UInt64) });
- var result = method.Invoke(null, new object[] { Unsafe.Read<UInt64>(_dataTable.inArrayPtr)});
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result));
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunReflectionScenario()
{
+ var firstOp = (ulong)(Random.Next(0, int.MaxValue));
var method = typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), new Type[] { typeof(UInt64) });
- UInt64 parameter = (UInt64) _dataTable.inArray[0];
- var result = method.Invoke(null, new object[] { parameter });
+ var result = method.Invoke(null, new object[] { firstOp });
Unsafe.Write(_dataTable.outArrayPtr, (Vector128<UInt64>)(result));
- ValidateResult(parameter, _dataTable.outArrayPtr);
+ ValidateResult(firstOp, _dataTable.outArrayPtr);
}
public void RunClsVarScenario()
@@ -161,9 +126,9 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar, _dataTable.outArrayPtr);
}
- public void RunLclVarScenario_UnsafeRead()
+ public void RunLclVarScenario()
{
- var firstOp = Unsafe.Read<UInt64>(_dataTable.inArrayPtr);
+ var firstOp = (ulong)(Random.Next(0, int.MaxValue));
var result = Sse2.SetAllVector128(firstOp);
Unsafe.Write(_dataTable.outArrayPtr, result);
@@ -193,7 +158,7 @@ namespace JIT.HardwareIntrinsics.X86
try
{
- RunBasicScenario_UnsafeRead();
+ RunBasicScenario();
}
catch (PlatformNotSupportedException)
{
@@ -203,29 +168,16 @@ namespace JIT.HardwareIntrinsics.X86
private void ValidateResult(UInt64 firstOp, void* result, [CallerMemberName] string method = "")
{
- UInt64[] inArray = new UInt64[Op1ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray = new UInt64[Op1ElementCount];
UInt64[] outArray = new UInt64[RetElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
- ValidateResult(inArray, outArray, method);
+ ValidateResult(firstOp, outArray, method);
}
- private void ValidateResult(UInt64[] firstOp, UInt64[] result, [CallerMemberName] string method = "")
+ private void ValidateResult(UInt64 firstOp, UInt64[] result, [CallerMemberName] string method = "")
{
- if (result[0] != firstOp[0])
+ if (result[0] != firstOp)
{
Succeeded = false;
}
@@ -233,7 +185,7 @@ namespace JIT.HardwareIntrinsics.X86
{
for (var i = 1; i < RetElementCount; i++)
{
- if (result[i] != firstOp[0])
+ if (result[i] != firstOp)
{
Succeeded = false;
break;