Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Replacing usages of random with TestLibrary.Generator in the HWIntrinsic templated tests #19062

Merged
merged 6 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
74 changes: 74 additions & 0 deletions tests/src/Common/CoreCLRTestLibrary/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ public static Int64 GetInt64()
return iVal;
}

// returns a UInt64 between 0 and UInt64.MaxValue
public static UInt64 GetUInt64(Int32 new_seed)
{
Seed = new_seed;
return GetUInt64();
}
public static UInt64 GetUInt64()
{
byte[] buffer = new byte[8];
UInt64 iVal;

GetBytes(buffer);

// convert to UInt64
iVal = 0;
for (int i = 0; i < buffer.Length; i++)
{
iVal |= ((UInt64)buffer[i] << (i * 8));
}

TestFramework.LogVerbose("Random UInt64 produced: " + iVal.ToString());
return iVal;
}

// returns a non-negative Int32 between 0 and Int32.MaxValue
public static Int32 GetInt32(Int32 new_seed)
{
Expand All @@ -99,6 +123,30 @@ public static Int32 GetInt32()
return i;
}

// returns a UInt32 between 0 and UInt32.MaxValue
public static UInt32 GetUInt32(Int32 new_seed)
{
Seed = new_seed;
return GetUInt32();
}
public static UInt32 GetUInt32()
{
byte[] buffer = new byte[4];
UInt32 iVal;

GetBytes(buffer);

// convert to UInt32
iVal = 0;
for (int i = 0; i < buffer.Length; i++)
{
iVal |= ((UInt32)buffer[i] << (i * 4));
}

TestFramework.LogVerbose("Random UInt32 produced: " + iVal.ToString());
return iVal;
}

// returns a non-negative Int16 between 0 and Int16.MaxValue
public static Int16 GetInt16(Int32 new_seed)
{
Expand All @@ -112,6 +160,19 @@ public static Int16 GetInt16()
return i;
}

// returns a UInt16 between 0 and UInt16.MaxValue
public static UInt16 GetUInt16(Int32 new_seed)
{
Seed = new_seed;
return GetUInt16();
}
public static UInt16 GetUInt16()
{
UInt16 i = Convert.ToUInt16(m_rand.Next() % (1 + UInt16.MaxValue));
TestFramework.LogVerbose("Random UInt16 produced: " + i.ToString());
return i;
}

// returns a non-negative Byte between 0 and Byte.MaxValue
public static Byte GetByte(Int32 new_seed)
{
Expand All @@ -125,6 +186,19 @@ public static Byte GetByte()
return i;
}

// returns a non-negative SByte between 0 and SByte.MaxValue
public static SByte GetSByte(Int32 new_seed)
{
Seed = new_seed;
return GetSByte();
}
public static SByte GetSByte()
{
SByte i = Convert.ToSByte(m_rand.Next() % (1 + SByte.MaxValue));
TestFramework.LogVerbose("Random SByte produced: " + i.ToString());
return i;
}

// returns a non-negative Double between 0.0 and 1.0
public static Double GetDouble(Int32 new_seed)
{
Expand Down
5 changes: 0 additions & 5 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AddDouble testClass)

static SimpleBinaryOpTest__AddDouble()
{
var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AddDouble()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand Down
5 changes: 0 additions & 5 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AddSingle testClass)

static SimpleBinaryOpTest__AddSingle()
{
var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AddSingle()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AddSubtractDouble testClass

static SimpleBinaryOpTest__AddSubtractDouble()
{
var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AddSubtractDouble()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AddSubtractSingle testClass

static SimpleBinaryOpTest__AddSubtractSingle()
{
var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AddSubtractSingle()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand Down
5 changes: 0 additions & 5 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/And.Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AndDouble testClass)

static SimpleBinaryOpTest__AndDouble()
{
var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AndDouble()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand Down
5 changes: 0 additions & 5 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/And.Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AndSingle testClass)

static SimpleBinaryOpTest__AndSingle()
{
var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AndSingle()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand Down
5 changes: 0 additions & 5 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/AndNot.Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AndNotDouble testClass)

static SimpleBinaryOpTest__AndNotDouble()
{
var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AndNotDouble()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand Down
5 changes: 0 additions & 5 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/AndNot.Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -137,8 +136,6 @@ public void RunStructFldScenario(SimpleBinaryOpTest__AndNotSingle testClass)

static SimpleBinaryOpTest__AndNotSingle()
{
var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand All @@ -149,8 +146,6 @@ public SimpleBinaryOpTest__AndNotSingle()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetSingle(); }
Expand Down
3 changes: 0 additions & 3 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/Avx_r.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@
<Compile Include="..\Shared\SimpleTernOpTest_DataTable.cs" />
<Compile Include="..\Shared\SimpleUnOpTest_DataTable.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
</Project>
3 changes: 0 additions & 3 deletions tests/src/JIT/HardwareIntrinsics/X86/Avx/Avx_ro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@
<Compile Include="..\Shared\SimpleTernOpTest_DataTable.cs" />
<Compile Include="..\Shared\SimpleUnOpTest_DataTable.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ private struct TestStruct
public static TestStruct Create()
{
var testStruct = new TestStruct();
var random = new Random();

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>>());
Expand Down Expand Up @@ -144,8 +143,6 @@ public void RunStructFldScenario(SimpleTernaryOpTest__BlendVariableDouble testCl

static SimpleTernaryOpTest__BlendVariableDouble()
{
var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand All @@ -158,8 +155,6 @@ public SimpleTernaryOpTest__BlendVariableDouble()
{
Succeeded = true;

var random = new Random();

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] = TestLibrary.Generator.GetDouble(); }
Expand Down
Loading