Skip to content

Intrinsics support for WidenFourAsciiBytesToUtf16AndWriteToBuffer#38597

Merged
pgovind merged 1 commit intodotnet:masterfrom
pgovind:arm64
Jul 10, 2020
Merged

Intrinsics support for WidenFourAsciiBytesToUtf16AndWriteToBuffer#38597
pgovind merged 1 commit intodotnet:masterfrom
pgovind:arm64

Conversation

@pgovind
Copy link

@pgovind pgovind commented Jun 30, 2020

Implements 1 API from #35034

@ghost
Copy link

ghost commented Jun 30, 2020

Tagging subscribers to this area: @tannergooding
Notify danmosemsft if you want to be subscribed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the use of ToScalar here produce acceptable codegen? In the SSE2 code paths, analyzing the x86 codegen revealed that ConvertToUInt64 produced better codegen than ToScalar. I don't know if the arm64 JIT has a similar behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we have fixed most of these cases and improved the codegen for things like ToScalar. If not, we should as that is preferable for readability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ToScalar() is optimized for arm64.

@GrabYourPitchforks
Copy link
Member

Control flow LGTM, but I don't know enough about advsimd intrinsics to give this a proper review. @tannergooding, thoughts?
I really need to sit down with an arm64 machine for a few days and tinker. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GrabYourPitchforks, instead of maintaining this Shims.cs file, we could just include the *.PlatformNotSupported.cs variants of the relevant ISAs: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs

Thoughts? (Note we still need the Shims file for Vector64/Vector128/Vector256, but it would avoid needing to update for all of the ISAs)

Copy link
Contributor

@carlossanlop carlossanlop Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about this. Whenever you select "Go to definition" in Visual Studio, it takes you to the AdvSimd.PlatformNotSupported.cs file. Why do we have the same APIs throwing PNSE in two different files?

Edit: Santi explained the difference. Please ignore this comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried doing this, VS complained about not understanding the [Intrinsic] attribute. I didn't bother investigating why, but I did see some commented out code in this file with similar [Intrinsic] attributes. Maybe that's the reason @GrabYourPitchforks didn't include the whole file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no problem with including the PNSE file as long as we're not introducing public API. We'd need to define a dummy [Intrinsic] attribute in the consuming project, but that's very straightforward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that would be an issue. The types in the PNSE file are public, not internal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have ifdefs around these, just like how we have ifdefs around some of the new code analysis attributes. It might help code sharing between libraries that target netstandard2.0.
(Really that's an issue for a separate PR, but I wonder if this PR is a forcing function for it.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually sounds like we need one for some of the other OOB libraries as well. It might be good to just have an official shim library.

System.Text.Encodings.Web is using ifdefs today, but multitargets netstandard2.0, netcoreapp3.1, and net5; so the ifdefs are going to get a bit crazier

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For System.Text.Encodings.Web, I resorted to copying this file and extending it as needed. But would be great to have a package for frictionless intrinsics API usage.

@pgovind
Copy link
Author

pgovind commented Jul 9, 2020

Thanks for the stamp Tanner. FWIW, here are the micro benchmarks I ran on my machine (Yeeesh, that took an unreasonable amount of time to set up):

D:\repos\performance\src\tools\ResultsComparer>dotnet run --base "........\before_arm64" --diff "........\after_arm64" --threshold 0.01%
summary:
better: 1, geomean: 2.057
total diff: 1

No Slower results for the provided threshold = 0.01% and noise filter = 0.3ns.

Faster base/diff Base Median (ns) Diff Median (ns) Modality
System.Text.Experimental.Perf.ToUtf16(expected: "This is a big string of words. 2.06 1207.03 586.81

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the usage of these APIs inside ASCIIUtility.cs. Any reason why this is added?

Copy link
Author

@pgovind pgovind Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it looks like they sneaked in while I was doing an interactive add. I need them for my next PR, so I think I'll leave them in, unless someone disagrees :)

Returns="$(DocumentationFile)"/>

<PropertyGroup>
<DefineConstants Condition="'$(IsPrerelease)' != 'false' and '$(TargetFramework)' != '$(NetCoreAppCurrent)'">$(DefineConstants),USE_INTERNAL_ACCESSIBILITY</DefineConstants>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this living in Directory.Build.props. Shouldn't it rather be something that individual projects opt into?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first reaction too. Levi suggested that it live here, so I didn't pay too much attention to it. In my next PR, I'll move it to System.Utf8Experimental.csproj.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this constant meant to be used in contexts other than intrinsics shims? If not, then we should probably use a more specific name like USE_INTERNAL_INTRINSICS_SHIMS or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an infrastructure standpoint this is wrong as the TargetFramework property shouldn't be read outside the project file. Instead inferred properties like TargetFrameworkVersion and TargetFrameworkIdentifier should be used. If you already plan to move it then it's fine.

@pgovind pgovind merged commit 7fab504 into dotnet:master Jul 10, 2020
@pgovind pgovind deleted the arm64 branch July 10, 2020 18:20
/// </summary>
[CLSCompliant(false)]
public abstract class ArmBase
#if USE_INTERNAL_ACCESSIBILITY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to remove the CLSCompliant attribute when USE_INTERNAL_ACCESSIBILITY is enabled. Getting build warnings which I have to explicitly disable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. Will submit a small PR for this shortly

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants