From: Prashanth Govindarajan Date: Wed, 29 Jul 2020 18:02:03 +0000 (-0700) Subject: Narrow four utf16 chars to ascii and write to buffer (#39508) X-Git-Tag: submit/tizen/20210909.063632~6344 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=564426051c8ec46051ee29048650cdae39c62d48;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Narrow four utf16 chars to ascii and write to buffer (#39508) * Shims * shim * Cherry-pick * NarrowFourUtf16CharsToAsciiAndWriteToBuffer * Address comments * Nit --- diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs index 7628f6f..76075a5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs @@ -1003,6 +1003,16 @@ namespace System.Text Vector128 vecNarrow = Sse2.PackUnsignedSaturate(vecWide, vecWide).AsUInt32(); Unsafe.WriteUnaligned(ref outputBuffer, Sse2.ConvertToUInt32(vecNarrow)); } + else if (AdvSimd.IsSupported) + { + // Narrows a vector of words [ w0 w1 w2 w3 ] to a vector of bytes + // [ b0 b1 b2 b3 * * * * ], then writes 4 bytes (32 bits) to the destination. + + Vector128 vecWide = Vector128.CreateScalarUnsafe(value).AsInt16(); + Vector64 lower = AdvSimd.ExtractNarrowingSaturateUnsignedLower(vecWide); + Unsafe.WriteUnaligned(ref outputBuffer, lower.AsUInt32().ToScalar()); + } + else { if (BitConverter.IsLittleEndian) diff --git a/src/libraries/System.Utf8String.Experimental/src/System/Runtime/Intrinsics/Intrinsics.Shims.cs b/src/libraries/System.Utf8String.Experimental/src/System/Runtime/Intrinsics/Intrinsics.Shims.cs index fa4602b..ff020e0 100644 --- a/src/libraries/System.Utf8String.Experimental/src/System/Runtime/Intrinsics/Intrinsics.Shims.cs +++ b/src/libraries/System.Utf8String.Experimental/src/System/Runtime/Intrinsics/Intrinsics.Shims.cs @@ -9,6 +9,8 @@ namespace System.Runtime.Intrinsics public static Vector64 CreateScalar(uint value) => throw new PlatformNotSupportedException(); public static Vector64 AsByte(this Vector64 vector) where T : struct => throw new PlatformNotSupportedException(); public static Vector64 AsUInt32(this Vector64 vector) where T : struct => throw new PlatformNotSupportedException(); + public static Vector64 GetLower(this Vector128 vector) where T : struct => throw new PlatformNotSupportedException(); + public static Vector64 AsUInt64(this Vector64 vector) where T : struct => throw new PlatformNotSupportedException(); } internal readonly struct Vector64 where T : struct @@ -21,6 +23,8 @@ namespace System.Runtime.Intrinsics public static Vector128 Create(short value) => throw new PlatformNotSupportedException(); public static Vector128 Create(ulong value) => throw new PlatformNotSupportedException(); public static Vector128 Create(ushort value) => throw new PlatformNotSupportedException(); + public static Vector128 Create(byte value) => throw new PlatformNotSupportedException(); + public static Vector128 Create(uint value) => throw new PlatformNotSupportedException(); public static Vector128 CreateScalarUnsafe(ulong value) => throw new PlatformNotSupportedException(); public static Vector128 AsByte(this Vector128 vector) where T : struct => throw new PlatformNotSupportedException(); public static Vector128 AsInt16(this Vector128 vector) where T : struct => throw new PlatformNotSupportedException();