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/internal/obj/x86: automatically fix CMPL argument order #10199

Closed
josharian opened this issue Mar 19, 2015 · 4 comments
Closed

cmd/internal/obj/x86: automatically fix CMPL argument order #10199

josharian opened this issue Mar 19, 2015 · 4 comments

Comments

@josharian
Copy link
Contributor

CL 7697 caused doasm failures on 386:

runtime/append_test.go:1: doasm: notfound ft=2 tt=20 00112 (runtime/iface_test.go:207)  CMPL    $0, BX 2 20

I worked around the problem by reversing the order of the arguments during walk (CL 7810), but that's not the right fix. CMPL is symmetric, so liblink should gracefully generate CMPL BX, $0 instead.

@randall77
Copy link
Contributor

CMPL is symmetric only if you're using EQ/NE on the result.

I think liblink is right, x86 can only compare with a constant in one direction. Try compiling this with gcc (as a .s file):
cmpq $0, %rax
cmpq %rax, $0
The second one fails. at&t ordering syntax is weird, I can't be sure if that second one corresponds to your error. In any case, maybe something upstream of liblink needs to make sure the order is correct, and if not swap the order and the sense of all the LT/LE/GT/GE that use it?

@josharian
Copy link
Contributor Author

Umm, right, thanks. Brrev already knows how to swap comparison order. It looks like the right place for this fix might be bgen, in 8g/cgen.go. Russ has said that he's going to make a lot of this code portable soon, so now might not be the right time to touch it. The workaround is ugly, but it works for now.

@josharian josharian changed the title liblink: handle CMPL $0, BX on 386 8g: automatically fix CMPL argument order Mar 19, 2015
@josharian josharian changed the title 8g: automatically fix CMPL argument order cmd/8g: automatically fix CMPL argument order Mar 19, 2015
@minux
Copy link
Member

minux commented Mar 19, 2015 via email

@robpike robpike changed the title cmd/8g: automatically fix CMPL argument order obj/x86: automatically fix CMPL argument order Mar 21, 2015
@mikioh mikioh changed the title obj/x86: automatically fix CMPL argument order cmd/.../obj/x86: automatically fix CMPL argument order Mar 22, 2015
@rsc
Copy link
Contributor

rsc commented Apr 10, 2015

It cannot be automatically fixed.

There is only one position the constant can go in, and if you swap them it screws up later comparisons. The calling code must be careful to put the constant in the right place, and that's all we can do.

@rsc rsc changed the title cmd/.../obj/x86: automatically fix CMPL argument order cmd/internal/obj/x86: automatically fix CMPL argument order Apr 10, 2015
@rsc rsc closed this as completed Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

5 participants