Skip to content

Magic division by constant for OptimizeForJS. Does it make sense? #4054

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

Closed
MaxGraey opened this issue Aug 4, 2021 · 3 comments
Closed

Magic division by constant for OptimizeForJS. Does it make sense? #4054

MaxGraey opened this issue Aug 4, 2021 · 3 comments

Comments

@MaxGraey
Copy link
Contributor

MaxGraey commented Aug 4, 2021

I'm working on a new rule for OptimizeForJS that optimizes the division / modulo by constant for 64-bit types. Since for this particular case it is too expensive to call and execute a helper (polyfill) function for full division. According to my simple tests this gives up to 7x performance gain if the high part of dividend is not zero. The PR will come out pretty huge, so I'm wondering if it's worth it.

Rule will rewrite this i64(x) / C to something like this in simplified form mulh64(x, mag.M) >> mag.S

@tlively
Copy link
Member

tlively commented Aug 4, 2021

This sounds fairly straightforward, but I don't understand everything involved. What will make the PR large?

@MaxGraey
Copy link
Contributor Author

MaxGraey commented Aug 4, 2021

See #4055. It's just half of PR

@MaxGraey
Copy link
Contributor Author

MaxGraey commented Aug 5, 2021

So I expect it will be 1000-1200 LOCs including lit tests.

@MaxGraey MaxGraey changed the title Magic division by constant for OptimizeForJS. Doe it makes sense? Magic division by constant for OptimizeForJS. Does it make sense? Aug 5, 2021
@MaxGraey MaxGraey closed this as completed Aug 5, 2022
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 a pull request may close this issue.

2 participants