From 7fab504a54e97b20d08946c2ed621b48cca4fbc6 Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Fri, 10 Jul 2020 11:20:26 -0700 Subject: [PATCH] Intrinsics support for WidenFourAsciiBytesToUtf16AndWriteToBuffer (#38597) --- src/libraries/Directory.Build.targets | 4 ++++ .../Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs | 7 +++++- .../Intrinsics/Arm/ArmBase.PlatformNotSupported.cs | 7 +++++- .../src/System/Text/ASCIIUtility.cs | 7 ++++++ .../src/System.Utf8String.Experimental.csproj | 2 ++ .../System/Runtime/Intrinsics/Intrinsics.Shims.cs | 28 +++++++--------------- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/libraries/Directory.Build.targets b/src/libraries/Directory.Build.targets index 5cbc77d..48dc86d 100644 --- a/src/libraries/Directory.Build.targets +++ b/src/libraries/Directory.Build.targets @@ -219,6 +219,10 @@ + + $(DefineConstants),USE_INTERNAL_ACCESSIBILITY + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs index 45a09e2..bd0d20b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs @@ -9,7 +9,12 @@ namespace System.Runtime.Intrinsics.Arm /// This class provides access to the ARM AdvSIMD hardware instructions via intrinsics /// [CLSCompliant(false)] - public abstract class AdvSimd : ArmBase +#if USE_INTERNAL_ACCESSIBILITY + internal +#else + public +#endif + abstract class AdvSimd : ArmBase { internal AdvSimd() { } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs index 8ec5754..ad356ad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs @@ -10,7 +10,12 @@ namespace System.Runtime.Intrinsics.Arm /// This class provides access to the ARM base hardware instructions via intrinsics /// [CLSCompliant(false)] - public abstract class ArmBase +#if USE_INTERNAL_ACCESSIBILITY + internal +#else + public +#endif + abstract class ArmBase { internal ArmBase() { } 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 da8ddd6..e85c1bb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; #if SYSTEM_PRIVATE_CORELIB @@ -1700,6 +1701,12 @@ namespace System.Text Vector128 vecWide = Sse2.UnpackLow(vecNarrow, Vector128.Zero).AsUInt64(); Unsafe.WriteUnaligned(ref Unsafe.As(ref outputBuffer), Sse2.X64.ConvertToUInt64(vecWide)); } + else if (AdvSimd.Arm64.IsSupported) + { + Vector128 vecNarrow = AdvSimd.DuplicateToVector128(value).AsByte(); + Vector128 vecWide = AdvSimd.Arm64.ZipLow(vecNarrow, Vector128.Zero).AsUInt64(); + Unsafe.WriteUnaligned(ref Unsafe.As(ref outputBuffer), vecWide.ToScalar()); + } else { if (BitConverter.IsLittleEndian) diff --git a/src/libraries/System.Utf8String.Experimental/src/System.Utf8String.Experimental.csproj b/src/libraries/System.Utf8String.Experimental/src/System.Utf8String.Experimental.csproj index 4496422..5b84d79 100644 --- a/src/libraries/System.Utf8String.Experimental/src/System.Utf8String.Experimental.csproj +++ b/src/libraries/System.Utf8String.Experimental/src/System.Utf8String.Experimental.csproj @@ -41,6 +41,8 @@ + + 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 d776b9d..e5f9284 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 @@ -26,6 +26,8 @@ namespace System.Runtime.Intrinsics public static Vector128 AsUInt64(this Vector128 vector) where T : struct => throw new PlatformNotSupportedException(); public static T GetElement(this Vector128 vector, int index) where T : struct => throw new PlatformNotSupportedException(); public static T ToScalar(this Vector64 vector) where T : struct => throw new PlatformNotSupportedException(); + public static unsafe Vector128 CreateScalar(ulong value) => throw new PlatformNotSupportedException(); + public static T ToScalar(this Vector128 vector) where T : struct => throw new PlatformNotSupportedException(); } internal readonly struct Vector128 where T : struct @@ -127,27 +129,13 @@ namespace System.Runtime.Intrinsics.X86 } } -namespace System.Runtime.Intrinsics.Arm +namespace System.Runtime.CompilerServices { - internal abstract class ArmBase + // Calls to methods or references to fields marked with this attribute may be replaced at + // some call sites with jit intrinsic expansions. + // Types marked with this attribute may be specially treated by the runtime/compiler. + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, Inherited = false)] + internal sealed class IntrinsicAttribute : Attribute { - public abstract class Arm64 - { - public const bool IsSupported = false; - public static int LeadingZeroCount(ulong value) => throw new PlatformNotSupportedException(); - public static uint ReverseElementBits(ulong value) => throw new PlatformNotSupportedException(); - } - public const bool IsSupported = false; - public static int LeadingZeroCount(uint value) => throw new PlatformNotSupportedException(); - public static uint ReverseElementBits(uint value) => throw new PlatformNotSupportedException(); - } - - internal abstract class AdvSimd : ArmBase - { - public new abstract class Arm64 : ArmBase.Arm64 - { - public static Vector64 AddAcross(Vector64 value) => throw new PlatformNotSupportedException(); - } - public static Vector64 PopCount(Vector64 value) => throw new PlatformNotSupportedException(); } } -- 2.7.4