-
-
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
Vector{128,256} operations that use MmShuffle fall back to method call #2121
Comments
@gfoidl This has been on my mind for a long while and I was actually thinking about it the other day. Ideally I'd like to be able to keep using MMShuffle in some manner as it helps visual the operation and helps porting. |
Another option is to use binary literals. Defining constants like -- Getting the JIT to handle this properly is still on my radar, but its not "simple" and probably won't make .NET 7 unfortunately. |
The approach with the constant looks good to me. It's self describing and the optimization kicks in. |
How could things like ImageSharp/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs Lines 113 to 119 in c661ab1
Typing a literal or the constant approach (as outlined above) won't work here as it's no compile time constant. |
This pattern could be changed to effectively expose The current issue in the JIT is that we are making a decision during "import" on whether or not a given call should be an intrinsic or left as a call. For most APIs this is "always intrinsic", for the handful of APIs that require a constant operand (because the underlying instruction encoding requires it), we currently just say "if the operand is constant, intrinsic; otherwise leave as call". This misses some cases, particularly where an input becomes constant after inlining. However, enabling handling for that case requires that we either generate some "small fallback" (not feasible in many cases), emit the 256-case jump table "inline" (which would overall be worse for throughput), or update the JIT to support converting the intrinsic back into a call very late (around |
@tannergooding thanks for the insights -- much appreciated! |
Prerequisites
DEBUG
andRELEASE
modeImageSharp version
Current main branch
Other ImageSharp packages and versions
none
Environment (Operating system, version and so on)
all .NET supported
.NET Framework version
all
Description
While working on #1762 I recognized that methods that use
ImageSharp/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs
Lines 236 to 238 in c661ab1
E.g.
Vp8Encoding.FTransformPass1SSE2
looks after inlining the vector constants likeIf instead
SimdUtils.Shuffle.MmShuffle
the constant is given as literal, then the code boils down to:This is a de-facto a JIT-limitation, recorded in dotnet/runtime#9989 and dotnet/runtime#38003, also noticed in #1517 (comment)
As this is quite a difference in code-gen, hence in perf it should show up too, I propose to change to typing the shuffle literals explicetely. E.g.
If OK I'd like to tackle this in one shot with #1762 (as I'm touching these pieces anyway).
Edit: I was too eager, the PR is out...
Steps to Reproduce
Look at dissassembly of any method that uses
SimdUtils.Shuffle.MmShuffle
.Images
No response
The text was updated successfully, but these errors were encountered: