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
Labels

Comments

@josharian
Copy link
Contributor

@josharian josharian commented Mar 1, 2020

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

@randall77 randall77 commented Mar 1, 2020

How would you do that, exactly?

@josharian
Copy link
Contributor Author

@josharian josharian commented Mar 1, 2020

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

@randall77 randall77 commented Mar 1, 2020

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

@josharian josharian commented Mar 1, 2020

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

@josharian josharian closed this Mar 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.