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

Commit 85d9900

Browse files
committed
Add tests for AVX/AVX2 intrinsics
1 parent ed49bad commit 85d9900

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+12681
-0
lines changed

tests/src/JIT/HardwareIntrinsics/X86/Avx/Avx_r.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
<Compile Include="Permute.Double.1.cs" />
131131
<Compile Include="Permute.Single.2.cs" />
132132
<Compile Include="Permute.Double.2.cs" />
133+
<Compile Include="PermuteVar.Single.cs" />
134+
<Compile Include="PermuteVar.Double.cs" />
133135
<Compile Include="RoundCurrentDirection.Double.cs" />
134136
<Compile Include="RoundCurrentDirection.Single.cs" />
135137
<Compile Include="RoundToNearestInteger.Double.cs" />

tests/src/JIT/HardwareIntrinsics/X86/Avx/Avx_ro.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
<Compile Include="Permute.Double.1.cs" />
131131
<Compile Include="Permute.Single.2.cs" />
132132
<Compile Include="Permute.Double.2.cs" />
133+
<Compile Include="PermuteVar.Single.cs" />
134+
<Compile Include="PermuteVar.Double.cs" />
133135
<Compile Include="RoundCurrentDirection.Double.cs" />
134136
<Compile Include="RoundCurrentDirection.Single.cs" />
135137
<Compile Include="RoundToNearestInteger.Double.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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, 2, 3, 4 }, new float[8]))
26+
{
27+
var vf = Avx.BroadcastVector128ToVector256((float*)(floatTable.inArrayPtr));
28+
Unsafe.Write(floatTable.outArrayPtr, vf);
29+
30+
if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y)))
31+
{
32+
Console.WriteLine("AVX BroadcastVector128ToVector256 failed on float:");
33+
foreach (var item in floatTable.outArray)
34+
{
35+
Console.Write(item + ", ");
36+
}
37+
Console.WriteLine();
38+
testResult = Fail;
39+
}
40+
}
41+
42+
using (TestTable<double> doubleTable = new TestTable<double>(new double[4] { 1, -5, 100, 0}, new double[4]))
43+
{
44+
var vf = Avx.BroadcastVector128ToVector256((double*)(doubleTable.inArrayPtr));
45+
Unsafe.Write(doubleTable.outArrayPtr, vf);
46+
47+
if (!doubleTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y)))
48+
{
49+
Console.WriteLine("AVX BroadcastVector128ToVector256 failed on double:");
50+
foreach (var item in doubleTable.outArray)
51+
{
52+
Console.Write(item + ", ");
53+
}
54+
Console.WriteLine();
55+
testResult = Fail;
56+
}
57+
}
58+
}
59+
return testResult;
60+
}
61+
62+
public unsafe struct TestTable<T> : IDisposable where T : struct
63+
{
64+
public T[] inArray;
65+
public T[] outArray;
66+
67+
public void* inArrayPtr => inHandle.AddrOfPinnedObject().ToPointer();
68+
public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer();
69+
70+
GCHandle inHandle;
71+
GCHandle outHandle;
72+
public TestTable(T[] a, T[] b)
73+
{
74+
this.inArray = a;
75+
this.outArray = b;
76+
77+
inHandle = GCHandle.Alloc(inArray, GCHandleType.Pinned);
78+
outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned);
79+
}
80+
public bool CheckResult(Func<T, T, bool> check)
81+
{
82+
for (int i = 0; i < outArray.Length/2; i++)
83+
{
84+
if (!check(inArray[i], outArray[i]))
85+
{
86+
return false;
87+
}
88+
}
89+
for (int i = outArray.Length/2; i < outArray.Length; i++)
90+
{
91+
if (!check(inArray[i - outArray.Length/2], outArray[i]))
92+
{
93+
return false;
94+
}
95+
}
96+
return true;
97+
}
98+
99+
public void Dispose()
100+
{
101+
inHandle.Free();
102+
outHandle.Free();
103+
}
104+
}
105+
106+
}
107+
}
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="BroadcastVector128ToVector256.cs" />
31+
</ItemGroup>
32+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
33+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
34+
</Project>
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>True</Optimize>
25+
</PropertyGroup>
26+
<ItemGroup>
27+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<Compile Include="BroadcastVector128ToVector256.cs" />
31+
</ItemGroup>
32+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
33+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
34+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 }))
26+
{
27+
28+
var vf1 = Unsafe.Read<Vector256<float>>(floatTable.inArray1Ptr);
29+
var res = Avx.MoveMask(vf1);
30+
31+
if (res != 0b00100010)
32+
{
33+
Console.WriteLine("Avx MoveMask failed on float:");
34+
Console.WriteLine(res);
35+
testResult = Fail;
36+
}
37+
}
38+
39+
using (TestTable<double> doubleTable = new TestTable<double>(new double[4] { 1, -5, 1, -5 }))
40+
{
41+
42+
var vf1 = Unsafe.Read<Vector256<double>>(doubleTable.inArray1Ptr);
43+
var res = Avx.MoveMask(vf1);
44+
45+
if (res != 0b1010)
46+
{
47+
Console.WriteLine("Avx MoveMask failed on double:");
48+
Console.WriteLine(res);
49+
testResult = Fail;
50+
}
51+
}
52+
}
53+
54+
55+
return testResult;
56+
}
57+
58+
public unsafe struct TestTable<T> : IDisposable where T : struct
59+
{
60+
public T[] inArray1;
61+
public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer();
62+
GCHandle inHandle1;
63+
64+
public TestTable(T[] a)
65+
{
66+
this.inArray1 = a;
67+
inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned);
68+
}
69+
70+
public void Dispose()
71+
{
72+
inHandle1.Free();
73+
}
74+
}
75+
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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>{EC7AD883-41EA-4BDC-BFBE-77A78B727D76}</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' ">
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
18+
<ItemGroup>
19+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
20+
<Visible>False</Visible>
21+
</CodeAnalysisDependentAssemblyPaths>
22+
</ItemGroup>
23+
<PropertyGroup>
24+
<DebugType>None</DebugType>
25+
<Optimize>True</Optimize>
26+
</PropertyGroup>
27+
<ItemGroup>
28+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
29+
</ItemGroup>
30+
<ItemGroup>
31+
<Compile Include="MoveMask.cs" />
32+
</ItemGroup>
33+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
34+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
35+
</PropertyGroup>
36+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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>{4D4CC0B8-3894-4F6F-868B-C93A7B722B5C}</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' ">
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
18+
<ItemGroup>
19+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
20+
<Visible>False</Visible>
21+
</CodeAnalysisDependentAssemblyPaths>
22+
</ItemGroup>
23+
<PropertyGroup>
24+
<DebugType>None</DebugType>
25+
<Optimize>True</Optimize>
26+
</PropertyGroup>
27+
<ItemGroup>
28+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
29+
</ItemGroup>
30+
<ItemGroup>
31+
<Compile Include="MoveMask.cs" />
32+
</ItemGroup>
33+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
34+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
35+
</PropertyGroup>
36+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
using System;
6+
using System.Collections.Generic;
7+
8+
namespace JIT.HardwareIntrinsics.X86
9+
{
10+
public static partial class Program
11+
{
12+
static Program()
13+
{
14+
TestList = new Dictionary<string, Action>() {
15+
["Permute2x128.Double.2"] = Permute2x128Double2,
16+
["Permute2x128.Single.2"] = Permute2x128Single2,
17+
["Permute2x128.Int32.2"] = Permute2x128Int322,
18+
["Permute2x128.UInt32.2"] = Permute2x128Int322,
19+
["Permute2x128.Int64.2"] = Permute2x128Int642,
20+
["Permute2x128.UInt64.2"] = Permute2x128UInt642,
21+
};
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)