-
Notifications
You must be signed in to change notification settings - Fork 91
Change Line::nearest implementation to be branchless
#505
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
Conversation
| // Clamp the parameter to be on the line segment. This results in `t==0` if `t==inf` above. | ||
| #[expect( | ||
| clippy::manual_clamp, | ||
| reason = "`clamp` uses slightly more instructions than chained `max` and `min` on x86 and aarch64" |
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.
aarch64: https://godbolt.org/z/Mv4Y19jrM
x86: https://godbolt.org/z/WW19hMd6v
Perhaps we should disable this lint in kurbo.
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.
Huh. I guess clamp can't really be improved because of how its NaN behavior is specified.
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.
Seems that way! (As a separate note, we actually use some of the NaN semantics of the chained-min-max in the analytical pixel coverage calculation in the sparse strips work, so this lint can be a bit noisy.)
This is a branchless calculation of a point-onto-line-segment projection. Also marks the method `#[inline]`. I started looking at this because of the math we introduced in linebender/vello#1214. This might allow us to introduce some tighter bounds there without introducing additional branching. This should be useful here regardless of whether the above happens.
Co-authored-by: jneem <joeneeman@gmail.com>
fb967fb to
e8baf8a
Compare
Missed in #505.
This is a branchless calculation of a point-onto-line-segment projection. Also marks the method
#[inline]and adds some testing.I started looking at this because of the math we introduced in linebender/vello#1214. This might allow us to introduce some tighter bounds there without introducing additional branching.
This should be useful here regardless of whether the above happens.