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/vet: incorrect complaint about PEXTRD instruction #15271

Closed
jacobsa opened this issue Apr 13, 2016 · 6 comments

Comments

Projects
None yet
5 participants
@jacobsa
Copy link
Contributor

commented Apr 13, 2016

This gist contains a program that prints 123. The value is generated by this assembly function:

// func foo() (x uint32)
TEXT ·foo(SB), NOSPLIT, $0-4
    // Stick 123 into the low 32 bits of X0.
    MOVQ $123, AX
    PINSRD $0, AX, X0

    // Return them.
    PEXTRD $0, X0, x+0(FP)
    RET

Indeed the program works correctly:

% go build -o /tmp/baz ./baz && /tmp/baz
123

However, go vet is unhappy about the PEXTRD instruction:

% go vet ./baz
baz/baz.s:12: [amd64] foo: invalid PEXTRD of x+0(FP); uint32 is 4-byte value
exit status 1

I don't understand what it's trying to tell me here. PEXTRD is supposed to operate on 4-byte values, as far as I understand it.

I tried using PEXTRL instead, but the assembler says it doesn't exist. (I don't understand why sometimes I can use both L/D, e.g. MOVL and MOVD, and other times I can't.)

I'm using Go 1.6 on linux/amd64.

@bradfitz bradfitz added this to the Unplanned milestone Apr 13, 2016

@bradfitz

This comment has been minimized.

Copy link
Member

commented Apr 13, 2016

/cc @robpike

@robpike

This comment has been minimized.

Copy link
Contributor

commented Apr 13, 2016

Sending to @rsc, owner of the assembly checker.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 14, 2016

CL https://golang.org/cl/22083 mentions this issue.

@gopherbot gopherbot closed this in 67cdec0 Apr 14, 2016

@jacobsa

This comment has been minimized.

Copy link
Contributor Author

commented Apr 14, 2016

@josharian: Thanks for the fix! (And now I know where to look if I want to fix it myself next time.) Is this going to come up again for PEXTRB and PEXTRW?

(Also do you happen to know the answer to my implicit question above about why I can say MOVL or MOVD, but I can't say PEXTRL?)

@josharian

This comment has been minimized.

Copy link
Contributor

commented Apr 14, 2016

And now I know where to look if I want to fix it myself next time.

Excellent. :)

Is this going to come up again for PEXTRB and PEXTRW?

I don't think so; vet should correctly interpret the trailing B and W already.

(Also do you happen to know the answer to my implicit question above about why I can say MOVL or MOVD, but I can't say PEXTRL?)

The assembly language is not particularly well-defined. The assembler works (more or less) off the list of internal instruction names (see e.g. cmd/internal/obj/x86/anames.go). Those internal instruction names mostly match a well-defined pattern. PEXTRD doesn't fit that pattern; it sticks closer to x86 speak.

In a few important cases like the various Jxx mnemonics (JAE, JCC, JHI, etc.), there are synonyms. We could teach the assembler that PEXTRL is a synonym for PEXTRD. (Or we could rename PEXTRD to PEXTRL, but that'll break existing code unnecessarily.) It's not technically challenging to add synonyms, but it does contribute to sprawl. If you think we should add a synonym, please file a new issue and cc @robpike, who should probably make that call.

Hope that all makes sense.

@jacobsa

This comment has been minimized.

Copy link
Contributor Author

commented Apr 14, 2016

Thanks, it does make sense.

@golang golang locked and limited conversation to collaborators Apr 15, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.