Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Bitmap operations SIMD logic refactor #942

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.1" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Numerics.Tensors" Version="9.0.3" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions benchmark/BDN.benchmark/Bitmap/BitOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

namespace BDN.benchmark.Bitmap
{
public class BitOperations
{

}
}
67 changes: 67 additions & 0 deletions libs/common/Numerics/IBinaryOperator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Numerics;
using System.Runtime.Intrinsics;

namespace Garnet.common.Numerics
{
/// <summary>Operator that takes two input values and returns a single value.</summary>
public interface IBinaryOperator
{
/// <summary>
/// Computes the binary operation of two scalar values.
/// </summary>
static abstract T Invoke<T>(T x, T y) where T : IBinaryInteger<T>;

/// <summary>
/// Computes the binary operation of two vectors.
/// </summary>
static abstract Vector128<byte> Invoke(Vector128<byte> x, Vector128<byte> y);

/// <inheritdoc cref="Invoke(Vector128{byte}, Vector128{byte})"/>
static abstract Vector256<byte> Invoke(Vector256<byte> x, Vector256<byte> y);

/// <inheritdoc cref="Invoke(Vector128{byte}, Vector128{byte})"/>
static abstract Vector512<byte> Invoke(Vector512<byte> x, Vector512<byte> y);
}

/// <summary><c>x &amp; y</c></summary>
public readonly struct BitwiseAndOperator : IBinaryOperator
{
/// <inheritdoc/>
public static T Invoke<T>(T x, T y) where T : IBinaryInteger<T> => x & y;
/// <inheritdoc/>
public static Vector128<byte> Invoke(Vector128<byte> x, Vector128<byte> y) => x & y;
/// <inheritdoc/>
public static Vector256<byte> Invoke(Vector256<byte> x, Vector256<byte> y) => x & y;
/// <inheritdoc/>
public static Vector512<byte> Invoke(Vector512<byte> x, Vector512<byte> y) => x & y;
}

/// <summary><c>x | y</c></summary>
public readonly struct BitwiseOrOperator : IBinaryOperator
{
/// <inheritdoc/>
public static T Invoke<T>(T x, T y) where T : IBinaryInteger<T> => x | y;
/// <inheritdoc/>
public static Vector128<byte> Invoke(Vector128<byte> x, Vector128<byte> y) => x | y;
/// <inheritdoc/>
public static Vector256<byte> Invoke(Vector256<byte> x, Vector256<byte> y) => x | y;
/// <inheritdoc/>
public static Vector512<byte> Invoke(Vector512<byte> x, Vector512<byte> y) => x | y;
}

/// <summary><c>x ^ y</c></summary>
public readonly struct BitwiseXorOperator : IBinaryOperator
{
/// <inheritdoc/>
public static T Invoke<T>(T x, T y) where T : IBinaryInteger<T> => x ^ y;
/// <inheritdoc/>
public static Vector128<byte> Invoke(Vector128<byte> x, Vector128<byte> y) => x ^ y;
/// <inheritdoc/>
public static Vector256<byte> Invoke(Vector256<byte> x, Vector256<byte> y) => x ^ y;
/// <inheritdoc/>
public static Vector512<byte> Invoke(Vector512<byte> x, Vector512<byte> y) => x ^ y;
}
}
1 change: 1 addition & 0 deletions libs/server/Garnet.server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="System.Numerics.Tensors" />
<PackageReference Include="KeraLua" />
</ItemGroup>

Expand Down
Loading