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

cmd/compile: use some partial register instructions on amd64? #37593

Closed
josharian opened this issue Mar 1, 2020 · 4 comments
Closed

cmd/compile: use some partial register instructions on amd64? #37593

josharian opened this issue Mar 1, 2020 · 4 comments

Comments

@josharian
Copy link
Contributor

This is the standard way to check whether a value is 32 bit:

func is32bit(x int64) bool {
	return x == int64(int32(x))
}

On amd64, this compiles to a MOVLQSX and a CMPQ. However, it could compile to just a TESTL of the top half of the register.

Is there a reason that we don't have any optimizations like this, other than that no one has bothered to write any yet?

@randall77
Copy link
Contributor

How would you do that, exactly?

@josharian
Copy link
Contributor Author

I haven’t written the code to check that this actually works, but something like:

Add OpAMD64TESTLU (U for upper), which takes a reg and generates flags.

Add a rewrite rule for the pattern above.

During instruction generation, emit a TESTL that refers to the top half of the register assigned by regalloc.

@randall77
Copy link
Contributor

I didn't know you could do that.
The only instructions I know that access the non-lowest part of an integer register are the byte operations that access AH, BH, CH, DH (bits 8-15).

Even if such an instruction exists, I don't see how you would use it. We need to test that bits 32-63 match bit 31. How would you factor bit 31 into the equation? (x == int64(uint32(x)) might be doable, though.)

@josharian
Copy link
Contributor Author

Oh. I see now I misinterpreted something I read. Never mind. Nothing to see here. 🐑

@golang golang locked and limited conversation to collaborators Mar 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants