From df651f2abe8711de81ffb4d7e0fddee36a298e70 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 6 Nov 2023 17:25:12 +0700 Subject: Create indirection layer for intrinsics support --- crypto/src/math/raw/Nat512.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'crypto/src/math/raw/Nat512.cs') diff --git a/crypto/src/math/raw/Nat512.cs b/crypto/src/math/raw/Nat512.cs index 56fa9a2c9..71b53214c 100644 --- a/crypto/src/math/raw/Nat512.cs +++ b/crypto/src/math/raw/Nat512.cs @@ -67,7 +67,8 @@ namespace Org.BouncyCastle.Math.Raw public static void Xor(ReadOnlySpan x, ReadOnlySpan y, Span z) { #if NETCOREAPP3_0_OR_GREATER - if (Avx2.IsSupported && Unsafe.SizeOf>() == 32) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Avx2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..16]); var Y = MemoryMarshal.AsBytes(y[..16]); @@ -87,7 +88,8 @@ namespace Org.BouncyCastle.Math.Raw return; } - if (Sse2.IsSupported && Unsafe.SizeOf>() == 16) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Sse2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..16]); var Y = MemoryMarshal.AsBytes(y[..16]); @@ -145,7 +147,8 @@ namespace Org.BouncyCastle.Math.Raw public static void XorTo(ReadOnlySpan x, Span z) { #if NETCOREAPP3_0_OR_GREATER - if (Avx2.IsSupported && Unsafe.SizeOf>() == 32) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Avx2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..16]); var Z = MemoryMarshal.AsBytes(z[..16]); @@ -164,7 +167,8 @@ namespace Org.BouncyCastle.Math.Raw return; } - if (Sse2.IsSupported && Unsafe.SizeOf>() == 16) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Sse2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..16]); var Z = MemoryMarshal.AsBytes(z[..16]); @@ -221,7 +225,8 @@ namespace Org.BouncyCastle.Math.Raw public static void Xor64(ReadOnlySpan x, ReadOnlySpan y, Span z) { #if NETCOREAPP3_0_OR_GREATER - if (Avx2.IsSupported && Unsafe.SizeOf>() == 32) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Avx2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..8]); var Y = MemoryMarshal.AsBytes(y[..8]); @@ -241,7 +246,8 @@ namespace Org.BouncyCastle.Math.Raw return; } - if (Sse2.IsSupported && Unsafe.SizeOf>() == 16) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Sse2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..8]); var Y = MemoryMarshal.AsBytes(y[..8]); @@ -299,7 +305,8 @@ namespace Org.BouncyCastle.Math.Raw public static void XorTo64(ReadOnlySpan x, Span z) { #if NETCOREAPP3_0_OR_GREATER - if (Avx2.IsSupported && Unsafe.SizeOf>() == 32) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Avx2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..8]); var Z = MemoryMarshal.AsBytes(z[..8]); @@ -318,7 +325,8 @@ namespace Org.BouncyCastle.Math.Raw return; } - if (Sse2.IsSupported && Unsafe.SizeOf>() == 16) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Sse2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPacked) { var X = MemoryMarshal.AsBytes(x[..8]); var Z = MemoryMarshal.AsBytes(z[..8]); -- cgit 1.4.1