Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a981b5

Browse files
committed
Revert "Use multi-reg load/store for EncodeToUtf8 (dotnet#95513)"
This reverts commit fdb03ca.
1 parent 15339d7 commit 3a981b5

File tree

1 file changed

+0
-67
lines changed

1 file changed

+0
-67
lines changed

src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Encoder.cs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,6 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan<byte> bytes, Span
8585
goto DoneExit;
8686
}
8787

88-
end = srcMax - 48;
89-
if (AdvSimd.Arm64.IsSupported && (end >= src))
90-
{
91-
AdvSimdEncode(ref src, ref dest, end, maxSrcLength, destLength, srcBytes, destBytes);
92-
93-
if (src == srcEnd)
94-
goto DoneExit;
95-
}
96-
9788
end = srcMax - 16;
9889
if ((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian && (end >= src))
9990
{
@@ -489,64 +480,6 @@ private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, b
489480
destBytes = dest;
490481
}
491482

492-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
493-
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
494-
private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart)
495-
{
496-
// C# implementatino of https://github.com/aklomp/base64/blob/3a5add8652076612a8407627a42c768736a4263f/lib/arch/neon64/enc_loop.c
497-
Vector128<byte> str1;
498-
Vector128<byte> str2;
499-
Vector128<byte> str3;
500-
Vector128<byte> res1;
501-
Vector128<byte> res2;
502-
Vector128<byte> res3;
503-
Vector128<byte> res4;
504-
Vector128<byte> tblEnc1 = Vector128.Create("ABCDEFGHIJKLMNOP"u8).AsByte();
505-
Vector128<byte> tblEnc2 = Vector128.Create("QRSTUVWXYZabcdef"u8).AsByte();
506-
Vector128<byte> tblEnc3 = Vector128.Create("ghijklmnopqrstuv"u8).AsByte();
507-
Vector128<byte> tblEnc4 = Vector128.Create("wxyz0123456789+/"u8).AsByte();
508-
byte* src = srcBytes;
509-
byte* dest = destBytes;
510-
511-
// If we have Neon support, pick off 48 bytes at a time for as long as we can.
512-
do
513-
{
514-
// Load 48 bytes and deinterleave:
515-
AssertRead<Vector128<byte>>(src, srcStart, sourceLength);
516-
(str1, str2, str3) = AdvSimd.Arm64.LoadVector128x3AndUnzip(src);
517-
518-
// Divide bits of three input bytes over four output bytes:
519-
res1 = AdvSimd.ShiftRightLogical(str1, 2);
520-
res2 = AdvSimd.ShiftRightLogical(str2, 4);
521-
res3 = AdvSimd.ShiftRightLogical(str3, 6);
522-
res2 = AdvSimd.ShiftLeftAndInsert(res2, str1, 4);
523-
res3 = AdvSimd.ShiftLeftAndInsert(res3, str2, 2);
524-
525-
// Clear top two bits:
526-
res2 &= AdvSimd.DuplicateToVector128((byte)0x3F);
527-
res3 &= AdvSimd.DuplicateToVector128((byte)0x3F);
528-
res4 = str3 & AdvSimd.DuplicateToVector128((byte)0x3F);
529-
530-
// The bits have now been shifted to the right locations;
531-
// translate their values 0..63 to the Base64 alphabet.
532-
// Use a 64-byte table lookup:
533-
res1 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res1);
534-
res2 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res2);
535-
res3 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res3);
536-
res4 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res4);
537-
538-
// Interleave and store result:
539-
AssertWrite<Vector128<byte>>(dest, destStart, destLength);
540-
AdvSimd.Arm64.StoreVector128x4AndZip(dest, (res1, res2, res3, res4));
541-
542-
src += 48;
543-
dest += 64;
544-
} while (src <= srcEnd);
545-
546-
srcBytes = src;
547-
destBytes = dest;
548-
}
549-
550483
[MethodImpl(MethodImplOptions.AggressiveInlining)]
551484
[CompExactlyDependsOn(typeof(Ssse3))]
552485
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]

0 commit comments

Comments
 (0)