Skip to content
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

math/big: avoid DIVQ #9246

Open
griesemer opened this Issue Dec 10, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@griesemer
Copy link
Contributor

griesemer commented Dec 10, 2014

Suggested by Torbjörn Granlund (personal communication):

"
Division:

The DIVQ instruction is terrible. Don't ever use it. You might
want to take a look at "Improved Division by Invariant Integers" by
me and a collegue of mine. Your loop will become about 10 times
faster. You need to apply this also to generic division (not just the
one-divisor-word case.
"

(paper reference: https://gmplib.org/~tege/division-paper.pdf)

@griesemer griesemer self-assigned this Dec 10, 2014

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Dec 10, 2014

The Go compiler already does this. If you want to know the sequence, write
a program with a constant divide and use go tool 6g -S.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Dec 10, 2014

I think the suggestion here is to do it when dividing in a loop by an invariant value that is only known at run time.

@griesemer

This comment has been minimized.

Copy link
Contributor Author

griesemer commented Dec 10, 2014

Ok, good to know. Note that Torbjörn's paper suggests that even for a non-constant divisor, division via mutiplication by inverse is faster:

"Somewhat surprisingly, a well-tuned Newton reciprocal followed by multiplication and adjustments wins over the hardware division instructions even for a single non-invariant division on modern 64-bit PC processors."

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed release-none labels Apr 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.