From 7fa9581750aca0d959c334a9767e306251611d82 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 3 Jun 2019 12:15:32 -0700 Subject: Removing the TestAllOnes, TestAllZeros, and TestMixOnesZeros methods from the Sse41 class (#24886) * Removing the TestAllOnes, TestAllZeros, and TestMixOnesZeros methods from the Sse41 class * Removing JIT support for the SSE41_TestAllOnes, SSE41_TestAllZeros, and SSE41_TestMixOnesZeros intrinsics * Removing tests for the Sse41.TestAllOnes, Sse41.TestAllZeros, and Sse41.TestMixOnesZeros methods --- .../X86/Shared/GenerateTests.csx | 24 - .../HardwareIntrinsics/X86/Sse41/Program.Sse41.cs | 24 - .../HardwareIntrinsics/X86/Sse41/Sse41_r.csproj | 24 - .../HardwareIntrinsics/X86/Sse41/Sse41_ro.csproj | 24 - .../X86/Sse41/TestAllOnes.Byte.cs | 501 ------------------- .../X86/Sse41/TestAllOnes.Int16.cs | 501 ------------------- .../X86/Sse41/TestAllOnes.Int32.cs | 501 ------------------- .../X86/Sse41/TestAllOnes.Int64.cs | 501 ------------------- .../X86/Sse41/TestAllOnes.SByte.cs | 501 ------------------- .../X86/Sse41/TestAllOnes.UInt16.cs | 501 ------------------- .../X86/Sse41/TestAllOnes.UInt32.cs | 501 ------------------- .../X86/Sse41/TestAllOnes.UInt64.cs | 501 ------------------- .../X86/Sse41/TestAllZeros.Byte.cs | 545 -------------------- .../X86/Sse41/TestAllZeros.Int16.cs | 545 -------------------- .../X86/Sse41/TestAllZeros.Int32.cs | 545 -------------------- .../X86/Sse41/TestAllZeros.Int64.cs | 545 -------------------- .../X86/Sse41/TestAllZeros.SByte.cs | 545 -------------------- .../X86/Sse41/TestAllZeros.UInt16.cs | 545 -------------------- .../X86/Sse41/TestAllZeros.UInt32.cs | 545 -------------------- .../X86/Sse41/TestAllZeros.UInt64.cs | 545 -------------------- .../X86/Sse41/TestMixOnesZeros.Byte.cs | 552 --------------------- .../X86/Sse41/TestMixOnesZeros.Int16.cs | 552 --------------------- .../X86/Sse41/TestMixOnesZeros.Int32.cs | 552 --------------------- .../X86/Sse41/TestMixOnesZeros.Int64.cs | 552 --------------------- .../X86/Sse41/TestMixOnesZeros.SByte.cs | 552 --------------------- .../X86/Sse41/TestMixOnesZeros.UInt16.cs | 552 --------------------- .../X86/Sse41/TestMixOnesZeros.UInt32.cs | 552 --------------------- .../X86/Sse41/TestMixOnesZeros.UInt64.cs | 552 --------------------- 28 files changed, 12880 deletions(-) delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Byte.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int16.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int32.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int64.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.SByte.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt16.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt32.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt64.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Byte.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int16.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int32.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int64.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.SByte.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt16.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt32.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt64.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Byte.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int16.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int32.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int64.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.SByte.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt16.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt32.cs delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt64.cs (limited to 'tests/src') diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx index 7cbf8b7551..853681c651 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx +++ b/tests/src/JIT/HardwareIntrinsics/X86/Shared/GenerateTests.csx @@ -572,22 +572,6 @@ private static readonly (string templateFileName, Dictionary tem ("SimpleUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "RoundToZero", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits((firstOp[0] > 0) ? MathF.Floor(firstOp[0]) : MathF.Ceiling(firstOp[0]))", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits((firstOp[i] > 0) ? MathF.Floor(firstOp[i]) : MathF.Ceiling(firstOp[i]))"}), ("SimpleBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "RoundToZeroScalar", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits((right[0] > 0) ? Math.Floor(right[0]) : Math.Ceiling(right[0]))", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(left[i])"}), ("SimpleBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse", ["Method"] = "RoundToZeroScalar", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits((right[0] > 0) ? MathF.Floor(right[0]) : MathF.Ceiling(right[0]))", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(~value[i] & byte.MaxValue) == 0"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "(~value[i] & -1) == 0"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "(~value[i] & -1) == 0"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "(~value[i] & -1) == 0"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "SByte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "(~value[i] & -1) == 0"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "(~value[i] & ushort.MaxValue) == 0"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "(~value[i] & uint.MaxValue) == 0"}), - ("BooleanUnOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllOnes", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(~value[i] & ulong.MaxValue) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "SByte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "SByte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), - ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestAllZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(left[i] & right[i]) == 0"}), ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "(~left[i] & right[i]) == 0"}), ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "(~left[i] & right[i]) == 0"}), ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "(~left[i] & right[i]) == 0"}), @@ -596,14 +580,6 @@ private static readonly (string templateFileName, Dictionary tem ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "(~left[i] & right[i]) == 0"}), ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "(~left[i] & right[i]) == 0"}), ("BooleanBinOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "(~left[i] & right[i]) == 0"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "SByte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "SByte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), - ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestMixOnesZeros", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestNotZAndNotC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestNotZAndNotC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), ("BooleanTwoCmpOpTest.template", new Dictionary { ["Isa"] = "Sse41", ["LoadIsa"] = "Sse2", ["Method"] = "TestNotZAndNotC", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] ="Vector128", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int32", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "((left[i] & right[i]) == 0)", ["ValidateRemainingResults"] = "((~left[i] & right[i]) == 0)"}), diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Program.Sse41.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Program.Sse41.cs index f60ab4e0c8..64cfe1e14c 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Program.Sse41.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Program.Sse41.cs @@ -91,22 +91,6 @@ namespace JIT.HardwareIntrinsics.X86 ["RoundToZero.Single"] = RoundToZeroSingle, ["RoundToZeroScalar.Double"] = RoundToZeroScalarDouble, ["RoundToZeroScalar.Single"] = RoundToZeroScalarSingle, - ["TestAllOnes.Byte"] = TestAllOnesByte, - ["TestAllOnes.Int16"] = TestAllOnesInt16, - ["TestAllOnes.Int32"] = TestAllOnesInt32, - ["TestAllOnes.Int64"] = TestAllOnesInt64, - ["TestAllOnes.SByte"] = TestAllOnesSByte, - ["TestAllOnes.UInt16"] = TestAllOnesUInt16, - ["TestAllOnes.UInt32"] = TestAllOnesUInt32, - ["TestAllOnes.UInt64"] = TestAllOnesUInt64, - ["TestAllZeros.Byte"] = TestAllZerosByte, - ["TestAllZeros.Int16"] = TestAllZerosInt16, - ["TestAllZeros.Int32"] = TestAllZerosInt32, - ["TestAllZeros.Int64"] = TestAllZerosInt64, - ["TestAllZeros.SByte"] = TestAllZerosSByte, - ["TestAllZeros.UInt16"] = TestAllZerosUInt16, - ["TestAllZeros.UInt32"] = TestAllZerosUInt32, - ["TestAllZeros.UInt64"] = TestAllZerosUInt64, ["TestC.Byte"] = TestCByte, ["TestC.Int16"] = TestCInt16, ["TestC.Int32"] = TestCInt32, @@ -115,14 +99,6 @@ namespace JIT.HardwareIntrinsics.X86 ["TestC.UInt16"] = TestCUInt16, ["TestC.UInt32"] = TestCUInt32, ["TestC.UInt64"] = TestCUInt64, - ["TestMixOnesZeros.Byte"] = TestMixOnesZerosByte, - ["TestMixOnesZeros.Int16"] = TestMixOnesZerosInt16, - ["TestMixOnesZeros.Int32"] = TestMixOnesZerosInt32, - ["TestMixOnesZeros.Int64"] = TestMixOnesZerosInt64, - ["TestMixOnesZeros.SByte"] = TestMixOnesZerosSByte, - ["TestMixOnesZeros.UInt16"] = TestMixOnesZerosUInt16, - ["TestMixOnesZeros.UInt32"] = TestMixOnesZerosUInt32, - ["TestMixOnesZeros.UInt64"] = TestMixOnesZerosUInt64, ["TestNotZAndNotC.Byte"] = TestNotZAndNotCByte, ["TestNotZAndNotC.Int16"] = TestNotZAndNotCInt16, ["TestNotZAndNotC.Int32"] = TestNotZAndNotCInt32, diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_r.csproj index 714705da10..50cad6efe5 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_r.csproj @@ -80,22 +80,6 @@ - - - - - - - - - - - - - - - - @@ -104,14 +88,6 @@ - - - - - - - - diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_ro.csproj index 67552f99db..9445151a70 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/Sse41_ro.csproj @@ -78,22 +78,6 @@ - - - - - - - - - - - - - - - - @@ -102,14 +86,6 @@ - - - - - - - - diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Byte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Byte.cs deleted file mode 100644 index 971052bcb4..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Byte.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesByte() - { - var test = new BooleanUnaryOpTest__TestAllOnesByte(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesByte - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(Byte[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesByte testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesByte testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Byte*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Byte); - - private static Byte[] _data1 = new Byte[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesByte() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesByte() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Byte*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesByte(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesByte(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Byte*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Byte*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Byte*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - Byte[] inArray1 = new Byte[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - Byte[] inArray1 = new Byte[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(Byte[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & byte.MaxValue) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int16.cs deleted file mode 100644 index dcb8dd6379..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int16.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesInt16() - { - var test = new BooleanUnaryOpTest__TestAllOnesInt16(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesInt16 - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(Int16[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesInt16 testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesInt16 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int16*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int16); - - private static Int16[] _data1 = new Int16[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesInt16() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesInt16() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int16*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesInt16(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesInt16(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int16*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int16*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int16*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - Int16[] inArray1 = new Int16[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - Int16[] inArray1 = new Int16[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(Int16[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & -1) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int32.cs deleted file mode 100644 index 18b2a9f3f9..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int32.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesInt32() - { - var test = new BooleanUnaryOpTest__TestAllOnesInt32(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesInt32 - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(Int32[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesInt32 testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesInt32 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int32*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int32); - - private static Int32[] _data1 = new Int32[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesInt32() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesInt32() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int32*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesInt32(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesInt32(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int32*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int32*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int32*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - Int32[] inArray1 = new Int32[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - Int32[] inArray1 = new Int32[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(Int32[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & -1) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int64.cs deleted file mode 100644 index 8165661caf..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.Int64.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesInt64() - { - var test = new BooleanUnaryOpTest__TestAllOnesInt64(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesInt64 - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(Int64[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesInt64 testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesInt64 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int64*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int64); - - private static Int64[] _data1 = new Int64[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesInt64() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesInt64() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int64*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesInt64(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesInt64(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int64*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int64*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((Int64*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - Int64[] inArray1 = new Int64[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - Int64[] inArray1 = new Int64[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(Int64[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & -1) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.SByte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.SByte.cs deleted file mode 100644 index a0c103d9c8..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.SByte.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesSByte() - { - var test = new BooleanUnaryOpTest__TestAllOnesSByte(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesSByte - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(SByte[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesSByte testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesSByte testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((SByte*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(SByte); - - private static SByte[] _data1 = new SByte[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesSByte() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesSByte() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((SByte*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesSByte(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesSByte(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((SByte*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((SByte*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((SByte*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - SByte[] inArray1 = new SByte[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - SByte[] inArray1 = new SByte[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(SByte[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & -1) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt16.cs deleted file mode 100644 index a845f0695d..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt16.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesUInt16() - { - var test = new BooleanUnaryOpTest__TestAllOnesUInt16(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesUInt16 - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(UInt16[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesUInt16 testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesUInt16 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt16*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt16); - - private static UInt16[] _data1 = new UInt16[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesUInt16() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesUInt16() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt16*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesUInt16(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesUInt16(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt16*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt16*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt16*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - UInt16[] inArray1 = new UInt16[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - UInt16[] inArray1 = new UInt16[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(UInt16[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & ushort.MaxValue) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt32.cs deleted file mode 100644 index 5b9ff68578..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt32.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesUInt32() - { - var test = new BooleanUnaryOpTest__TestAllOnesUInt32(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesUInt32 - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(UInt32[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesUInt32 testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesUInt32 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt32*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt32); - - private static UInt32[] _data1 = new UInt32[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesUInt32() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesUInt32() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt32*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesUInt32(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesUInt32(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt32*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt32*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt32*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - UInt32[] inArray1 = new UInt32[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - UInt32[] inArray1 = new UInt32[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(UInt32[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & uint.MaxValue) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt64.cs deleted file mode 100644 index b20108f761..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllOnes.UInt64.cs +++ /dev/null @@ -1,501 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllOnesUInt64() - { - var test = new BooleanUnaryOpTest__TestAllOnesUInt64(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanUnaryOpTest__TestAllOnesUInt64 - { - private struct DataTable - { - private byte[] inArray1; - - private GCHandle inHandle1; - - private ulong alignment; - - public DataTable(UInt64[] inArray1, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanUnaryOpTest__TestAllOnesUInt64 testClass) - { - var result = Sse41.TestAllOnes(_fld1); - testClass.ValidateResult(_fld1, result); - } - - public void RunStructFldScenario_Load(BooleanUnaryOpTest__TestAllOnesUInt64 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt64*)(pFld1)) - ); - - testClass.ValidateResult(_fld1, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt64); - - private static UInt64[] _data1 = new UInt64[Op1ElementCount]; - - private static Vector128 _clsVar1; - - private Vector128 _fld1; - - private DataTable _dataTable; - - static BooleanUnaryOpTest__TestAllOnesUInt64() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanUnaryOpTest__TestAllOnesUInt64() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - _dataTable = new DataTable(_data1, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllOnes( - Unsafe.Read>(_dataTable.inArray1Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllOnes( - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllOnes), new Type[] { typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllOnes( - _clsVar1 - ); - - ValidateResult(_clsVar1, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt64*)(pClsVar1)) - ); - - ValidateResult(_clsVar1, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)); - var result = Sse41.TestAllOnes(op1); - - ValidateResult(op1, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanUnaryOpTest__TestAllOnesUInt64(); - var result = Sse41.TestAllOnes(test._fld1); - - ValidateResult(test._fld1, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanUnaryOpTest__TestAllOnesUInt64(); - - fixed (Vector128* pFld1 = &test._fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt64*)(pFld1)) - ); - - ValidateResult(test._fld1, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllOnes(_fld1); - - ValidateResult(_fld1, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - { - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt64*)(pFld1)) - ); - - ValidateResult(_fld1, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes(test._fld1); - ValidateResult(test._fld1, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllOnes( - Sse2.LoadVector128((UInt64*)(&test._fld1)) - ); - - ValidateResult(test._fld1, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, bool result, [CallerMemberName] string method = "") - { - UInt64[] inArray1 = new UInt64[Op1ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(void* op1, bool result, [CallerMemberName] string method = "") - { - UInt64[] inArray1 = new UInt64[Op1ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, result, method); - } - - private void ValidateResult(UInt64[] value, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((~value[i] & ulong.MaxValue) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllOnes)}(Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" value: ({string.Join(", ", value)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Byte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Byte.cs deleted file mode 100644 index 074374d3f4..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Byte.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosByte() - { - var test = new BooleanBinaryOpTest__TestAllZerosByte(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosByte - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Byte[] inArray1, Byte[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosByte testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosByte testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Byte*)(pFld1)), - Sse2.LoadVector128((Byte*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Byte); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Byte); - - private static Byte[] _data1 = new Byte[Op1ElementCount]; - private static Byte[] _data2 = new Byte[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosByte() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosByte() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Byte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Byte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Byte*)(pClsVar1)), - Sse2.LoadVector128((Byte*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Byte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosByte(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosByte(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Byte*)(pFld1)), - Sse2.LoadVector128((Byte*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Byte*)(pFld1)), - Sse2.LoadVector128((Byte*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Byte*)(&test._fld1)), - Sse2.LoadVector128((Byte*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Byte[] inArray1 = new Byte[Op1ElementCount]; - Byte[] inArray2 = new Byte[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Byte[] inArray1 = new Byte[Op1ElementCount]; - Byte[] inArray2 = new Byte[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Byte[] left, Byte[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int16.cs deleted file mode 100644 index a817f88263..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int16.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosInt16() - { - var test = new BooleanBinaryOpTest__TestAllZerosInt16(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosInt16 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Int16[] inArray1, Int16[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosInt16 testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosInt16 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int16*)(pFld1)), - Sse2.LoadVector128((Int16*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int16); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Int16); - - private static Int16[] _data1 = new Int16[Op1ElementCount]; - private static Int16[] _data2 = new Int16[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosInt16() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosInt16() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int16*)(pClsVar1)), - Sse2.LoadVector128((Int16*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Int16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosInt16(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosInt16(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int16*)(pFld1)), - Sse2.LoadVector128((Int16*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int16*)(pFld1)), - Sse2.LoadVector128((Int16*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int16*)(&test._fld1)), - Sse2.LoadVector128((Int16*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Int16[] inArray1 = new Int16[Op1ElementCount]; - Int16[] inArray2 = new Int16[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Int16[] inArray1 = new Int16[Op1ElementCount]; - Int16[] inArray2 = new Int16[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Int16[] left, Int16[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int32.cs deleted file mode 100644 index b5fe2e0258..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int32.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosInt32() - { - var test = new BooleanBinaryOpTest__TestAllZerosInt32(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosInt32 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Int32[] inArray1, Int32[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosInt32 testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosInt32 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int32*)(pFld1)), - Sse2.LoadVector128((Int32*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int32); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Int32); - - private static Int32[] _data1 = new Int32[Op1ElementCount]; - private static Int32[] _data2 = new Int32[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosInt32() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosInt32() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int32*)(pClsVar1)), - Sse2.LoadVector128((Int32*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Int32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosInt32(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosInt32(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int32*)(pFld1)), - Sse2.LoadVector128((Int32*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int32*)(pFld1)), - Sse2.LoadVector128((Int32*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int32*)(&test._fld1)), - Sse2.LoadVector128((Int32*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Int32[] inArray1 = new Int32[Op1ElementCount]; - Int32[] inArray2 = new Int32[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Int32[] inArray1 = new Int32[Op1ElementCount]; - Int32[] inArray2 = new Int32[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Int32[] left, Int32[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int64.cs deleted file mode 100644 index 9668f1aaeb..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.Int64.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosInt64() - { - var test = new BooleanBinaryOpTest__TestAllZerosInt64(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosInt64 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Int64[] inArray1, Int64[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosInt64 testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosInt64 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int64*)(pFld1)), - Sse2.LoadVector128((Int64*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int64); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Int64); - - private static Int64[] _data1 = new Int64[Op1ElementCount]; - private static Int64[] _data2 = new Int64[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosInt64() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosInt64() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int64*)(pClsVar1)), - Sse2.LoadVector128((Int64*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Int64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosInt64(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosInt64(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int64*)(pFld1)), - Sse2.LoadVector128((Int64*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int64*)(pFld1)), - Sse2.LoadVector128((Int64*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((Int64*)(&test._fld1)), - Sse2.LoadVector128((Int64*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Int64[] inArray1 = new Int64[Op1ElementCount]; - Int64[] inArray2 = new Int64[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Int64[] inArray1 = new Int64[Op1ElementCount]; - Int64[] inArray2 = new Int64[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Int64[] left, Int64[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.SByte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.SByte.cs deleted file mode 100644 index b9bac593fb..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.SByte.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosSByte() - { - var test = new BooleanBinaryOpTest__TestAllZerosSByte(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosSByte - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(SByte[] inArray1, SByte[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosSByte testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosSByte testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((SByte*)(pFld1)), - Sse2.LoadVector128((SByte*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(SByte); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(SByte); - - private static SByte[] _data1 = new SByte[Op1ElementCount]; - private static SByte[] _data2 = new SByte[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosSByte() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosSByte() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((SByte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((SByte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((SByte*)(pClsVar1)), - Sse2.LoadVector128((SByte*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((SByte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosSByte(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosSByte(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((SByte*)(pFld1)), - Sse2.LoadVector128((SByte*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((SByte*)(pFld1)), - Sse2.LoadVector128((SByte*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((SByte*)(&test._fld1)), - Sse2.LoadVector128((SByte*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - SByte[] inArray1 = new SByte[Op1ElementCount]; - SByte[] inArray2 = new SByte[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - SByte[] inArray1 = new SByte[Op1ElementCount]; - SByte[] inArray2 = new SByte[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(SByte[] left, SByte[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt16.cs deleted file mode 100644 index 6fc7837d50..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt16.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosUInt16() - { - var test = new BooleanBinaryOpTest__TestAllZerosUInt16(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosUInt16 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(UInt16[] inArray1, UInt16[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosUInt16 testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosUInt16 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt16*)(pFld1)), - Sse2.LoadVector128((UInt16*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt16); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(UInt16); - - private static UInt16[] _data1 = new UInt16[Op1ElementCount]; - private static UInt16[] _data2 = new UInt16[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosUInt16() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosUInt16() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt16*)(pClsVar1)), - Sse2.LoadVector128((UInt16*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosUInt16(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosUInt16(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt16*)(pFld1)), - Sse2.LoadVector128((UInt16*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt16*)(pFld1)), - Sse2.LoadVector128((UInt16*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt16*)(&test._fld1)), - Sse2.LoadVector128((UInt16*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - UInt16[] inArray1 = new UInt16[Op1ElementCount]; - UInt16[] inArray2 = new UInt16[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - UInt16[] inArray1 = new UInt16[Op1ElementCount]; - UInt16[] inArray2 = new UInt16[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(UInt16[] left, UInt16[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt32.cs deleted file mode 100644 index 32d21b47ae..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt32.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosUInt32() - { - var test = new BooleanBinaryOpTest__TestAllZerosUInt32(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosUInt32 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(UInt32[] inArray1, UInt32[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosUInt32 testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosUInt32 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt32*)(pFld1)), - Sse2.LoadVector128((UInt32*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt32); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(UInt32); - - private static UInt32[] _data1 = new UInt32[Op1ElementCount]; - private static UInt32[] _data2 = new UInt32[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosUInt32() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosUInt32() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt32*)(pClsVar1)), - Sse2.LoadVector128((UInt32*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((UInt32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosUInt32(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosUInt32(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt32*)(pFld1)), - Sse2.LoadVector128((UInt32*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt32*)(pFld1)), - Sse2.LoadVector128((UInt32*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt32*)(&test._fld1)), - Sse2.LoadVector128((UInt32*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - UInt32[] inArray1 = new UInt32[Op1ElementCount]; - UInt32[] inArray2 = new UInt32[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - UInt32[] inArray1 = new UInt32[Op1ElementCount]; - UInt32[] inArray2 = new UInt32[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(UInt32[] left, UInt32[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt64.cs deleted file mode 100644 index 51dca4e987..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestAllZeros.UInt64.cs +++ /dev/null @@ -1,545 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestAllZerosUInt64() - { - var test = new BooleanBinaryOpTest__TestAllZerosUInt64(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestAllZerosUInt64 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(UInt64[] inArray1, UInt64[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestAllZerosUInt64 testClass) - { - var result = Sse41.TestAllZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestAllZerosUInt64 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt64*)(pFld1)), - Sse2.LoadVector128((UInt64*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt64); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(UInt64); - - private static UInt64[] _data1 = new UInt64[Op1ElementCount]; - private static UInt64[] _data2 = new UInt64[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestAllZerosUInt64() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestAllZerosUInt64() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestAllZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestAllZeros( - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestAllZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestAllZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt64*)(pClsVar1)), - Sse2.LoadVector128((UInt64*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((UInt64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestAllZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestAllZerosUInt64(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestAllZerosUInt64(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt64*)(pFld1)), - Sse2.LoadVector128((UInt64*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestAllZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt64*)(pFld1)), - Sse2.LoadVector128((UInt64*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestAllZeros( - Sse2.LoadVector128((UInt64*)(&test._fld1)), - Sse2.LoadVector128((UInt64*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - UInt64[] inArray1 = new UInt64[Op1ElementCount]; - UInt64[] inArray2 = new UInt64[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - UInt64[] inArray1 = new UInt64[Op1ElementCount]; - UInt64[] inArray2 = new UInt64[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(UInt64[] left, UInt64[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult &= ((left[i] & right[i]) == 0); - } - - succeeded = (expectedResult == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestAllZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Byte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Byte.cs deleted file mode 100644 index f5a86d3c60..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Byte.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosByte() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosByte(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosByte - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Byte[] inArray1, Byte[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosByte testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosByte testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Byte*)(pFld1)), - Sse2.LoadVector128((Byte*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Byte); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Byte); - - private static Byte[] _data1 = new Byte[Op1ElementCount]; - private static Byte[] _data2 = new Byte[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosByte() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosByte() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Byte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Byte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Byte*)(pClsVar1)), - Sse2.LoadVector128((Byte*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Byte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Byte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Byte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosByte(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosByte(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Byte*)(pFld1)), - Sse2.LoadVector128((Byte*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Byte*)(pFld1)), - Sse2.LoadVector128((Byte*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Byte*)(&test._fld1)), - Sse2.LoadVector128((Byte*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Byte[] inArray1 = new Byte[Op1ElementCount]; - Byte[] inArray2 = new Byte[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Byte[] inArray1 = new Byte[Op1ElementCount]; - Byte[] inArray2 = new Byte[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Byte[] left, Byte[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int16.cs deleted file mode 100644 index 3a462a92fa..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int16.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosInt16() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt16(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosInt16 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Int16[] inArray1, Int16[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosInt16 testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosInt16 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int16*)(pFld1)), - Sse2.LoadVector128((Int16*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int16); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Int16); - - private static Int16[] _data1 = new Int16[Op1ElementCount]; - private static Int16[] _data2 = new Int16[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosInt16() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosInt16() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int16*)(pClsVar1)), - Sse2.LoadVector128((Int16*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Int16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Int16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt16(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt16(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int16*)(pFld1)), - Sse2.LoadVector128((Int16*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int16*)(pFld1)), - Sse2.LoadVector128((Int16*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int16*)(&test._fld1)), - Sse2.LoadVector128((Int16*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Int16[] inArray1 = new Int16[Op1ElementCount]; - Int16[] inArray2 = new Int16[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Int16[] inArray1 = new Int16[Op1ElementCount]; - Int16[] inArray2 = new Int16[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Int16[] left, Int16[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int32.cs deleted file mode 100644 index e6109177ab..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int32.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosInt32() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt32(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosInt32 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Int32[] inArray1, Int32[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosInt32 testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosInt32 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int32*)(pFld1)), - Sse2.LoadVector128((Int32*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int32); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Int32); - - private static Int32[] _data1 = new Int32[Op1ElementCount]; - private static Int32[] _data2 = new Int32[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosInt32() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosInt32() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int32*)(pClsVar1)), - Sse2.LoadVector128((Int32*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Int32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Int32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt32(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt32(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int32*)(pFld1)), - Sse2.LoadVector128((Int32*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int32*)(pFld1)), - Sse2.LoadVector128((Int32*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int32*)(&test._fld1)), - Sse2.LoadVector128((Int32*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Int32[] inArray1 = new Int32[Op1ElementCount]; - Int32[] inArray2 = new Int32[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Int32[] inArray1 = new Int32[Op1ElementCount]; - Int32[] inArray2 = new Int32[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Int32[] left, Int32[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int64.cs deleted file mode 100644 index d1d1ad7c29..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.Int64.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosInt64() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt64(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosInt64 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(Int64[] inArray1, Int64[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosInt64 testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosInt64 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int64*)(pFld1)), - Sse2.LoadVector128((Int64*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Int64); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Int64); - - private static Int64[] _data1 = new Int64[Op1ElementCount]; - private static Int64[] _data2 = new Int64[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosInt64() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosInt64() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((Int64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int64*)(pClsVar1)), - Sse2.LoadVector128((Int64*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((Int64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((Int64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((Int64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt64(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosInt64(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int64*)(pFld1)), - Sse2.LoadVector128((Int64*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int64*)(pFld1)), - Sse2.LoadVector128((Int64*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((Int64*)(&test._fld1)), - Sse2.LoadVector128((Int64*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - Int64[] inArray1 = new Int64[Op1ElementCount]; - Int64[] inArray2 = new Int64[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - Int64[] inArray1 = new Int64[Op1ElementCount]; - Int64[] inArray2 = new Int64[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(Int64[] left, Int64[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.SByte.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.SByte.cs deleted file mode 100644 index 7502291f20..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.SByte.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosSByte() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosSByte(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosSByte - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(SByte[] inArray1, SByte[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosSByte testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosSByte testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((SByte*)(pFld1)), - Sse2.LoadVector128((SByte*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(SByte); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(SByte); - - private static SByte[] _data1 = new SByte[Op1ElementCount]; - private static SByte[] _data2 = new SByte[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosSByte() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosSByte() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((SByte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((SByte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((SByte*)(pClsVar1)), - Sse2.LoadVector128((SByte*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((SByte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((SByte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((SByte*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosSByte(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosSByte(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((SByte*)(pFld1)), - Sse2.LoadVector128((SByte*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((SByte*)(pFld1)), - Sse2.LoadVector128((SByte*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((SByte*)(&test._fld1)), - Sse2.LoadVector128((SByte*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - SByte[] inArray1 = new SByte[Op1ElementCount]; - SByte[] inArray2 = new SByte[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - SByte[] inArray1 = new SByte[Op1ElementCount]; - SByte[] inArray2 = new SByte[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(SByte[] left, SByte[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt16.cs deleted file mode 100644 index 74208d5e35..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt16.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosUInt16() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt16(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosUInt16 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(UInt16[] inArray1, UInt16[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosUInt16 testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosUInt16 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt16*)(pFld1)), - Sse2.LoadVector128((UInt16*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt16); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(UInt16); - - private static UInt16[] _data1 = new UInt16[Op1ElementCount]; - private static UInt16[] _data2 = new UInt16[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosUInt16() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosUInt16() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt16*)(pClsVar1)), - Sse2.LoadVector128((UInt16*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt16(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt16(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt16*)(pFld1)), - Sse2.LoadVector128((UInt16*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt16*)(pFld1)), - Sse2.LoadVector128((UInt16*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt16*)(&test._fld1)), - Sse2.LoadVector128((UInt16*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - UInt16[] inArray1 = new UInt16[Op1ElementCount]; - UInt16[] inArray2 = new UInt16[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - UInt16[] inArray1 = new UInt16[Op1ElementCount]; - UInt16[] inArray2 = new UInt16[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(UInt16[] left, UInt16[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt32.cs deleted file mode 100644 index 64950fc5c7..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt32.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosUInt32() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt32(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosUInt32 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(UInt32[] inArray1, UInt32[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosUInt32 testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosUInt32 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt32*)(pFld1)), - Sse2.LoadVector128((UInt32*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt32); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(UInt32); - - private static UInt32[] _data1 = new UInt32[Op1ElementCount]; - private static UInt32[] _data2 = new UInt32[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosUInt32() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosUInt32() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt32*)(pClsVar1)), - Sse2.LoadVector128((UInt32*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((UInt32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((UInt32*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt32(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt32(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt32*)(pFld1)), - Sse2.LoadVector128((UInt32*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt32*)(pFld1)), - Sse2.LoadVector128((UInt32*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt32*)(&test._fld1)), - Sse2.LoadVector128((UInt32*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - UInt32[] inArray1 = new UInt32[Op1ElementCount]; - UInt32[] inArray2 = new UInt32[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - UInt32[] inArray1 = new UInt32[Op1ElementCount]; - UInt32[] inArray2 = new UInt32[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(UInt32[] left, UInt32[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt64.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt64.cs deleted file mode 100644 index b97e93a2f3..0000000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestMixOnesZeros.UInt64.cs +++ /dev/null @@ -1,552 +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. - -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - -namespace JIT.HardwareIntrinsics.X86 -{ - public static partial class Program - { - private static void TestMixOnesZerosUInt64() - { - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt64(); - - if (test.IsSupported) - { - // Validates basic functionality works, using Unsafe.Read - test.RunBasicScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // 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(); - - if (Sse2.IsSupported) - { - // Validates passing a static member works, using pinning and Load - test.RunClsVarScenario_Load(); - } - - // Validates passing a local works, using Unsafe.Read - test.RunLclVarScenario_UnsafeRead(); - - if (Sse2.IsSupported) - { - // 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 class works - test.RunClassLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local class works, using pinning and Load - test.RunClassLclFldScenario_Load(); - } - - // Validates passing an instance member of a class works - test.RunClassFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a class works, using pinning and Load - test.RunClassFldScenario_Load(); - } - - // Validates passing the field of a local struct works - test.RunStructLclFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing the field of a local struct works, using pinning and Load - test.RunStructLclFldScenario_Load(); - } - - // Validates passing an instance member of a struct works - test.RunStructFldScenario(); - - if (Sse2.IsSupported) - { - // Validates passing an instance member of a struct works, using pinning and Load - test.RunStructFldScenario_Load(); - } - } - else - { - // Validates we throw on unsupported hardware - test.RunUnsupportedScenario(); - } - - if (!test.Succeeded) - { - throw new Exception("One or more scenarios did not complete as expected."); - } - } - } - - public sealed unsafe class BooleanBinaryOpTest__TestMixOnesZerosUInt64 - { - private struct DataTable - { - private byte[] inArray1; - private byte[] inArray2; - - private GCHandle inHandle1; - private GCHandle inHandle2; - - private ulong alignment; - - public DataTable(UInt64[] inArray1, UInt64[] inArray2, int alignment) - { - int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); - int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); - if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) - { - throw new ArgumentException("Invalid value of alignment"); - } - - this.inArray1 = new byte[alignment * 2]; - this.inArray2 = new byte[alignment * 2]; - - this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); - this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); - - this.alignment = (ulong)alignment; - - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); - Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); - } - - public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); - public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - } - - private static unsafe void* Align(byte* buffer, ulong expectedAlignment) - { - return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); - } - } - - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - - public void RunStructFldScenario(BooleanBinaryOpTest__TestMixOnesZerosUInt64 testClass) - { - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - testClass.ValidateResult(_fld1, _fld2, result); - } - - public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestMixOnesZerosUInt64 testClass) - { - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt64*)(pFld1)), - Sse2.LoadVector128((UInt64*)(pFld2)) - ); - - testClass.ValidateResult(_fld1, _fld2, result); - } - } - } - - private static readonly int LargestVectorSize = 16; - - private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(UInt64); - private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(UInt64); - - private static UInt64[] _data1 = new UInt64[Op1ElementCount]; - private static UInt64[] _data2 = new UInt64[Op2ElementCount]; - - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - - private DataTable _dataTable; - - static BooleanBinaryOpTest__TestMixOnesZerosUInt64() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - - public BooleanBinaryOpTest__TestMixOnesZerosUInt64() - { - Succeeded = true; - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); } - _dataTable = new DataTable(_data1, _data2, LargestVectorSize); - } - - public bool IsSupported => Sse41.IsSupported; - - public bool Succeeded { get; set; } - - public void RunBasicScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); - - var result = Sse41.TestMixOnesZeros( - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunBasicScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); - - var result = Sse41.TestMixOnesZeros( - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray2Ptr)) - ); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result); - } - - public void RunReflectionScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Unsafe.Read>(_dataTable.inArray1Ptr), - Unsafe.Read>(_dataTable.inArray2Ptr) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadVector128((UInt64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunReflectionScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned)); - - var result = typeof(Sse41).GetMethod(nameof(Sse41.TestMixOnesZeros), new Type[] { typeof(Vector128), typeof(Vector128) }) - .Invoke(null, new object[] { - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)), - Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray2Ptr)) - }); - - ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result)); - } - - public void RunClsVarScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); - - var result = Sse41.TestMixOnesZeros( - _clsVar1, - _clsVar2 - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - - public void RunClsVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); - - fixed (Vector128* pClsVar1 = &_clsVar1) - fixed (Vector128* pClsVar2 = &_clsVar2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt64*)(pClsVar1)), - Sse2.LoadVector128((UInt64*)(pClsVar2)) - ); - - ValidateResult(_clsVar1, _clsVar2, result); - } - } - - public void RunLclVarScenario_UnsafeRead() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - - var op1 = Unsafe.Read>(_dataTable.inArray1Ptr); - var op2 = Unsafe.Read>(_dataTable.inArray2Ptr); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - - var op1 = Sse2.LoadVector128((UInt64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadVector128((UInt64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunLclVarScenario_LoadAligned() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - - var op1 = Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray1Ptr)); - var op2 = Sse2.LoadAlignedVector128((UInt64*)(_dataTable.inArray2Ptr)); - var result = Sse41.TestMixOnesZeros(op1, op2); - - ValidateResult(op1, op2, result); - } - - public void RunClassLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt64(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunClassLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); - - var test = new BooleanBinaryOpTest__TestMixOnesZerosUInt64(); - - fixed (Vector128* pFld1 = &test._fld1) - fixed (Vector128* pFld2 = &test._fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt64*)(pFld1)), - Sse2.LoadVector128((UInt64*)(pFld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - } - - public void RunClassFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); - - var result = Sse41.TestMixOnesZeros(_fld1, _fld2); - - ValidateResult(_fld1, _fld2, result); - } - - public void RunClassFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); - - fixed (Vector128* pFld1 = &_fld1) - fixed (Vector128* pFld2 = &_fld2) - { - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt64*)(pFld1)), - Sse2.LoadVector128((UInt64*)(pFld2)) - ); - - ValidateResult(_fld1, _fld2, result); - } - } - - public void RunStructLclFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros(test._fld1, test._fld2); - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructLclFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); - - var test = TestStruct.Create(); - var result = Sse41.TestMixOnesZeros( - Sse2.LoadVector128((UInt64*)(&test._fld1)), - Sse2.LoadVector128((UInt64*)(&test._fld2)) - ); - - ValidateResult(test._fld1, test._fld2, result); - } - - public void RunStructFldScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); - - var test = TestStruct.Create(); - test.RunStructFldScenario(this); - } - - public void RunStructFldScenario_Load() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load)); - - var test = TestStruct.Create(); - test.RunStructFldScenario_Load(this); - } - - public void RunUnsupportedScenario() - { - TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); - - bool succeeded = false; - - try - { - RunBasicScenario_UnsafeRead(); - } - catch (PlatformNotSupportedException) - { - succeeded = true; - } - - if (!succeeded) - { - Succeeded = false; - } - } - - private void ValidateResult(Vector128 op1, Vector128 op2, bool result, [CallerMemberName] string method = "") - { - UInt64[] inArray1 = new UInt64[Op1ElementCount]; - UInt64[] inArray2 = new UInt64[Op2ElementCount]; - - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray1[0]), op1); - Unsafe.WriteUnaligned(ref Unsafe.As(ref inArray2[0]), op2); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") - { - UInt64[] inArray1 = new UInt64[Op1ElementCount]; - UInt64[] inArray2 = new UInt64[Op2ElementCount]; - - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); - - ValidateResult(inArray1, inArray2, result, method); - } - - private void ValidateResult(UInt64[] left, UInt64[] right, bool result, [CallerMemberName] string method = "") - { - bool succeeded = true; - - var expectedResult1 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult1 &= (((left[i] & right[i]) == 0)); - } - - var expectedResult2 = true; - - for (var i = 0; i < Op1ElementCount; i++) - { - expectedResult2 &= (((~left[i] & right[i]) == 0)); - } - - succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result); - - if (!succeeded) - { - TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestMixOnesZeros)}(Vector128, Vector128): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); - TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); - TestLibrary.TestFramework.LogInformation($" result: ({result})"); - TestLibrary.TestFramework.LogInformation(string.Empty); - - Succeeded = false; - } - } - } -} -- cgit v1.2.3