-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime.Intrinsicsin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Background and motivation
GFNI is supported by Intel in the Ice Lake and newer architectures, and by AMD in Zen 4.
These instructions are known to be useful for cryptography and bit manipulations.
An efficient bit-reversal can be implemented with it.
API Proposal
namespace System.Runtime.Intrinsics.X86;
public abstract class Gfni : Sse41
{
public static bool IsSupported { get; }
public static Vector128<byte> GaloisFieldAffineTransformInverse(Vector128<byte> x, Vector128<byte> a, [ConstantExpected] byte b);
public static Vector128<byte> GaloisFieldAffineTransform(Vector128<byte> x, Vector128<byte> a, [ConstantExpected] byte b);
public static Vector128<byte> GaloisFieldMultiply(Vector128<byte> left, Vector128<byte> right);
public abstract class X64 : Sse41.X64
{
public static bool IsSupported { get; }
}
public abstract class V256
{
public static new bool IsSupported { get; }
public static Vector256<byte> GaloisFieldAffineTransformInverse(Vector256<byte> x, Vector256<byte> a, [ConstantExpected] byte b);
public static Vector256<byte> GaloisFieldAffineTransform(Vector256<byte> x, Vector256<byte> a, [ConstantExpected] byte b);
public static Vector256<byte> GaloisFieldMultiply(Vector256<byte> left, Vector256<byte> right);
}
public abstract class V512
{
public static new bool IsSupported { get; }
public static Vector512<byte> GaloisFieldAffineTransformInverse(Vector512<byte> x, Vector512<byte> a, [ConstantExpected] byte b);
public static Vector512<byte> GaloisFieldAffineTransform(Vector512<byte> x, Vector512<byte> a, [ConstantExpected] byte b);
public static Vector512<byte> GaloisFieldMultiply(Vector512<byte> left, Vector512<byte> right);
}
}API Usage
// https://wunkolo.github.io/post/2020/11/gf2p8affineqb-bit-reversal/
public static Vector128<byte> ReverseBits128(Vector128<byte> value)
{
var xmm0 = Gfni.GaloisFieldAffineTransform(value, Vector128.Create(0b10000000_01000000_00100000_00010000_00001000_00000100_00000010_00000001ul).AsByte(), 0);
return Ssse3.Shuffle(xmm0, Vector128.Create(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, byte.MinValue));
}Alternative Designs
No response
Risks
No response
MichalPetryka, PaulusParssinen, saucecontrol, rducom and julealgon
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime.Intrinsicsin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged