-
-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Used inline SIMD vectors if they are constants #2122
Used inline SIMD vectors if they are constants #2122
Conversation
#endif | ||
|
||
static Vp8Encoding() | ||
private static byte[] GetClip1() |
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.
Instead of the static constructor (cctor) this method is now called from the static readonly
field.
Avoiding a cctor and using beforefieldinit
(IL) is the prefered way in dotnet/runtime too, as there are several pro reasons for it, liking timing, static init check, etc.
That's the only other code change not mentioned in PR's description.
6e6a2ad
to
dd35b74
Compare
The CI leg for windows-latest is failing with
Local tests are passing (VS, standard checkout as given in ReadMe). |
@JimBobSquarePants thanks, now we had a race condition. Thanks! |
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.
Sorry for the delay in reviewing. Been focusing on one of the other libraries.
This all looks good to me. I think I'll still follow up with a PR to introduce a complete set of constants for MMShuffle though.
I'm merging this. It's the same Skew test failing each time as noted in #2117 |
Prerequisites
Description
Starting with .NET 5 constant SIMD vectors can be used / created "inline", so that the JIT can read the values from the data section. Thus the need of static readonly fields for these kind of vectors is gone.
Codegen (x64) was spot-checked. Basically it's
For loops or other code that isn't tiered compiled by the JIT, the static init check needed by the runtime is also elided with this change.
In micro-benchmarks that change allone I expect to be just below noise, as all data is in the cache and the branch-predictor (static init check) will be trainined. The difference could (hopefully be should) be visible in real-world apps.
Note: for micro-benchmarks #2121 will have an effect, see machine code comparison over there.
Fixes #1762
Contributes to #2121
Patterns applied
If a constant vector is used only once outside a loop, then
Vector{128,256}.Create
is called in-place of the argument. That way the JIT is able to produce code likeand no additional (logical) register is needed.
If a constant vector is used once inside a loop, then the
Vector{128,256}.Create
is hoisted above the loop(s), as the JIT (currently) won't do this for us.If a constant vector is used several times outside a loop, then
Vector{128,256}.Create
is assigned to a vector variable as early as possible (to hide the latency of loading from mem), but not too far away to keep the logical context of the code.