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: incorrect assembly of CMP Rn,$0 on ppc64le/ppc64 #14532

Closed
laboger opened this issue Feb 26, 2016 · 7 comments
Closed

cmd: incorrect assembly of CMP Rn,$0 on ppc64le/ppc64 #14532

laboger opened this issue Feb 26, 2016 · 7 comments

Comments

@laboger
Copy link
Contributor

laboger commented Feb 26, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go 1.6
  2. What operating system and processor architecture are you using (go env)?
    linux ppc64le
  3. What did you do?
    I'm working on updating some asm file changes to improve performance on ppc64le. I see many
    files that contain CMP Ra,$0 that generate the wrong ppc64 assembler. I'm guessing that the contents of r0 is usually 0 and that is allowing these to work by luck.
  4. What did you expect to see?
    For an ASM like this:
    CMP R3,$0
    the code should be
    cmpdi r3,0
  5. What did you see instead?
    cmpd r3,r0

This is from an objdump:

TEXT runtime·memeqbody(SB),NOSPLIT,$0-0
......
CMPU R5,$0
757ac: 40 00 25 7c cmpld r5,r0

However if the value is not 0, then it assembles correctly

    CMP     R5,$32      

757b4: 20 00 25 2c cmpdi r5,32

@ianlancetaylor
Copy link
Contributor

On PPC r0 always contains 0 by definition (that is, it is not a real register). I think this is working as intended.

@minux
Copy link
Member

minux commented Feb 26, 2016

Yeah, R0 is always 0 in the Go ABI.

@laboger
Copy link
Contributor Author

laboger commented Feb 26, 2016

And what happens when Go code calls C code built by gcc where it is not always 0? Does it reinitialize it when it returns?

@mwhudson
Copy link
Contributor

On 27/02/2016 8:44 am, "laboger" notifications@github.com wrote:

And what happens when Go code calls C code built by gcc where it is not
always 0? Does it reinitialize it when it returns?

Yes.

@laboger
Copy link
Contributor Author

laboger commented Feb 26, 2016

Thanks for the responses.

@laboger laboger closed this as completed Feb 26, 2016
@peter-bergner
Copy link

ianlancetaylor wrote:

On PPC r0 always contains 0 by definition (that is, it is not a real register).

To be pedantic, r0 is a real register and can contain non-zero data. In fact, we use r0 as a scratch register in GCC all the time, as well as when we save/restore the link register in the prologue/epilogue.

That said, there are instructions where the contents of r0 are ignored and the value zero is used instead. For example, the base register in load and store instructions and addi and addis, etc. but only if r0 is the RA operand. If r0 isn't reset whenever r0 is used like calling non GO routines (eg, C), or whenever making syscalls (r0 holds the syscall number), then you can't guarantee that r0 is zero.

@minux
Copy link
Member

minux commented Feb 26, 2016 via email

@golang golang locked and limited conversation to collaborators Feb 28, 2017
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

6 participants