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

runtime: better support for 64bit div/mod operations on 32bit platforms #19509

Open
martisch opened this issue Mar 11, 2017 · 5 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Milestone

Comments

@martisch
Copy link
Contributor

encountered in https://go-review.googlesource.com/c/38071/:

assuming x and y are uint64:

q = x/y 
r = x%y

only uses a single DIV instruction on amd64 however on 386 this makes a runtime call to
uint64div and one to uint64mod.

  1. Both could be handled calculated together in a combined uint64divmod runtime call
  2. In case y is constant the compiler could optimize the calculation to not require a div and not need a runtime call
@martisch martisch added this to the Go1.9Maybe milestone Mar 11, 2017
@martisch
Copy link
Contributor Author

If these optimizations sound reasonable i can work on this for 1.9/1.10 after i have my current projects for 1.9 are submitted.

@josharian
Copy link
Contributor

Both could be handled calculated together in a combined uint64divmod runtime call

SGTM. We even already have this, although it's called dodiv at the moment.

In case y is constant the compiler could optimize the calculation to not require a div and not need a runtime call

The compiler should already do this. Worth double-checking, though.

@josharian
Copy link
Contributor

It's probably also work taking a brief look at the code that the compiler generates for vlrt.go. It was tuned for the old backend.

@martisch
Copy link
Contributor Author

about 2. I checked before and after the issue creation :)

The compiler does not simplify a div with 64bit operands on 32bit:

var x uint64

func main() {
	y := x / 10
	print(y)
}

uses a "CALL runtime.uint64div(SB)"

@josharian
Copy link
Contributor

:) I see.

Both seem worth fixing, then.

Independently, I wonder whether it's worth adding an int32 code path, where we do all the work with int32s instead of int64s, for values that fit in 32 bits (which is probably almost all of them in practice). Might even be cheaper on 64 bit machines. Probably worth a benchmarking experiment.

@bradfitz bradfitz modified the milestones: Go1.9Maybe, Go1.10 Jul 20, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@bradfitz bradfitz modified the milestones: Go1.11, Unplanned May 18, 2018
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Projects
None yet
Development

No branches or pull requests

5 participants