From e7e9f9582ddb183cba23efd1e8a05e2a8110304e Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Wed, 10 Jan 2024 16:23:51 -0500 Subject: [PATCH 1/6] [libs] Skip AdvSimdEncode on Mono --- .../src/System/Buffers/Text/Base64Encoder.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs index 9c28f57038a306..805e32c62e16fd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs @@ -493,6 +493,9 @@ private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, b [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart) { +#if MONO + return; +#else // C# implementatino of https://github.com/aklomp/base64/blob/3a5add8652076612a8407627a42c768736a4263f/lib/arch/neon64/enc_loop.c Vector128 str1; Vector128 str2; @@ -545,6 +548,7 @@ private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes srcBytes = src; destBytes = dest; +#endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] From 7dbdc18f0c82a9af22ad944af05018233a16400a Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Thu, 11 Jan 2024 09:46:08 -0500 Subject: [PATCH 2/6] Add guard around existing AdvSimdEncode callsite to exclude on Mono --- .../src/System/Buffers/Text/Base64Encoder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs index 805e32c62e16fd..adfaf6417ec382 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs @@ -84,7 +84,7 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span if (src == srcEnd) goto DoneExit; } - +#if !MONO end = srcMax - 48; if (AdvSimd.Arm64.IsSupported && (end >= src)) { @@ -93,7 +93,7 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span if (src == srcEnd) goto DoneExit; } - +#endif end = srcMax - 16; if ((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian && (end >= src)) { From b9556d0c6d0d28b520fe512c16d1eb27e3095859 Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Thu, 11 Jan 2024 10:59:10 -0500 Subject: [PATCH 3/6] Add issue to guard --- .../src/System/Buffers/Text/Base64Encoder.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs index adfaf6417ec382..27e5e62a25aff0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs @@ -84,7 +84,7 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span if (src == srcEnd) goto DoneExit; } -#if !MONO + end = srcMax - 48; if (AdvSimd.Arm64.IsSupported && (end >= src)) { @@ -93,7 +93,7 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span if (src == srcEnd) goto DoneExit; } -#endif + end = srcMax - 16; if ((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian && (end >= src)) { @@ -493,9 +493,9 @@ private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, b [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart) { -#if MONO +#if MONO // https://github.com/dotnet/runtime/issues/96828 return; -#else +#endif // C# implementatino of https://github.com/aklomp/base64/blob/3a5add8652076612a8407627a42c768736a4263f/lib/arch/neon64/enc_loop.c Vector128 str1; Vector128 str2; @@ -548,7 +548,6 @@ private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes srcBytes = src; destBytes = dest; -#endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] From a49d8b030b268fc017c8d0b68561cf2b31a5cf3f Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Thu, 11 Jan 2024 11:33:39 -0500 Subject: [PATCH 4/6] Guard AdvSimdEncode logic for not Mono --- .../src/System/Buffers/Text/Base64Encoder.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs index 27e5e62a25aff0..bc61b4a4f4cef5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs @@ -493,9 +493,7 @@ private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, b [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart) { -#if MONO // https://github.com/dotnet/runtime/issues/96828 - return; -#endif +#if !MONO // https://github.com/dotnet/runtime/issues/96828 // C# implementatino of https://github.com/aklomp/base64/blob/3a5add8652076612a8407627a42c768736a4263f/lib/arch/neon64/enc_loop.c Vector128 str1; Vector128 str2; @@ -548,6 +546,7 @@ private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes srcBytes = src; destBytes = dest; +#endif // !MONO } [MethodImpl(MethodImplOptions.AggressiveInlining)] From 05c6acb937ee94479d0cc655d9237aeffc5293da Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Thu, 11 Jan 2024 15:29:04 -0500 Subject: [PATCH 5/6] Make AdvSimdEncode inaccessible on Mono --- .../src/System/Buffers/Text/Base64Encoder.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs index bc61b4a4f4cef5..68925e6ae32e08 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs @@ -85,6 +85,7 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span goto DoneExit; } +#if !MONO // https://github.com/dotnet/runtime/issues/96828 end = srcMax - 48; if (AdvSimd.Arm64.IsSupported && (end >= src)) { @@ -93,6 +94,7 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span if (src == srcEnd) goto DoneExit; } +#endif end = srcMax - 16; if ((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian && (end >= src)) @@ -489,11 +491,11 @@ private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, b destBytes = dest; } +#if !MONO // https://github.com/dotnet/runtime/issues/96828 [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart) { -#if !MONO // https://github.com/dotnet/runtime/issues/96828 // C# implementatino of https://github.com/aklomp/base64/blob/3a5add8652076612a8407627a42c768736a4263f/lib/arch/neon64/enc_loop.c Vector128 str1; Vector128 str2; @@ -546,8 +548,8 @@ private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes srcBytes = src; destBytes = dest; -#endif // !MONO } +#endif // !MONO [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(Ssse3))] From 8ab79aada0d88c8f1f048a6a1ee81fca0507908c Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Thu, 11 Jan 2024 15:41:47 -0500 Subject: [PATCH 6/6] Update issue comment --- .../src/System/Buffers/Text/Base64Encoder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs index 68925e6ae32e08..d669d11b8b58b8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs @@ -85,7 +85,7 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span goto DoneExit; } -#if !MONO // https://github.com/dotnet/runtime/issues/96828 +#if !MONO // https://github.com/dotnet/runtime/issues/93081 end = srcMax - 48; if (AdvSimd.Arm64.IsSupported && (end >= src)) { @@ -491,7 +491,7 @@ private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, b destBytes = dest; } -#if !MONO // https://github.com/dotnet/runtime/issues/96828 +#if !MONO // https://github.com/dotnet/runtime/issues/93081 [MethodImpl(MethodImplOptions.AggressiveInlining)] [CompExactlyDependsOn(typeof(AdvSimd.Arm64))] private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart)