<Compile Include="Permute.Double.1.cs" />
<Compile Include="Permute.Single.2.cs" />
<Compile Include="Permute.Double.2.cs" />
- <Compile Include="PermuteVar.Single.cs" />
- <Compile Include="PermuteVar.Double.cs" />
<Compile Include="RoundCurrentDirection.Double.cs" />
<Compile Include="RoundCurrentDirection.Single.cs" />
<Compile Include="RoundToNearestInteger.Double.cs" />
<Compile Include="Permute.Double.1.cs" />
<Compile Include="Permute.Single.2.cs" />
<Compile Include="Permute.Double.2.cs" />
- <Compile Include="PermuteVar.Single.cs" />
- <Compile Include="PermuteVar.Double.cs" />
<Compile Include="RoundCurrentDirection.Double.cs" />
<Compile Include="RoundCurrentDirection.Single.cs" />
<Compile Include="RoundToNearestInteger.Double.cs" />
+++ /dev/null
-// 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 PermuteVarDouble()
- {
- var test = new SimpleBinaryOpTest__PermuteVarDouble();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.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 (Avx.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();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.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();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class SimpleBinaryOpTest__PermuteVarDouble
- {
- private struct TestStruct
- {
- public Vector256<Double> _fld1;
- public Vector256<Double> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref testStruct._fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int64BitsToDouble(1); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref testStruct._fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(SimpleBinaryOpTest__PermuteVarDouble testClass)
- {
- var result = Avx.PermuteVar(_fld1, _fld2);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Double>>() / sizeof(Double);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector256<Double>>() / sizeof(Double);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Double>>() / sizeof(Double);
-
- private static Double[] _data1 = new Double[Op1ElementCount];
- private static Double[] _data2 = new Double[Op2ElementCount];
-
- private static Vector256<Double> _clsVar1;
- private static Vector256<Double> _clsVar2;
-
- private Vector256<Double> _fld1;
- private Vector256<Double> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Double, Double, Double> _dataTable;
-
- static SimpleBinaryOpTest__PermuteVarDouble()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _clsVar1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int64BitsToDouble(1); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _clsVar2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- }
-
- public SimpleBinaryOpTest__PermuteVarDouble()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int64BitsToDouble(1); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int64BitsToDouble(1); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Double, Double, Double>(_data1, _data2, new Double[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.PermuteVar(
- Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr),
- Unsafe.Read<Vector256<Double>>(_dataTable.inArray2Ptr)
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.PermuteVar(
- Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr)),
- Avx.LoadVector256((Double*)(_dataTable.inArray2Ptr))
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.PermuteVar(
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr)),
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArray2Ptr))
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.PermuteVar), new Type[] { typeof(Vector256<Double>), typeof(Vector256<Double>) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr),
- Unsafe.Read<Vector256<Double>>(_dataTable.inArray2Ptr)
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Double>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.PermuteVar), new Type[] { typeof(Vector256<Double>), typeof(Vector256<Double>) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr)),
- Avx.LoadVector256((Double*)(_dataTable.inArray2Ptr))
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Double>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.PermuteVar), new Type[] { typeof(Vector256<Double>), typeof(Vector256<Double>) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr)),
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArray2Ptr))
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Double>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.PermuteVar(
- _clsVar1,
- _clsVar2
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr);
- var right = Unsafe.Read<Vector256<Double>>(_dataTable.inArray2Ptr);
- var result = Avx.PermuteVar(left, right);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr));
- var right = Avx.LoadVector256((Double*)(_dataTable.inArray2Ptr));
- var result = Avx.PermuteVar(left, right);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr));
- var right = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray2Ptr));
- var result = Avx.PermuteVar(left, right);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new SimpleBinaryOpTest__PermuteVarDouble();
- var result = Avx.PermuteVar(test._fld1, test._fld2);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.PermuteVar(_fld1, _fld2);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.PermuteVar(test._fld1, test._fld2);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- Succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- Succeeded = true;
- }
- }
-
- private void ValidateResult(Vector256<Double> left, Vector256<Double> right, void* result, [CallerMemberName] string method = "")
- {
- Double[] inArray1 = new Double[Op1ElementCount];
- Double[] inArray2 = new Double[Op2ElementCount];
- Double[] outArray = new Double[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), left);
- Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), right);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Double[] inArray1 = new Double[Op1ElementCount];
- Double[] inArray2 = new Double[Op2ElementCount];
- Double[] outArray = new Double[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Double>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector256<Double>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Double[] left, Double[] right, Double[] result, [CallerMemberName] string method = "")
- {
- if (BitConverter.DoubleToInt64Bits(left[0]) != BitConverter.DoubleToInt64Bits(result[0]))
- {
- Succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if (i > 1 ? (BitConverter.DoubleToInt64Bits(left[2]) != BitConverter.DoubleToInt64Bits(result[i])) : (BitConverter.DoubleToInt64Bits(left[0]) != BitConverter.DoubleToInt64Bits(result[i])))
- {
- Succeeded = false;
- break;
- }
- }
- }
-
- if (!Succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.PermuteVar)}<Double>(Vector256<Double>, Vector256<Double>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
- }
- }
- }
-}
+++ /dev/null
-// 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 PermuteVarSingle()
- {
- var test = new SimpleBinaryOpTest__PermuteVarSingle();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.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 (Avx.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();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.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();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class SimpleBinaryOpTest__PermuteVarSingle
- {
- private struct TestStruct
- {
- public Vector256<Single> _fld1;
- public Vector256<Single> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref testStruct._fld1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int32BitsToSingle(1); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref testStruct._fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(SimpleBinaryOpTest__PermuteVarSingle testClass)
- {
- var result = Avx.PermuteVar(_fld1, _fld2);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Single>>() / sizeof(Single);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector256<Single>>() / sizeof(Single);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Single>>() / sizeof(Single);
-
- private static Single[] _data1 = new Single[Op1ElementCount];
- private static Single[] _data2 = new Single[Op2ElementCount];
-
- private static Vector256<Single> _clsVar1;
- private static Vector256<Single> _clsVar2;
-
- private Vector256<Single> _fld1;
- private Vector256<Single> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Single, Single, Single> _dataTable;
-
- static SimpleBinaryOpTest__PermuteVarSingle()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _clsVar1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int32BitsToSingle(1); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _clsVar2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- }
-
- public SimpleBinaryOpTest__PermuteVarSingle()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _fld1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int32BitsToSingle(1); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = BitConverter.Int32BitsToSingle(1); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Single, Single, Single>(_data1, _data2, new Single[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.PermuteVar(
- Unsafe.Read<Vector256<Single>>(_dataTable.inArray1Ptr),
- Unsafe.Read<Vector256<Single>>(_dataTable.inArray2Ptr)
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.PermuteVar(
- Avx.LoadVector256((Single*)(_dataTable.inArray1Ptr)),
- Avx.LoadVector256((Single*)(_dataTable.inArray2Ptr))
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.PermuteVar(
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArray1Ptr)),
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArray2Ptr))
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.PermuteVar), new Type[] { typeof(Vector256<Single>), typeof(Vector256<Single>) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Single>>(_dataTable.inArray1Ptr),
- Unsafe.Read<Vector256<Single>>(_dataTable.inArray2Ptr)
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Single>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.PermuteVar), new Type[] { typeof(Vector256<Single>), typeof(Vector256<Single>) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Single*)(_dataTable.inArray1Ptr)),
- Avx.LoadVector256((Single*)(_dataTable.inArray2Ptr))
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Single>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.PermuteVar), new Type[] { typeof(Vector256<Single>), typeof(Vector256<Single>) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArray1Ptr)),
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArray2Ptr))
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Single>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.PermuteVar(
- _clsVar1,
- _clsVar2
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Single>>(_dataTable.inArray1Ptr);
- var right = Unsafe.Read<Vector256<Single>>(_dataTable.inArray2Ptr);
- var result = Avx.PermuteVar(left, right);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Single*)(_dataTable.inArray1Ptr));
- var right = Avx.LoadVector256((Single*)(_dataTable.inArray2Ptr));
- var result = Avx.PermuteVar(left, right);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Single*)(_dataTable.inArray1Ptr));
- var right = Avx.LoadAlignedVector256((Single*)(_dataTable.inArray2Ptr));
- var result = Avx.PermuteVar(left, right);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new SimpleBinaryOpTest__PermuteVarSingle();
- var result = Avx.PermuteVar(test._fld1, test._fld2);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.PermuteVar(_fld1, _fld2);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.PermuteVar(test._fld1, test._fld2);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- Succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- Succeeded = true;
- }
- }
-
- private void ValidateResult(Vector256<Single> left, Vector256<Single> right, void* result, [CallerMemberName] string method = "")
- {
- Single[] inArray1 = new Single[Op1ElementCount];
- Single[] inArray2 = new Single[Op2ElementCount];
- Single[] outArray = new Single[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), left);
- Unsafe.WriteUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), right);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Single[] inArray1 = new Single[Op1ElementCount];
- Single[] inArray2 = new Single[Op2ElementCount];
- Single[] outArray = new Single[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Single>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector256<Single>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "")
- {
- if (BitConverter.SingleToInt32Bits(left[1]) != BitConverter.SingleToInt32Bits(result[0]))
- {
- Succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if (i > 3 ? (BitConverter.SingleToInt32Bits(left[5]) != BitConverter.SingleToInt32Bits(result[i])) : (BitConverter.SingleToInt32Bits(left[1]) != BitConverter.SingleToInt32Bits(result[i])))
- {
- Succeeded = false;
- break;
- }
- }
- }
-
- if (!Succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.PermuteVar)}<Single>(Vector256<Single>, Vector256<Single>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
- }
- }
- }
-}
["Permute.Double.1"] = PermuteDouble1,
["Permute.Single.2"] = PermuteSingle2,
["Permute.Double.2"] = PermuteDouble2,
- ["PermuteVar.Single"] = PermuteVarSingle,
- ["PermuteVar.Double"] = PermuteVarDouble,
["RoundCurrentDirection.Double"] = RoundCurrentDirectionDouble,
["RoundCurrentDirection.Single"] = RoundCurrentDirectionSingle,
["RoundToNearestInteger.Double"] = RoundToNearestIntegerDouble,
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "Permute", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(firstOp[1])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[2]) != BitConverter.DoubleToInt64Bits(firstOp[2]) || BitConverter.DoubleToInt64Bits(result[2]) != BitConverter.DoubleToInt64Bits(firstOp[2])"}),
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Sse", ["Method"] = "Permute", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Single", ["Imm"] = "2", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(firstOp[2])", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[1]) != BitConverter.SingleToInt32Bits(firstOp[0]) || BitConverter.SingleToInt32Bits(result[2]) != BitConverter.SingleToInt32Bits(firstOp[0])"}),
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Sse2",["Method"] = "Permute", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector128", ["Op1BaseType"] = "Double", ["Imm"] = "2", ["LargestVectorSize"] = "16", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(firstOp[0])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[1]) != BitConverter.DoubleToInt64Bits(firstOp[1])"}),
- ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "PermuteVar", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector256", ["Op2BaseType"] = "Single", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "BitConverter.Int32BitsToSingle(1)", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(left[1]) != BitConverter.SingleToInt32Bits(result[0])", ["ValidateRemainingResults"] = "i > 3 ? (BitConverter.SingleToInt32Bits(left[5]) != BitConverter.SingleToInt32Bits(result[i])) : (BitConverter.SingleToInt32Bits(left[1]) != BitConverter.SingleToInt32Bits(result[i]))"}),
- ("SimpleBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "PermuteVar", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector256", ["Op2BaseType"] = "Double", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "BitConverter.Int64BitsToDouble(1)", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(left[0]) != BitConverter.DoubleToInt64Bits(result[0])", ["ValidateRemainingResults"] = "i > 1 ? (BitConverter.DoubleToInt64Bits(left[2]) != BitConverter.DoubleToInt64Bits(result[i])) : (BitConverter.DoubleToInt64Bits(left[0]) != BitConverter.DoubleToInt64Bits(result[i]))"}),
("SimpleUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "RoundCurrentDirection", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(Math.Round(firstOp[0]))", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(Math.Round(firstOp[i]))"}),
("SimpleUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "RoundCurrentDirection", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Single", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(MathF.Round(firstOp[0]))", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(MathF.Round(firstOp[i]))"}),
("SimpleUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "RoundToNearestInteger", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(Math.Round(firstOp[0], MidpointRounding.AwayFromZero))", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(Math.Round(firstOp[i], MidpointRounding.AwayFromZero))"}),