-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Move the various helper intrinsics to be implemented on the S.R.Intrinsics.Vector types #20147
Conversation
FYI. @CarolEidt, @fiigii, @eerhardt, @terrajobst Still working on the other help intrinsics, but this is an early view (at least for |
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs
Outdated
Show resolved
Hide resolved
We probably need generic versions as well. public Vector128<U> As<U>() |
I asked about this last Tuesday (25th) and the design review group decided against it. Users wanting to use generic algorithms can write their own extension methods or use |
I encourage to have a generic version
|
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
Outdated
Show resolved
Hide resolved
Feel free to open another issue requesting this. However, given the original design review (which decided we should expose
If there is a code-gen problem with |
Right. You have to do:
and trust that the JIT will optimize it appropriately. -- I have sent an e-mail and included this on the list of things we should get confirmation on. |
@tannergooding Thanks, but the code seems to have really bad codegen (release publish, debug jit, release runtime/corelib) static void Main(string[] args)
{
Vector128<float> v1 = Sse.SetZeroVector128();
Vector128<int> v = Unsafe.As<Vector128<float>, Vector128<int>>(ref v1);
Console.WriteLine(Sse2.Add(v, v));
} IN0010: 000000 push rbp
IN0011: 000001 sub rsp, 64
IN0012: 000005 lea rbp, [rsp+40H]
IN0013: 00000A xor rax, rax
IN0014: 00000C mov qword ptr [V01 rbp-20H], rax
IN0015: 000010 mov qword ptr [V01+0x8 rbp-18H], rax
IN0016: 000014 mov gword ptr [V00 rbp-08H], rdi
G_M45811_IG02: ; offs=000018H, size=004DH, gcrefRegs=00000000 {}, byrefRegs=00000000 {}, byref
IN0001: 000018 vxorps xmm0, xmm0, xmm0
IN0002: 00001D vmovapd xmmword ptr [V01 rbp-20H], xmm0
IN0003: 000023 lea rdi, bword ptr [V01 rbp-20H]
IN0004: 000027 call Unsafe:As(byref):byref
IN0005: 00002C vmovupd xmm0, xmmword ptr [rax]
IN0006: 000031 vmovapd xmmword ptr [V03 rbp-30H], xmm0
IN0007: 000037 vmovapd xmm0, xmmword ptr [V03 rbp-30H]
IN0008: 00003D vpaddd xmm0, xmm0, xmmword ptr [V03 rbp-30H]
IN0009: 000043 vmovapd xmmword ptr [V04 rbp-40H], xmm0
IN000a: 000049 lea rsi, bword ptr [V04 rbp-40H]
IN000b: 00004D mov rdi, 0x11D464F18
IN000c: 000057 call CORINFO_HELP_BOX
IN000d: 00005C mov rdi, rax
IN000e: 00005F call Console:WriteLine(ref)
IN000f: 000064 nop
G_M45811_IG03: ; offs=000065H, size=0006H, epilog, nogc, emitadd
IN0017: 000065 lea rsp, [rbp]
IN0018: 000069 pop rbp
IN0019: 00006A ret |
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs
Outdated
Show resolved
Hide resolved
@fiigii - Now that tiered compilation is enabled, if you want to see the optimized code you need to set
Note that the boxing is done for the call to |
@CarolEidt Thank you! |
Updated to also cover the |
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.PlatformNotSupported.cs
Outdated
Show resolved
Hide resolved
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
Outdated
Show resolved
Hide resolved
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128`1.cs
Outdated
Show resolved
Hide resolved
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
Outdated
Show resolved
Hide resolved
Still TODO:
|
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
Show resolved
Hide resolved
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128`1.cs
Outdated
Show resolved
Hide resolved
Currently, we have AVX "Insert/Extract Element" helpers to match SSE4.1 instructions. It would be nice to have a bunch of platform-agnostic insert/extract for all the vector types (but we still need the SSE4.1 intrinsic). |
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128`1.cs
Outdated
Show resolved
Hide resolved
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
Outdated
Show resolved
Hide resolved
src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
Outdated
Show resolved
Hide resolved
I think, from the API shape perspective. This matches what we would expect and what I would want to confirm at the follow up API review we'll be having. If everyone else is also happy with this, I think we should be good to merge and we can do any minor/residual cleanup after the API review (we already reviewed and approved moving the helper methods to the base types, the follow-up review is confirming the moved APIs shapes and names are what we want). After the CoreFX side is updated, I can finish the remaining JIT hookup for the various Create methods and we can add the "CreateScalarUnsafe" methods (or whatever name we decide upon) after the follow-up API review. |
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
Outdated
Show resolved
Hide resolved
@tannergooding Thanks for the work. The new APIs look good to me overall. |
@fiigii, updated to only add the new APIs and their software implementations. |
src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs
Outdated
Show resolved
Hide resolved
We need to move |
This has been updated as per the API review that happened today:
|
CC. @GrabYourPitchforks who was in the review. |
Could you please add XML comments for these helper intrinsics, especially |
Done. |
CoreFX side is here: dotnet/corefx#33302 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the work, especially the great documentation 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I would have liked to see tests added for these at the same time as the IL implementation. The tests should presumably be in a shared directory as these are not target-specific.
That said, I'm fine with this going in now, and adding the tests with the JIT support.
Right, the problem is that we can't add tests until after the new APIs appear in the reference assembly :( |
Ah yes, of course. Thanks for clarifying. |
Changed |
…nsics.Vector types (dotnet#20147) * Renaming Vector64.cs, Vector128.cs, and Vector256.cs to be Vector64_1.cs, etc * Adding some core helper methods to the Vector64, Vector128, and Vecto256 types. * Adding some documentation comments to the System.Runtime.Intrinsics.Vector types * Changing `Set` to `With`
…nsics.Vector types (dotnet/coreclr#20147) * Renaming Vector64.cs, Vector128.cs, and Vector256.cs to be Vector64_1.cs, etc * Adding some core helper methods to the Vector64, Vector128, and Vecto256 types. * Adding some documentation comments to the System.Runtime.Intrinsics.Vector types * Changing `Set` to `With` Commit migrated from dotnet/coreclr@ce586ae
No description provided.