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 2 commits into
base: main
Choose a base branch
from
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions libs/common/Numerics/TensorPrimitives.IBinaryOperator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;

namespace Garnet.common.Numerics
{
public static unsafe partial class TensorPrimitives
{
/// <summary>x &amp; y</summary>
public readonly struct BitwiseAndOperator<T> : IBinaryOperator<T> where T : IBitwiseOperators<T, T, T>
{
public static T Invoke(T x, T y) => x & y;
public static Vector128<T> Invoke(Vector128<T> x, Vector128<T> y) => x & y;
public static Vector256<T> Invoke(Vector256<T> x, Vector256<T> y) => x & y;
public static Vector512<T> Invoke(Vector512<T> x, Vector512<T> y) => x & y;
}

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

/// <summary>x ^ y</summary>
public readonly struct BitwiseXorOperator<T> : IBinaryOperator<T> where T : IBitwiseOperators<T, T, T>
{
public static T Invoke(T x, T y) => x ^ y;
public static Vector128<T> Invoke(Vector128<T> x, Vector128<T> y) => x ^ y;
public static Vector256<T> Invoke(Vector256<T> x, Vector256<T> y) => x ^ y;
public static Vector512<T> Invoke(Vector512<T> x, Vector512<T> y) => x ^ y;
}

/// <summary>Operator that takes two input values and returns a single value.</summary>
public interface IBinaryOperator<T>
{
static abstract T Invoke(T x, T y);
static abstract Vector128<T> Invoke(Vector128<T> x, Vector128<T> y);
static abstract Vector256<T> Invoke(Vector256<T> x, Vector256<T> y);
static abstract Vector512<T> Invoke(Vector512<T> x, Vector512<T> y);
}
}
}
Loading
Loading