-
-
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
Fix and normalize Vector4 UnPremultiply #2369
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2c30c90
Fix pre/unpremultiply methods
JimBobSquarePants 5a5d23c
Update test tolerances to cater for reference decoder bug.
JimBobSquarePants 189c07b
Fix benchmarks
JimBobSquarePants 9e19134
Implement feedback and update benchmarks
JimBobSquarePants aed484a
Merge branch 'main' into js/premultiply
JimBobSquarePants 1704140
Remove bad debug check and refs
JimBobSquarePants aab9955
normalize code
JimBobSquarePants File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Branching in SIMD code is "generally" undesirable.
It's probably worth comparing this to an implementation that does
CompareEqual
+Blend
instead (much like you're already doing for theAvx2
path) to see which is better.You should be able to use the
AsVector128()
again. WithSse.CompareEqual
and usingSse41.BlendVariable
.If
Sse41
isn't supported (which is unlikely since its been around since 2007), you can replace it withSse.Or(Sse.And(left, mask), Sse.AndNot(mask, right))
-- That is:
(left & mask) | (right & ~mask)
--
Sse.AndNot(x, y)
does~x & y
, despite its name implyingx & ~y
; a weird quirk of the instructionThere 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.
--
left
here represents the value to use if the comparison result (mask
) was true for that element--
right
correspondingly is the value to use if it wasfalse
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.
Would you believe the version I had was actually faster!?
UnPremultiply using Vector4 and branching.
UnPremultiply using Sse41.
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.
I'd believe it.
The general reason to avoid branching is that it often slows down the overall operation. However, the exact difference depends on the scenario being tested and how frequently that branch will be hit as compared to the cost of computing and blending both paths.
If I'm reading your table right, then in this case, they look practically identical with a little less error and deviation for blending in
Bulk
. But the branching ends up winning out for single operations.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.
Yeah. We'd only ever use in for single operations or for overlaps in the AVX run.