Intrinsics support for WidenFourAsciiBytesToUtf16AndWriteToBuffer (#38597)
authorPrashanth Govindarajan <prgovi@microsoft.com>
Fri, 10 Jul 2020 18:20:26 +0000 (11:20 -0700)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 18:20:26 +0000 (11:20 -0700)
src/libraries/Directory.Build.targets
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs
src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs
src/libraries/System.Utf8String.Experimental/src/System.Utf8String.Experimental.csproj
src/libraries/System.Utf8String.Experimental/src/System/Runtime/Intrinsics/Intrinsics.Shims.cs

index 5cbc77d..48dc86d 100644 (file)
   <Target Name="GetDocumentationFile"
           Returns="$(DocumentationFile)"/>
 
+  <PropertyGroup>
+    <DefineConstants Condition="'$(IsPrerelease)' != 'false' and '$(TargetFramework)' != '$(NetCoreAppCurrent)'">$(DefineConstants),USE_INTERNAL_ACCESSIBILITY</DefineConstants>
+  </PropertyGroup>
+  
   <!-- Adds Nullable annotation attributes to netstandard <= 2.0 builds -->
   <Choose>
     <When Condition="'$(Nullable)' != '' and ($(TargetFramework.StartsWith('netstandard1')) or '$(TargetFramework)' == 'netstandard2.0' or $(TargetFramework.StartsWith('netcoreapp2')) or '$(TargetFrameworkIdentifier)' == '.NETFramework')">
index 45a09e2..bd0d20b 100644 (file)
@@ -9,7 +9,12 @@ namespace System.Runtime.Intrinsics.Arm
     /// This class provides access to the ARM AdvSIMD hardware instructions via intrinsics
     /// </summary>
     [CLSCompliant(false)]
-    public abstract class AdvSimd : ArmBase
+#if USE_INTERNAL_ACCESSIBILITY
+    internal
+#else
+    public
+#endif
+        abstract class AdvSimd : ArmBase
     {
         internal AdvSimd() { }
 
index 8ec5754..ad356ad 100644 (file)
@@ -10,7 +10,12 @@ namespace System.Runtime.Intrinsics.Arm
     /// This class provides access to the ARM base hardware instructions via intrinsics
     /// </summary>
     [CLSCompliant(false)]
-    public abstract class ArmBase
+#if USE_INTERNAL_ACCESSIBILITY
+    internal
+#else
+    public
+#endif
+        abstract class ArmBase
     {
         internal ArmBase() { }
 
index da8ddd6..e85c1bb 100644 (file)
@@ -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<ulong> vecWide = Sse2.UnpackLow(vecNarrow, Vector128<byte>.Zero).AsUInt64();
                 Unsafe.WriteUnaligned<ulong>(ref Unsafe.As<char, byte>(ref outputBuffer), Sse2.X64.ConvertToUInt64(vecWide));
             }
+            else if (AdvSimd.Arm64.IsSupported)
+            {
+                Vector128<byte> vecNarrow = AdvSimd.DuplicateToVector128(value).AsByte();
+                Vector128<ulong> vecWide = AdvSimd.Arm64.ZipLow(vecNarrow, Vector128<byte>.Zero).AsUInt64();
+                Unsafe.WriteUnaligned<ulong>(ref Unsafe.As<char, byte>(ref outputBuffer), vecWide.ToScalar());
+            }
             else
             {
                 if (BitConverter.IsLittleEndian)
index 4496422..5b84d79 100644 (file)
@@ -41,6 +41,8 @@
   <ItemGroup Condition="'$(IsPrerelease)' != 'false' AND '$(TargetFramework)' != '$(NetCoreAppCurrent)'">
     <Compile Include="System\Globalization\GlobalizationMode.cs" />
     <Compile Include="System\Runtime\Intrinsics\Intrinsics.Shims.cs" />
+    <Compile Include="$(CoreLibSharedDir)\System\Runtime\Intrinsics\Arm\AdvSimd.PlatformNotSupported.cs" Link="System\Runtime\Intrinsics\Arm\AdvSimd.PlatformNotSupported.cs" />
+    <Compile Include="$(CoreLibSharedDir)\System\Runtime\Intrinsics\Arm\ArmBase.PlatformNotSupported.cs" Link="System\Runtime\Intrinsics\Arm\ArmBase.PlatformNotSupported.cs" />
     <Compile Include="System\ThrowHelper.cs" />
     <Compile Include="System\Utf8Extensions.Portable.cs" />
     <Compile Include="System\Utf8String.Portable.cs" />
index d776b9d..e5f9284 100644 (file)
@@ -26,6 +26,8 @@ namespace System.Runtime.Intrinsics
         public static Vector128<ulong> AsUInt64<T>(this Vector128<T> vector) where T : struct => throw new PlatformNotSupportedException();
         public static T GetElement<T>(this Vector128<T> vector, int index) where T : struct => throw new PlatformNotSupportedException();
         public static T ToScalar<T>(this Vector64<T> vector) where T : struct => throw new PlatformNotSupportedException();
+        public static unsafe Vector128<ulong> CreateScalar(ulong value) => throw new PlatformNotSupportedException();
+        public static T ToScalar<T>(this Vector128<T> vector) where T : struct => throw new PlatformNotSupportedException();
     }
     internal readonly struct Vector128<T>
         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<byte> AddAcross(Vector64<byte> value) => throw new PlatformNotSupportedException();
-        }
-        public static Vector64<byte> PopCount(Vector64<byte> value) => throw new PlatformNotSupportedException();
     }
 }