From 83025327576ba5f95ae979b688107c59a227bb50 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:54:43 +0100 Subject: [PATCH] Avoid `ExtractMostSignificantBits` in AVX512 path --- .../System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs index 97765e340acff..4ea898af62273 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs @@ -663,6 +663,7 @@ private static unsafe void Avx512Decode(TBase64Decoder decode // The JIT won't hoist these "constants", so help it Vector512 vbmiLookup0 = Vector512.Create(decoder.VbmiLookup0).AsSByte(); Vector512 vbmiLookup1 = Vector512.Create(decoder.VbmiLookup1).AsSByte(); + Vector512 errorMask = Vector512.Create(sbyte.MinValue); Vector512 vbmiPackedLanesControl = Vector512.Create( 0x06000102, 0x090a0405, 0x0c0d0e08, 0x16101112, 0x191a1415, 0x1c1d1e18, 0x26202122, 0x292a2425, @@ -687,7 +688,7 @@ private static unsafe void Avx512Decode(TBase64Decoder decode // origIndex = [...|00dddddd|00cccccc|00bbbbbb|00aaaaaa] Vector512 origIndex = Avx512Vbmi.PermuteVar64x8x2(vbmiLookup0, str, vbmiLookup1); Vector512 errorVec = (origIndex.AsInt32() | str.AsInt32()).AsSByte(); - if (errorVec.ExtractMostSignificantBits() != 0) + if ((errorVec & errorMask) != Vector512.Zero) { break; }