Skip to content

libm: optimize fmod #1002

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

quaternic
Copy link
Contributor

@quaternic quaternic commented Aug 1, 2025

This is kind of a retry at #898. One of the problems there was that it would have added overhead and regressed performance for typical inputs.

Unlike that PR, this doesn't aim for sub-linear scaling; the cost of evaluating fmod(x, y) is still roughly proportional to log2(|x/y|). However, the constant factor is much better. Running the random-benchmarks locally, I got walltime reductions of

fmodf16:  -56.9%
fmodf:    -85.0%
fmod:     -95.4%
fmodf128: -98.7%

Needs #1011 and #1012

@tgross35
Copy link
Contributor

Sorry I haven't reviewed yet; I am excited about this but have been a bit short on time.

Any chance you're willing to commits to separate PRs? From a quick glance the first two look good, but I'll need a bit more time for the last one.

fmodf128: -98.7%

Seriously impressive :)

@quaternic
Copy link
Contributor Author

Yeah, I probably should have split it. I'm not home at this time, but I'll try to do that on Tuesday.

If possible, could you run the walltime benchmarks on something non-x86?

@quaternic quaternic changed the title Optimize fmod with a method using integer multiplication libm: optimize fmod Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants