Repository navigation
Revise how constant SIMD vectors are defined in BCL #44115
Description
Activity
Dotnet-GitSync-Bot commented
on Nov 1, 2020 CollaboratorMore actionsI couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
- addeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Nov 1, 2020 RWD00 dq FF01FFFFFF00FFFFh, FF03FFFFFF02FFFFh ; <-- it's here
Is this aligned?
Both the 16 and 32-byte SIMD constants will be properly aligned if we aren't emitting "small" code:
https://github.com/dotnet/runtime/blob/master/src/coreclr/src/jit/lowerxarch.cpp#L716-L717I don't believe we currently have the logic to allow those being folded into the corresponding operand (which is always safe for AVX+ and safe for non-small code for SSE+).Nevermind, the example above is already folding 👍
@tannergooding there is a minor issue with alignment:
public static void Test(ref Vector128<double> a, ref Vector256<double> b) { a = Vector128.Create(1.0, 2.0); b = Vector256.Create(11.0, 12.0, 13.0, 14.0); }
; Method Egor:Test(byref,byref) G_M24708_IG01: vzeroupper G_M24708_IG02: vmovupd xmm0, xmmword ptr [reloc @RWD00] vmovupd xmmword ptr [rcx], xmm0 vmovupd ymm0, ymmword ptr[reloc @RWD32] vmovupd ymmword ptr[rdx], ymm0 G_M24708_IG03: vzeroupper ret RWD00 dq 3FF0000000000000h, 4000000000000000h RWD16 dd 00000000h, 00000000h, 00000000h, 00000000h ;; <--- padding RWD32 dq 4026000000000000h, 4028000000000000h, 402A000000000000h, 402C000000000000h ; Total bytes of code: 31
It could be:
RWD00 dq 4026000000000000h, 4028000000000000h, 402A000000000000h, 402C000000000000h RWD32 dq 3FF0000000000000h, 4000000000000000h
slightly more compact
Right, we don't currently do any sorting of values and I don't know how amiable the existing data structures are to having that happen.
We need to take into account that on older runtimes there may be a regression by using
Vector128.Create(JIT got improved for this recently). E.g.System.Memory(for Base64) could regress, when the package gets uupdated for an .NET Core 3.1 target.Reacted by Clinton Ingram- addedgood first issueIssue should be easy to implement, good for first-time contributorsIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorsand removeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Jun 17, 2021 Marked as
easyandup-for-grabs.Do we need to care about the older runtimes or just use the current best pattern?
This mostly applies to hardware intrinsics which are .NET Core 3.1+ only, so I don't believe we have much to be concerned about here (I don't believe we are compiling for
netcoreapp3.1andnet6.0simultaneously).If we do target downlevel TFMs, then we should consider the perf implications as .NET 3.1 will have continued support through Dec 2022: https://dotnet.microsoft.com/platform/support/policy/dotnet-core
I can create a PR (next week or so), then we can discuss more over there?!
Reacted by Tanner Gooding- ghost addedin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
on Jun 28, 2021 Scan other repos: ... ML.NET, etc
ML.NET's highest .NET version (for the relevant project) is .NET Core 3.1, so current code over there seems to be the best option. Using Vector{128|256}.Create would be a de-optimization.
Places:
https://github.com/dotnet/machinelearning/blob/1b3cb77b9752fe4279376039ee20fc42822e4845/src/Microsoft.ML.CpuMath/AvxIntrinsics.cs#L48
https://github.com/dotnet/machinelearning/blob/1b3cb77b9752fe4279376039ee20fc42822e4845/src/Microsoft.ML.CpuMath/FactorizationMachine/AvxIntrinsics.cs#L15ASP.NET Core uses Vector{128|256}.Create already, no need to change something over there.
- ghost removedin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
on Jul 12, 2021 - ghost locked as resolved and limited conversation to collaborators
on Aug 11, 2021
From #44111 (comment)
There are 3 patterns we currently use across the BCL for const vectors:
Here is the current codegen for these cases:
The first case used to be avoided due to some codegen issues, but looks like those were resolved (e.g. JIT now saves such vectors into the data section, does Value Numbering for SIMDs including constant vectors, does CSE, etc - #31834?) so we now have a lot of
static readonlyfields and we can revise them and convert intoCase1(1.1)-style where possible (maybe even if we need to duplicate them in different methods), e.g.:Places to revise:
Known limitations for Case1:
/cc @stephentoub @GrabYourPitchforks @benaadams @tannergooding