From 1bff0cce7ba7de077c09e331d24e3b27c3779888 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 8 Feb 2021 12:22:12 -0800 Subject: [PATCH] Refactor TranscodeUtf8 to allow trimming of Vector128 (#47928) --- .../src/System/Text/Unicode/Utf8Utility.Transcoding.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs index b0c1376..ce8693b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs @@ -882,7 +882,8 @@ namespace System.Text.Unicode // vector is only used in those code paths, we leave it uninitialized if SSE4.1 // is not enabled. - Unsafe.SkipInit(out Vector128 nonAsciiUtf16DataMask); + Vector128 nonAsciiUtf16DataMask; + if (Sse41.X64.IsSupported || (AdvSimd.Arm64.IsSupported && BitConverter.IsLittleEndian)) { nonAsciiUtf16DataMask = Vector128.Create(unchecked((short)0xFF80)); // mask of non-ASCII bits in a UTF-16 char @@ -950,6 +951,10 @@ namespace System.Text.Unicode Vector128 utf16Data; for (i = 0; (uint)i < maxIters; i++) { + // The linker won't trim out nonAsciiUtf16DataMask unless this is in the loop. + // Luckily, this is a nop and will be elided by the JIT + Unsafe.SkipInit(out nonAsciiUtf16DataMask); + utf16Data = Unsafe.ReadUnaligned>(pInputBuffer); if (AdvSimd.IsSupported) -- 2.7.4