Skip to content

Commit

Permalink
[Arm64] Vector64<double>.CreateScalar, Vector64<ulong>CreateScalar an…
Browse files Browse the repository at this point in the history
…d Vector64<long>.CreateScalar (dotnet#38139)
  • Loading branch information
echesakov authored Jun 22, 2020
1 parent 8552b6d commit ab119ad
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ private static readonly (string templateFileName, Dictionary<string, string> tem
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "Create", ["VectorType"] = "Vector64", ["BaseType"] = "UInt32", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != expectedValue" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "Create", ["VectorType"] = "Vector64", ["BaseType"] = "UInt64", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != expectedValue" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "Byte", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "Double", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "Int16", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "Int32", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "Int64", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "SByte", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "Single", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "UInt16", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "UInt32", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalar", ["VectorType"] = "Vector64", ["BaseType"] = "UInt64", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "resultElements[i] != 0" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalarUnsafe", ["VectorType"] = "Vector64", ["BaseType"] = "Byte", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "false /* value is uninitialized */" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalarUnsafe", ["VectorType"] = "Vector64", ["BaseType"] = "Int16", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "false /* value is uninitialized */" }),
("VectorCreateTest.template", new Dictionary<string, string> { ["Isa"] = "Vector64", ["Method"] = "CreateScalarUnsafe", ["VectorType"] = "Vector64", ["BaseType"] = "Int32", ["LargestVectorSize"] = "8", ["NextValueOp"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "resultElements[0] != expectedValue", ["ValidateRemainingResults"] = "false /* value is uninitialized */" }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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\General\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;

namespace JIT.HardwareIntrinsics.General
{
public static partial class Program
{
private static void CreateScalarDouble()
{
var test = new VectorCreate__CreateScalarDouble();

// Validates basic functionality works
test.RunBasicScenario();

// Validates calling via reflection works
test.RunReflectionScenario();

if (!test.Succeeded)
{
throw new Exception("One or more scenarios did not complete as expected.");
}
}
}

public sealed unsafe class VectorCreate__CreateScalarDouble
{
private static readonly int LargestVectorSize = 8;

private static readonly int ElementCount = Unsafe.SizeOf<Vector64<Double>>() / sizeof(Double);

public bool Succeeded { get; set; } = true;

public void RunBasicScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

Double value = TestLibrary.Generator.GetDouble();
Vector64<Double> result = Vector64.CreateScalar(value);

ValidateResult(result, value);
}

public void RunReflectionScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

Double value = TestLibrary.Generator.GetDouble();
object result = typeof(Vector64)
.GetMethod(nameof(Vector64.CreateScalar), new Type[] { typeof(Double) })
.Invoke(null, new object[] { value });

ValidateResult((Vector64<Double>)(result), value);
}

private void ValidateResult(Vector64<Double> result, Double expectedValue, [CallerMemberName] string method = "")
{
Double[] resultElements = new Double[ElementCount];
Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref resultElements[0]), result);
ValidateResult(resultElements, expectedValue, method);
}

private void ValidateResult(Double[] resultElements, Double expectedValue, [CallerMemberName] string method = "")
{
bool succeeded = true;

if (resultElements[0] != expectedValue)
{
succeeded = false;
}
else
{
for (var i = 1; i < ElementCount; i++)
{
if (resultElements[i] != 0)
{
succeeded = false;
break;
}
}
}

if (!succeeded)
{
TestLibrary.TestFramework.LogInformation($"Vector64.CreateScalar(Double): {method} failed:");
TestLibrary.TestFramework.LogInformation($" value: {expectedValue}");
TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", resultElements)})");
TestLibrary.TestFramework.LogInformation(string.Empty);

Succeeded = false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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\General\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;

namespace JIT.HardwareIntrinsics.General
{
public static partial class Program
{
private static void CreateScalarInt64()
{
var test = new VectorCreate__CreateScalarInt64();

// Validates basic functionality works
test.RunBasicScenario();

// Validates calling via reflection works
test.RunReflectionScenario();

if (!test.Succeeded)
{
throw new Exception("One or more scenarios did not complete as expected.");
}
}
}

public sealed unsafe class VectorCreate__CreateScalarInt64
{
private static readonly int LargestVectorSize = 8;

private static readonly int ElementCount = Unsafe.SizeOf<Vector64<Int64>>() / sizeof(Int64);

public bool Succeeded { get; set; } = true;

public void RunBasicScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

Int64 value = TestLibrary.Generator.GetInt64();
Vector64<Int64> result = Vector64.CreateScalar(value);

ValidateResult(result, value);
}

public void RunReflectionScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

Int64 value = TestLibrary.Generator.GetInt64();
object result = typeof(Vector64)
.GetMethod(nameof(Vector64.CreateScalar), new Type[] { typeof(Int64) })
.Invoke(null, new object[] { value });

ValidateResult((Vector64<Int64>)(result), value);
}

private void ValidateResult(Vector64<Int64> result, Int64 expectedValue, [CallerMemberName] string method = "")
{
Int64[] resultElements = new Int64[ElementCount];
Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref resultElements[0]), result);
ValidateResult(resultElements, expectedValue, method);
}

private void ValidateResult(Int64[] resultElements, Int64 expectedValue, [CallerMemberName] string method = "")
{
bool succeeded = true;

if (resultElements[0] != expectedValue)
{
succeeded = false;
}
else
{
for (var i = 1; i < ElementCount; i++)
{
if (resultElements[i] != 0)
{
succeeded = false;
break;
}
}
}

if (!succeeded)
{
TestLibrary.TestFramework.LogInformation($"Vector64.CreateScalar(Int64): {method} failed:");
TestLibrary.TestFramework.LogInformation($" value: {expectedValue}");
TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", resultElements)})");
TestLibrary.TestFramework.LogInformation(string.Empty);

Succeeded = false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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\General\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;

namespace JIT.HardwareIntrinsics.General
{
public static partial class Program
{
private static void CreateScalarUInt64()
{
var test = new VectorCreate__CreateScalarUInt64();

// Validates basic functionality works
test.RunBasicScenario();

// Validates calling via reflection works
test.RunReflectionScenario();

if (!test.Succeeded)
{
throw new Exception("One or more scenarios did not complete as expected.");
}
}
}

public sealed unsafe class VectorCreate__CreateScalarUInt64
{
private static readonly int LargestVectorSize = 8;

private static readonly int ElementCount = Unsafe.SizeOf<Vector64<UInt64>>() / sizeof(UInt64);

public bool Succeeded { get; set; } = true;

public void RunBasicScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

UInt64 value = TestLibrary.Generator.GetUInt64();
Vector64<UInt64> result = Vector64.CreateScalar(value);

ValidateResult(result, value);
}

public void RunReflectionScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

UInt64 value = TestLibrary.Generator.GetUInt64();
object result = typeof(Vector64)
.GetMethod(nameof(Vector64.CreateScalar), new Type[] { typeof(UInt64) })
.Invoke(null, new object[] { value });

ValidateResult((Vector64<UInt64>)(result), value);
}

private void ValidateResult(Vector64<UInt64> result, UInt64 expectedValue, [CallerMemberName] string method = "")
{
UInt64[] resultElements = new UInt64[ElementCount];
Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref resultElements[0]), result);
ValidateResult(resultElements, expectedValue, method);
}

private void ValidateResult(UInt64[] resultElements, UInt64 expectedValue, [CallerMemberName] string method = "")
{
bool succeeded = true;

if (resultElements[0] != expectedValue)
{
succeeded = false;
}
else
{
for (var i = 1; i < ElementCount; i++)
{
if (resultElements[i] != 0)
{
succeeded = false;
break;
}
}
}

if (!succeeded)
{
TestLibrary.TestFramework.LogInformation($"Vector64.CreateScalar(UInt64): {method} failed:");
TestLibrary.TestFramework.LogInformation($" value: {expectedValue}");
TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", resultElements)})");
TestLibrary.TestFramework.LogInformation(string.Empty);

Succeeded = false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ static Program()
["Create.UInt32"] = CreateUInt32,
["Create.UInt64"] = CreateUInt64,
["CreateScalar.Byte"] = CreateScalarByte,
["CreateScalar.Double"] = CreateScalarDouble,
["CreateScalar.Int16"] = CreateScalarInt16,
["CreateScalar.Int32"] = CreateScalarInt32,
["CreateScalar.Int64"] = CreateScalarInt64,
["CreateScalar.SByte"] = CreateScalarSByte,
["CreateScalar.Single"] = CreateScalarSingle,
["CreateScalar.UInt16"] = CreateScalarUInt16,
["CreateScalar.UInt32"] = CreateScalarUInt32,
["CreateScalar.UInt64"] = CreateScalarUInt64,
["CreateScalarUnsafe.Byte"] = CreateScalarUnsafeByte,
["CreateScalarUnsafe.Int16"] = CreateScalarUnsafeInt16,
["CreateScalarUnsafe.Int32"] = CreateScalarUnsafeInt32,
Expand Down
Loading

0 comments on commit ab119ad

Please sign in to comment.