From 8a6d145fddeda78fa59517ed0dabc0f023313f8f Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Fri, 17 Jul 2020 12:24:29 -0700 Subject: [PATCH 1/6] Shims --- .../src/System/Runtime/Intrinsics/Intrinsics.Shims.cs | 4 ++++ 1 file changed, 4 insertions(+) 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 fa4602b33f429f..ff020e0259cfdc 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 @@ internal static class Vector64 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 @@ internal static class Vector128 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(); From fc0fee6bddf7c31ad2a31a78e9daefd416e74dc1 Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Mon, 20 Jul 2020 12:49:04 -0700 Subject: [PATCH 2/6] shim --- .../src/System/Runtime/Intrinsics/Intrinsics.Shims.cs | 1 + 1 file changed, 1 insertion(+) 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 ff020e0259cfdc..9c5a3c26a05b32 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 @@ -11,6 +11,7 @@ internal static class Vector64 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(); + public static Vector64 AsUInt32(this Vector64 vector) where T : struct => throw new PlatformNotSupportedException(); } internal readonly struct Vector64 where T : struct From 3e5ced852731a0af98f246553b8404a787c5dc59 Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Mon, 20 Jul 2020 16:27:42 -0700 Subject: [PATCH 3/6] Cherry-pick --- .../src/System/Runtime/Intrinsics/Intrinsics.Shims.cs | 1 - 1 file changed, 1 deletion(-) 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 9c5a3c26a05b32..ff020e0259cfdc 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 @@ -11,7 +11,6 @@ internal static class Vector64 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(); - public static Vector64 AsUInt32(this Vector64 vector) where T : struct => throw new PlatformNotSupportedException(); } internal readonly struct Vector64 where T : struct From b511d88b9b68f04ebf7480163feeb89e302c0703 Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Fri, 17 Jul 2020 12:25:27 -0700 Subject: [PATCH 4/6] NarrowFourUtf16CharsToAsciiAndWriteToBuffer --- .../src/System/Text/ASCIIUtility.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 7628f6f89b45e8..7ea91d22e3d5c9 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,19 @@ private static void NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref byte outputB Vector128 vecNarrow = Sse2.PackUnsignedSaturate(vecWide, vecWide).AsUInt32(); Unsafe.WriteUnaligned(ref outputBuffer, Sse2.ConvertToUInt32(vecNarrow)); } + else if (AdvSimd.Arm64.IsSupported) + { + // Narrows a vector of words [ w0 w1 w2 w3 ] to a vector of bytes + // [ b0 b1 b2 b3 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 + { + AdvSimd.StoreSelectedScalar((byte*)Unsafe.AsPointer(ref outputBuffer), lower, 0); + } + } + else { if (BitConverter.IsLittleEndian) From 9c2b8a7f0e9ef55a6c386f1c915c8b01f83d326d Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Mon, 20 Jul 2020 10:46:16 -0700 Subject: [PATCH 5/6] Address comments --- .../System.Private.CoreLib/src/System/Text/ASCIIUtility.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 7ea91d22e3d5c9..a0a86ed25e0ff2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs @@ -1006,14 +1006,11 @@ private static void NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref byte outputB else if (AdvSimd.Arm64.IsSupported) { // Narrows a vector of words [ w0 w1 w2 w3 ] to a vector of bytes - // [ b0 b1 b2 b3 b0 b1 b2 b3 ], then writes 4 bytes (32 bits) to the destination. + // [ 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 - { - AdvSimd.StoreSelectedScalar((byte*)Unsafe.AsPointer(ref outputBuffer), lower, 0); - } + Unsafe.WriteUnaligned(ref outputBuffer, lower.AsUInt32().ToScalar()); } else From 938efcec8f8b7e099c890acedec55fd511b4d698 Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Mon, 20 Jul 2020 13:55:01 -0700 Subject: [PATCH 6/6] Nit --- .../System.Private.CoreLib/src/System/Text/ASCIIUtility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a0a86ed25e0ff2..76075a5e66dc48 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs @@ -1003,7 +1003,7 @@ private static void NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref byte outputB Vector128 vecNarrow = Sse2.PackUnsignedSaturate(vecWide, vecWide).AsUInt32(); Unsafe.WriteUnaligned(ref outputBuffer, Sse2.ConvertToUInt32(vecNarrow)); } - else if (AdvSimd.Arm64.IsSupported) + 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.