Skip to content

Commit 554638d

Browse files
SIMD for Silk.NET.Math (#665)
* Working on simd proposal * WIP * sss * Store and Load * Create * Abs * With Get Element * Constants, retargeted back * Docs * Tiny revert * A few docs * Formatting and dce * And, Not, Xor, Or * AllBitsSet Relaxing type constraints for scalar bitwise operations * PR review 1. IsHardwareAccelerated added 2. Method Not simplified 3. A few docs * API listed * IsHardwareAccelerated fixed * With/Get Element replaced with BCL API * Ducks
1 parent 1ef2ac4 commit 554638d

Some content is hidden

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

50 files changed

+6037
-1052
lines changed
Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,105 @@
1-
#nullable enable
1+
#nullable enable
2+
Silk.NET.Maths.Simd128
3+
Silk.NET.Maths.Simd128<T>
4+
Silk.NET.Maths.Simd256
5+
Silk.NET.Maths.Simd256<T>
6+
Silk.NET.Maths.Simd64
7+
Silk.NET.Maths.Simd64<T>
8+
static readonly Silk.NET.Maths.Simd128<T>.AllBitsSet -> System.Runtime.Intrinsics.Vector128<T>
9+
static readonly Silk.NET.Maths.Simd128<T>.E -> System.Runtime.Intrinsics.Vector128<T>
10+
static readonly Silk.NET.Maths.Simd128<T>.Epsilon -> System.Runtime.Intrinsics.Vector128<T>
11+
static readonly Silk.NET.Maths.Simd128<T>.MaxValue -> System.Runtime.Intrinsics.Vector128<T>
12+
static readonly Silk.NET.Maths.Simd128<T>.MinusOne -> System.Runtime.Intrinsics.Vector128<T>
13+
static readonly Silk.NET.Maths.Simd128<T>.MinusTwo -> System.Runtime.Intrinsics.Vector128<T>
14+
static readonly Silk.NET.Maths.Simd128<T>.MinValue -> System.Runtime.Intrinsics.Vector128<T>
15+
static readonly Silk.NET.Maths.Simd128<T>.NaN -> System.Runtime.Intrinsics.Vector128<T>
16+
static readonly Silk.NET.Maths.Simd128<T>.NegativeInfinity -> System.Runtime.Intrinsics.Vector128<T>
17+
static readonly Silk.NET.Maths.Simd128<T>.One -> System.Runtime.Intrinsics.Vector128<T>
18+
static readonly Silk.NET.Maths.Simd128<T>.Pi -> System.Runtime.Intrinsics.Vector128<T>
19+
static readonly Silk.NET.Maths.Simd128<T>.PiOver2 -> System.Runtime.Intrinsics.Vector128<T>
20+
static readonly Silk.NET.Maths.Simd128<T>.PositiveInfinity -> System.Runtime.Intrinsics.Vector128<T>
21+
static readonly Silk.NET.Maths.Simd128<T>.Tau -> System.Runtime.Intrinsics.Vector128<T>
22+
static readonly Silk.NET.Maths.Simd128<T>.Two -> System.Runtime.Intrinsics.Vector128<T>
23+
static readonly Silk.NET.Maths.Simd128<T>.Zero -> System.Runtime.Intrinsics.Vector128<T>
24+
static readonly Silk.NET.Maths.Simd256<T>.AllBitsSet -> System.Runtime.Intrinsics.Vector256<T>
25+
static readonly Silk.NET.Maths.Simd256<T>.E -> System.Runtime.Intrinsics.Vector256<T>
26+
static readonly Silk.NET.Maths.Simd256<T>.Epsilon -> System.Runtime.Intrinsics.Vector256<T>
27+
static readonly Silk.NET.Maths.Simd256<T>.MaxValue -> System.Runtime.Intrinsics.Vector256<T>
28+
static readonly Silk.NET.Maths.Simd256<T>.MinusOne -> System.Runtime.Intrinsics.Vector256<T>
29+
static readonly Silk.NET.Maths.Simd256<T>.MinusTwo -> System.Runtime.Intrinsics.Vector256<T>
30+
static readonly Silk.NET.Maths.Simd256<T>.MinValue -> System.Runtime.Intrinsics.Vector256<T>
31+
static readonly Silk.NET.Maths.Simd256<T>.NaN -> System.Runtime.Intrinsics.Vector256<T>
32+
static readonly Silk.NET.Maths.Simd256<T>.NegativeInfinity -> System.Runtime.Intrinsics.Vector256<T>
33+
static readonly Silk.NET.Maths.Simd256<T>.One -> System.Runtime.Intrinsics.Vector256<T>
34+
static readonly Silk.NET.Maths.Simd256<T>.Pi -> System.Runtime.Intrinsics.Vector256<T>
35+
static readonly Silk.NET.Maths.Simd256<T>.PiOver2 -> System.Runtime.Intrinsics.Vector256<T>
36+
static readonly Silk.NET.Maths.Simd256<T>.PositiveInfinity -> System.Runtime.Intrinsics.Vector256<T>
37+
static readonly Silk.NET.Maths.Simd256<T>.Tau -> System.Runtime.Intrinsics.Vector256<T>
38+
static readonly Silk.NET.Maths.Simd256<T>.Two -> System.Runtime.Intrinsics.Vector256<T>
39+
static readonly Silk.NET.Maths.Simd256<T>.Zero -> System.Runtime.Intrinsics.Vector256<T>
40+
static readonly Silk.NET.Maths.Simd64<T>.AllBitsSet -> System.Runtime.Intrinsics.Vector64<T>
41+
static readonly Silk.NET.Maths.Simd64<T>.E -> System.Runtime.Intrinsics.Vector64<T>
42+
static readonly Silk.NET.Maths.Simd64<T>.Epsilon -> System.Runtime.Intrinsics.Vector64<T>
43+
static readonly Silk.NET.Maths.Simd64<T>.MaxValue -> System.Runtime.Intrinsics.Vector64<T>
44+
static readonly Silk.NET.Maths.Simd64<T>.MinusOne -> System.Runtime.Intrinsics.Vector64<T>
45+
static readonly Silk.NET.Maths.Simd64<T>.MinusTwo -> System.Runtime.Intrinsics.Vector64<T>
46+
static readonly Silk.NET.Maths.Simd64<T>.MinValue -> System.Runtime.Intrinsics.Vector64<T>
47+
static readonly Silk.NET.Maths.Simd64<T>.NaN -> System.Runtime.Intrinsics.Vector64<T>
48+
static readonly Silk.NET.Maths.Simd64<T>.NegativeInfinity -> System.Runtime.Intrinsics.Vector64<T>
49+
static readonly Silk.NET.Maths.Simd64<T>.One -> System.Runtime.Intrinsics.Vector64<T>
50+
static readonly Silk.NET.Maths.Simd64<T>.Pi -> System.Runtime.Intrinsics.Vector64<T>
51+
static readonly Silk.NET.Maths.Simd64<T>.PiOver2 -> System.Runtime.Intrinsics.Vector64<T>
52+
static readonly Silk.NET.Maths.Simd64<T>.PositiveInfinity -> System.Runtime.Intrinsics.Vector64<T>
53+
static readonly Silk.NET.Maths.Simd64<T>.Tau -> System.Runtime.Intrinsics.Vector64<T>
54+
static readonly Silk.NET.Maths.Simd64<T>.Two -> System.Runtime.Intrinsics.Vector64<T>
55+
static readonly Silk.NET.Maths.Simd64<T>.Zero -> System.Runtime.Intrinsics.Vector64<T>
56+
static Silk.NET.Maths.Scalar.And<T>(T left, T right) -> T
57+
static Silk.NET.Maths.Scalar.Not<T>(T value) -> T
58+
static Silk.NET.Maths.Scalar.Or<T>(T left, T right) -> T
59+
static Silk.NET.Maths.Scalar.RotateLeft<T>(T value, int offset) -> T
60+
static Silk.NET.Maths.Scalar.RotateRight<T>(T value, int offset) -> T
61+
static Silk.NET.Maths.Scalar.ShiftLeft<T>(T value, int offset) -> T
62+
static Silk.NET.Maths.Scalar.ShiftRight<T>(T value, int offset) -> T
63+
static Silk.NET.Maths.Scalar.Xor<T>(T left, T right) -> T
64+
static Silk.NET.Maths.Simd128.Abs<T>(System.Runtime.Intrinsics.Vector128<T> vector) -> System.Runtime.Intrinsics.Vector128<T>
65+
static Silk.NET.Maths.Simd128.Add<T>(System.Runtime.Intrinsics.Vector128<T> left, System.Runtime.Intrinsics.Vector128<T> right) -> System.Runtime.Intrinsics.Vector128<T>
66+
static Silk.NET.Maths.Simd128.And<T>(System.Runtime.Intrinsics.Vector128<T> left, System.Runtime.Intrinsics.Vector128<T> right) -> System.Runtime.Intrinsics.Vector128<T>
67+
static Silk.NET.Maths.Simd128.Create<T>(T value) -> System.Runtime.Intrinsics.Vector128<T>
68+
static Silk.NET.Maths.Simd128.Divide<T>(System.Runtime.Intrinsics.Vector128<T> left, System.Runtime.Intrinsics.Vector128<T> right) -> System.Runtime.Intrinsics.Vector128<T>
69+
static Silk.NET.Maths.Simd128.Load<T>(T* ptr) -> System.Runtime.Intrinsics.Vector128<T>
70+
static Silk.NET.Maths.Simd128.Multiply<T>(System.Runtime.Intrinsics.Vector128<T> left, System.Runtime.Intrinsics.Vector128<T> right) -> System.Runtime.Intrinsics.Vector128<T>
71+
static Silk.NET.Maths.Simd128.Not<T>(System.Runtime.Intrinsics.Vector128<T> vector) -> System.Runtime.Intrinsics.Vector128<T>
72+
static Silk.NET.Maths.Simd128.Or<T>(System.Runtime.Intrinsics.Vector128<T> left, System.Runtime.Intrinsics.Vector128<T> right) -> System.Runtime.Intrinsics.Vector128<T>
73+
static Silk.NET.Maths.Simd128.Store<T>(T* destination, System.Runtime.Intrinsics.Vector128<T> source) -> void
74+
static Silk.NET.Maths.Simd128.Subtract<T>(System.Runtime.Intrinsics.Vector128<T> left, System.Runtime.Intrinsics.Vector128<T> right) -> System.Runtime.Intrinsics.Vector128<T>
75+
static Silk.NET.Maths.Simd128.Xor<T>(System.Runtime.Intrinsics.Vector128<T> left, System.Runtime.Intrinsics.Vector128<T> right) -> System.Runtime.Intrinsics.Vector128<T>
76+
static Silk.NET.Maths.Simd128<T>.IsHardwareAccelerated.get -> bool
77+
static Silk.NET.Maths.Simd128<T>.IsSupported.get -> bool
78+
static Silk.NET.Maths.Simd256.Abs<T>(System.Runtime.Intrinsics.Vector256<T> vector) -> System.Runtime.Intrinsics.Vector256<T>
79+
static Silk.NET.Maths.Simd256.Add<T>(System.Runtime.Intrinsics.Vector256<T> left, System.Runtime.Intrinsics.Vector256<T> right) -> System.Runtime.Intrinsics.Vector256<T>
80+
static Silk.NET.Maths.Simd256.And<T>(System.Runtime.Intrinsics.Vector256<T> left, System.Runtime.Intrinsics.Vector256<T> right) -> System.Runtime.Intrinsics.Vector256<T>
81+
static Silk.NET.Maths.Simd256.Create<T>(T value) -> System.Runtime.Intrinsics.Vector256<T>
82+
static Silk.NET.Maths.Simd256.Divide<T>(System.Runtime.Intrinsics.Vector256<T> left, System.Runtime.Intrinsics.Vector256<T> right) -> System.Runtime.Intrinsics.Vector256<T>
83+
static Silk.NET.Maths.Simd256.Load<T>(T* ptr) -> System.Runtime.Intrinsics.Vector256<T>
84+
static Silk.NET.Maths.Simd256.Multiply<T>(System.Runtime.Intrinsics.Vector256<T> left, System.Runtime.Intrinsics.Vector256<T> right) -> System.Runtime.Intrinsics.Vector256<T>
85+
static Silk.NET.Maths.Simd256.Not<T>(System.Runtime.Intrinsics.Vector256<T> vector) -> System.Runtime.Intrinsics.Vector256<T>
86+
static Silk.NET.Maths.Simd256.Or<T>(System.Runtime.Intrinsics.Vector256<T> left, System.Runtime.Intrinsics.Vector256<T> right) -> System.Runtime.Intrinsics.Vector256<T>
87+
static Silk.NET.Maths.Simd256.Store<T>(T* destination, System.Runtime.Intrinsics.Vector256<T> source) -> void
88+
static Silk.NET.Maths.Simd256.Subtract<T>(System.Runtime.Intrinsics.Vector256<T> left, System.Runtime.Intrinsics.Vector256<T> right) -> System.Runtime.Intrinsics.Vector256<T>
89+
static Silk.NET.Maths.Simd256.Xor<T>(System.Runtime.Intrinsics.Vector256<T> left, System.Runtime.Intrinsics.Vector256<T> right) -> System.Runtime.Intrinsics.Vector256<T>
90+
static Silk.NET.Maths.Simd256<T>.IsHardwareAccelerated.get -> bool
91+
static Silk.NET.Maths.Simd256<T>.IsSupported.get -> bool
92+
static Silk.NET.Maths.Simd64.Abs<T>(System.Runtime.Intrinsics.Vector64<T> vector) -> System.Runtime.Intrinsics.Vector64<T>
93+
static Silk.NET.Maths.Simd64.Add<T>(System.Runtime.Intrinsics.Vector64<T> left, System.Runtime.Intrinsics.Vector64<T> right) -> System.Runtime.Intrinsics.Vector64<T>
94+
static Silk.NET.Maths.Simd64.And<T>(System.Runtime.Intrinsics.Vector64<T> left, System.Runtime.Intrinsics.Vector64<T> right) -> System.Runtime.Intrinsics.Vector64<T>
95+
static Silk.NET.Maths.Simd64.Create<T>(T value) -> System.Runtime.Intrinsics.Vector64<T>
96+
static Silk.NET.Maths.Simd64.Divide<T>(System.Runtime.Intrinsics.Vector64<T> left, System.Runtime.Intrinsics.Vector64<T> right) -> System.Runtime.Intrinsics.Vector64<T>
97+
static Silk.NET.Maths.Simd64.Load<T>(T* ptr) -> System.Runtime.Intrinsics.Vector64<T>
98+
static Silk.NET.Maths.Simd64.Multiply<T>(System.Runtime.Intrinsics.Vector64<T> left, System.Runtime.Intrinsics.Vector64<T> right) -> System.Runtime.Intrinsics.Vector64<T>
99+
static Silk.NET.Maths.Simd64.Not<T>(System.Runtime.Intrinsics.Vector64<T> vector) -> System.Runtime.Intrinsics.Vector64<T>
100+
static Silk.NET.Maths.Simd64.Or<T>(System.Runtime.Intrinsics.Vector64<T> left, System.Runtime.Intrinsics.Vector64<T> right) -> System.Runtime.Intrinsics.Vector64<T>
101+
static Silk.NET.Maths.Simd64.Store<T>(T* destination, System.Runtime.Intrinsics.Vector64<T> source) -> void
102+
static Silk.NET.Maths.Simd64.Subtract<T>(System.Runtime.Intrinsics.Vector64<T> left, System.Runtime.Intrinsics.Vector64<T> right) -> System.Runtime.Intrinsics.Vector64<T>
103+
static Silk.NET.Maths.Simd64.Xor<T>(System.Runtime.Intrinsics.Vector64<T> left, System.Runtime.Intrinsics.Vector64<T> right) -> System.Runtime.Intrinsics.Vector64<T>
104+
static Silk.NET.Maths.Simd64<T>.IsHardwareAccelerated.get -> bool
105+
static Silk.NET.Maths.Simd64<T>.IsSupported.get -> bool

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.And.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
9+
510

611
namespace Silk.NET.Maths
712
{
@@ -10,7 +15,7 @@ static partial class Scalar
1015
/// <summary>
1116
/// Performs And on supported types
1217
/// </summary>
13-
public static T And<T>(T left, T right) where T : unmanaged
18+
public static T And<T>(T left, T right)
1419
{
1520
return Byte(left, right);
1621

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.Not.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
59

610
namespace Silk.NET.Maths
711
{
@@ -10,7 +14,7 @@ static partial class Scalar
1014
/// <summary>
1115
/// Performs Not on supported types
1216
/// </summary>
13-
public static T Not<T>(T value) where T : unmanaged
17+
public static T Not<T>(T value)
1418
{
1519
return Byte(value);
1620

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.Or.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
59

610
namespace Silk.NET.Maths
711
{
@@ -10,7 +14,7 @@ static partial class Scalar
1014
/// <summary>
1115
/// Performs Or on supported types
1216
/// </summary>
13-
public static T Or<T>(T left, T right) where T : unmanaged
17+
public static T Or<T>(T left, T right)
1418
{
1519
return Byte(left, right);
1620

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.RotateLeft.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
59

610
namespace Silk.NET.Maths
711
{
@@ -11,7 +15,7 @@ static partial class Scalar
1115
/// Rotates a given value bitwise.
1216
/// Shifting float and double obeys unsigned integers' behaviour.
1317
/// </summary>
14-
public static T RotateLeft<T>(T value, int offset) where T : unmanaged
18+
public static T RotateLeft<T>(T value, int offset)
1519
{
1620
return Byte(value, offset);
1721

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.RotateRight.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
59

610
namespace Silk.NET.Maths
711
{
@@ -11,7 +15,7 @@ static partial class Scalar
1115
/// Rotates a given value bitwise.
1216
/// Shifting float and double obeys unsigned integers' behaviour.
1317
/// </summary>
14-
public static T RotateRight<T>(T value, int offset) where T : unmanaged
18+
public static T RotateRight<T>(T value, int offset)
1519
{
1620
return Byte(value, offset);
1721

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.ShiftLeft.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
59

610
namespace Silk.NET.Maths
711
{
@@ -10,7 +14,7 @@ static partial class Scalar
1014
/// <summary>
1115
/// Performs ShiftLeft on supported types
1216
/// </summary>
13-
public static T ShiftLeft<T>(T value, int offset) where T : unmanaged
17+
public static T ShiftLeft<T>(T value, int offset)
1418
{
1519
return Byte(value, offset);
1620

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.ShiftRight.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
59

610
namespace Silk.NET.Maths
711
{
@@ -10,7 +14,7 @@ static partial class Scalar
1014
/// <summary>
1115
/// Performs ShiftRight on supported types
1216
/// </summary>
13-
public static T ShiftRight<T>(T value, int offset) where T : unmanaged
17+
public static T ShiftRight<T>(T value, int offset)
1418
{
1519
return Byte(value, offset);
1620

src/Maths/Silk.NET.Maths/Scalar.Bitwise/Scalar.Xor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
// nullability-related things
6+
#pragma warning disable 8603
7+
#pragma warning disable 8605
8+
#pragma warning disable 8600
59

610
namespace Silk.NET.Maths
711
{
@@ -10,7 +14,7 @@ static partial class Scalar
1014
/// <summary>
1115
/// Performs Xor on supported types
1216
/// </summary>
13-
public static T Xor<T>(T left, T right) where T : unmanaged
17+
public static T Xor<T>(T left, T right)
1418
{
1519
return Byte(left, right);
1620

src/Maths/Silk.NET.Maths/Silk.NET.Maths.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<WarningsAsErrors>true</WarningsAsErrors>
99
<LangVersion>9.0</LangVersion>
1010

11-
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0'">$(DefineConstants);SSE</DefineConstants>
11+
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0'">$(DefineConstants);SSE;AVX;INTRINSICS</DefineConstants>
1212
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);BTEC_INTRINSICS;MATHF</DefineConstants>
1313
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0'">$(DefineConstants);POH;AdvSIMD</DefineConstants>
1414
<EnableNETAnalyzers>true</EnableNETAnalyzers>

0 commit comments

Comments
 (0)