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

Commit c127fa7

Browse files
tannergoodingjkotas
authored andcommitted
Organizing the tests/src/JIT/HardwareIntrinsics/X86 folder by ISA to make it more manageable. (#15617)
1 parent 8f9d5e0 commit c127fa7

File tree

22 files changed

+857
-436
lines changed

22 files changed

+857
-436
lines changed

tests/src/JIT/HardwareIntrinsics/X86/Add.cs

Lines changed: 0 additions & 428 deletions
This file was deleted.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
6+
using System;
7+
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
9+
using System.Runtime.Intrinsics.X86;
10+
using System.Runtime.Intrinsics;
11+
12+
namespace IntelHardwareIntrinsicTest
13+
{
14+
class Program
15+
{
16+
const int Pass = 100;
17+
const int Fail = 0;
18+
19+
static unsafe int Main(string[] args)
20+
{
21+
int testResult = Pass;
22+
23+
if (Avx.IsSupported)
24+
{
25+
using (TestTable<float> floatTable = new TestTable<float>(new float[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new float[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new float[8]))
26+
using (TestTable<double> doubleTable = new TestTable<double>(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4]))
27+
{
28+
var vf1 = Unsafe.Read<Vector256<float>>(floatTable.inArray1Ptr);
29+
var vf2 = Unsafe.Read<Vector256<float>>(floatTable.inArray2Ptr);
30+
var vf3 = Avx.Add(vf1, vf2);
31+
Unsafe.Write(floatTable.outArrayPtr, vf3);
32+
33+
var vd1 = Unsafe.Read<Vector256<double>>(doubleTable.inArray1Ptr);
34+
var vd2 = Unsafe.Read<Vector256<double>>(doubleTable.inArray2Ptr);
35+
var vd3 = Avx.Add(vd1, vd2);
36+
Unsafe.Write(doubleTable.outArrayPtr, vd3);
37+
38+
if (!floatTable.CheckResult((x, y, z) => x + y == z))
39+
{
40+
Console.WriteLine("AVX Add failed on float:");
41+
foreach (var item in floatTable.outArray)
42+
{
43+
Console.Write(item + ", ");
44+
}
45+
Console.WriteLine();
46+
testResult = Fail;
47+
}
48+
49+
if (!doubleTable.CheckResult((x, y, z) => x + y == z))
50+
{
51+
Console.WriteLine("AVX Add failed on double:");
52+
foreach (var item in doubleTable.outArray)
53+
{
54+
Console.Write(item + ", ");
55+
}
56+
Console.WriteLine();
57+
testResult = Fail;
58+
}
59+
}
60+
}
61+
62+
return testResult;
63+
}
64+
65+
public unsafe struct TestTable<T> : IDisposable where T : struct
66+
{
67+
public T[] inArray1;
68+
public T[] inArray2;
69+
public T[] outArray;
70+
71+
public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer();
72+
public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer();
73+
public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer();
74+
75+
GCHandle inHandle1;
76+
GCHandle inHandle2;
77+
GCHandle outHandle;
78+
public TestTable(T[] a, T[] b, T[] c)
79+
{
80+
this.inArray1 = a;
81+
this.inArray2 = b;
82+
this.outArray = c;
83+
84+
inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned);
85+
inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned);
86+
outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned);
87+
}
88+
public bool CheckResult(Func<T, T, T, bool> check)
89+
{
90+
for (int i = 0; i < inArray1.Length; i++)
91+
{
92+
if (!check(inArray1[i], inArray2[i], outArray[i]))
93+
{
94+
return false;
95+
}
96+
}
97+
return true;
98+
}
99+
100+
public void Dispose()
101+
{
102+
inHandle1.Free();
103+
inHandle2.Free();
104+
outHandle.Free();
105+
}
106+
}
107+
108+
}
109+
}

tests/src/JIT/HardwareIntrinsics/X86/Add_r.csproj renamed to tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_r.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
</ItemGroup>
3232
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
3333
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
34-
</Project>
34+
</Project>

tests/src/JIT/HardwareIntrinsics/X86/Add_ro.csproj renamed to tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_ro.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
</ItemGroup>
3232
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
3333
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
34-
</Project>
34+
</Project>
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
6+
using System;
7+
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
9+
using System.Runtime.Intrinsics.X86;
10+
using System.Runtime.Intrinsics;
11+
12+
namespace IntelHardwareIntrinsicTest
13+
{
14+
class Program
15+
{
16+
const int Pass = 100;
17+
const int Fail = 0;
18+
19+
static unsafe int Main(string[] args)
20+
{
21+
int testResult = Pass;
22+
23+
if (Avx2.IsSupported)
24+
{
25+
using (TestTable<int> intTable = new TestTable<int>(new int[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new int[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new int[8]))
26+
using (TestTable<long> longTable = new TestTable<long>(new long[4] { 1, -5, 100, 0 }, new long[4] { 22, -1, -50, 0 }, new long[4]))
27+
using (TestTable<uint> uintTable = new TestTable<uint>(new uint[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new uint[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new uint[8]))
28+
using (TestTable<ulong> ulongTable = new TestTable<ulong>(new ulong[4] { 1, 5, 100, 0 }, new ulong[4] { 22, 1, 50, 0 }, new ulong[4]))
29+
using (TestTable<short> shortTable = new TestTable<short>(new short[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new short[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new short[16]))
30+
using (TestTable<ushort> ushortTable = new TestTable<ushort>(new ushort[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[16]))
31+
using (TestTable<sbyte> sbyteTable = new TestTable<sbyte>(new sbyte[32] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[32] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[32]))
32+
using (TestTable<byte> byteTable = new TestTable<byte>(new byte[32] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[32] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[32]))
33+
{
34+
35+
var vi1 = Unsafe.Read<Vector256<int>>(intTable.inArray1Ptr);
36+
var vi2 = Unsafe.Read<Vector256<int>>(intTable.inArray2Ptr);
37+
var vi3 = Avx2.Add(vi1, vi2);
38+
Unsafe.Write(intTable.outArrayPtr, vi3);
39+
40+
var vl1 = Unsafe.Read<Vector256<long>>(longTable.inArray1Ptr);
41+
var vl2 = Unsafe.Read<Vector256<long>>(longTable.inArray2Ptr);
42+
var vl3 = Avx2.Add(vl1, vl2);
43+
Unsafe.Write(longTable.outArrayPtr, vl3);
44+
45+
var vui1 = Unsafe.Read<Vector256<uint>>(uintTable.inArray1Ptr);
46+
var vui2 = Unsafe.Read<Vector256<uint>>(uintTable.inArray2Ptr);
47+
var vui3 = Avx2.Add(vui1, vui2);
48+
Unsafe.Write(uintTable.outArrayPtr, vui3);
49+
50+
var vul1 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray1Ptr);
51+
var vul2 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray2Ptr);
52+
var vul3 = Avx2.Add(vul1, vul2);
53+
Unsafe.Write(ulongTable.outArrayPtr, vul3);
54+
55+
var vs1 = Unsafe.Read<Vector256<short>>(shortTable.inArray1Ptr);
56+
var vs2 = Unsafe.Read<Vector256<short>>(shortTable.inArray2Ptr);
57+
var vs3 = Avx2.Add(vs1, vs2);
58+
Unsafe.Write(shortTable.outArrayPtr, vs3);
59+
60+
var vus1 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray1Ptr);
61+
var vus2 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray2Ptr);
62+
var vus3 = Avx2.Add(vus1, vus2);
63+
Unsafe.Write(ushortTable.outArrayPtr, vus3);
64+
65+
var vsb1 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray1Ptr);
66+
var vsb2 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray2Ptr);
67+
var vsb3 = Avx2.Add(vsb1, vsb2);
68+
Unsafe.Write(sbyteTable.outArrayPtr, vsb3);
69+
70+
var vb1 = Unsafe.Read<Vector256<byte>>(byteTable.inArray1Ptr);
71+
var vb2 = Unsafe.Read<Vector256<byte>>(byteTable.inArray2Ptr);
72+
var vb3 = Avx2.Add(vb1, vb2);
73+
Unsafe.Write(byteTable.outArrayPtr, vb3);
74+
75+
if (!intTable.CheckResult((x, y, z) => x + y == z))
76+
{
77+
Console.WriteLine("AVX2 Add failed on int:");
78+
foreach (var item in intTable.outArray)
79+
{
80+
Console.Write(item + ", ");
81+
}
82+
Console.WriteLine();
83+
testResult = Fail;
84+
}
85+
86+
if (!longTable.CheckResult((x, y, z) => x + y == z))
87+
{
88+
Console.WriteLine("AVX2 Add failed on long:");
89+
foreach (var item in longTable.outArray)
90+
{
91+
Console.Write(item + ", ");
92+
}
93+
Console.WriteLine();
94+
testResult = Fail;
95+
}
96+
97+
if (!uintTable.CheckResult((x, y, z) => x + y == z))
98+
{
99+
Console.WriteLine("AVX2 Add failed on uint:");
100+
foreach (var item in uintTable.outArray)
101+
{
102+
Console.Write(item + ", ");
103+
}
104+
Console.WriteLine();
105+
testResult = Fail;
106+
}
107+
108+
if (!ulongTable.CheckResult((x, y, z) => x + y == z))
109+
{
110+
Console.WriteLine("AVX2 Add failed on ulong:");
111+
foreach (var item in ulongTable.outArray)
112+
{
113+
Console.Write(item + ", ");
114+
}
115+
Console.WriteLine();
116+
testResult = Fail;
117+
}
118+
119+
if (!shortTable.CheckResult((x, y, z) => x + y == z))
120+
{
121+
Console.WriteLine("AVX2 Add failed on short:");
122+
foreach (var item in shortTable.outArray)
123+
{
124+
Console.Write(item + ", ");
125+
}
126+
Console.WriteLine();
127+
testResult = Fail;
128+
}
129+
130+
if (!ushortTable.CheckResult((x, y, z) => x + y == z))
131+
{
132+
Console.WriteLine("AVX2 Add failed on ushort:");
133+
foreach (var item in ushortTable.outArray)
134+
{
135+
Console.Write(item + ", ");
136+
}
137+
Console.WriteLine();
138+
testResult = Fail;
139+
}
140+
141+
if (!sbyteTable.CheckResult((x, y, z) => x + y == z))
142+
{
143+
Console.WriteLine("AVX2 Add failed on sbyte:");
144+
foreach (var item in sbyteTable.outArray)
145+
{
146+
Console.Write(item + ", ");
147+
}
148+
Console.WriteLine();
149+
testResult = Fail;
150+
}
151+
152+
if (!byteTable.CheckResult((x, y, z) => x + y == z))
153+
{
154+
Console.WriteLine("AVX2 Add failed on byte:");
155+
foreach (var item in byteTable.outArray)
156+
{
157+
Console.Write(item + ", ");
158+
}
159+
Console.WriteLine();
160+
testResult = Fail;
161+
}
162+
}
163+
164+
}
165+
166+
return testResult;
167+
}
168+
169+
public unsafe struct TestTable<T> : IDisposable where T : struct
170+
{
171+
public T[] inArray1;
172+
public T[] inArray2;
173+
public T[] outArray;
174+
175+
public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer();
176+
public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer();
177+
public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer();
178+
179+
GCHandle inHandle1;
180+
GCHandle inHandle2;
181+
GCHandle outHandle;
182+
public TestTable(T[] a, T[] b, T[] c)
183+
{
184+
this.inArray1 = a;
185+
this.inArray2 = b;
186+
this.outArray = c;
187+
188+
inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned);
189+
inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned);
190+
outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned);
191+
}
192+
public bool CheckResult(Func<T, T, T, bool> check)
193+
{
194+
for (int i = 0; i < inArray1.Length; i++)
195+
{
196+
if (!check(inArray1[i], inArray2[i], outArray[i]))
197+
{
198+
return false;
199+
}
200+
}
201+
return true;
202+
}
203+
204+
public void Dispose()
205+
{
206+
inHandle1.Free();
207+
inHandle2.Free();
208+
outHandle.Free();
209+
}
210+
}
211+
212+
}
213+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
12+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13+
</PropertyGroup>
14+
<!-- Default configurations to help VS understand the configurations -->
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
17+
<ItemGroup>
18+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
19+
<Visible>False</Visible>
20+
</CodeAnalysisDependentAssemblyPaths>
21+
</ItemGroup>
22+
<PropertyGroup>
23+
<DebugType>None</DebugType>
24+
<Optimize></Optimize>
25+
</PropertyGroup>
26+
<ItemGroup>
27+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<Compile Include="Add.cs" />
31+
</ItemGroup>
32+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
33+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
34+
</Project>

0 commit comments

Comments
 (0)