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/arm: Wrongly Assembled ARM Branch Instructions #19419

Closed
benshi001 opened this issue Mar 6, 2017 · 5 comments
Closed

cmd/internal/obj/arm: Wrongly Assembled ARM Branch Instructions #19419

benshi001 opened this issue Mar 6, 2017 · 5 comments

Comments

@benshi001
Copy link
Member

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

the newest master branch

What operating system and processor architecture are you using (go env)?

ARM//Raspberry Pi 2/Debian

What did you do?

Add 2 test for BEQ in cmd/asm/internal/asm/testdata/arm.s

jmp_label:
BEQ jmp_label
BEQ 8(PC)

What did you expect to see?

The test pass when running src/all.bash

What did you see instead?

02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
02024 (testdata/arm.s:749) BEQ
--- FAIL: TestARMEndToEnd (0.04s)
endtoend_test.go:363: GOARM=5
endtoend_test.go:149: mismatched output:
have 00498 (testdata/arm.s:748) BEQ
want 00498 (testdata/arm.s:748) BEQ jmp_label
endtoend_test.go:179: branch out of range (0x1fb)
00499 (testdata/arm.s:749) BEQ 507(PC) []
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:363: GOARM=6
endtoend_test.go:149: mismatched output:
have 00498 (testdata/arm.s:748) BEQ
want 00498 (testdata/arm.s:748) BEQ jmp_label
endtoend_test.go:179: branch out of range (0x1fb)
00499 (testdata/arm.s:749) BEQ 507(PC) []
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:363: GOARM=7
endtoend_test.go:149: mismatched output:
have 00498 (testdata/arm.s:748) BEQ
want 00498 (testdata/arm.s:748) BEQ jmp_label
endtoend_test.go:179: branch out of range (0x1fb)
00499 (testdata/arm.s:749) BEQ 507(PC) []
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
endtoend_test.go:179: illegal combination 02024 (testdata/arm.s:749) BEQ; NONE NONE NONE, 0 0
endtoend_test.go:179: from 0 0 to 0 0
FAIL
FAIL cmd/asm/internal/asm 0.233s

@cherrymui
Copy link
Member

endtoend_test.go:179: branch out of range (0x1fb)

Did you add them to the end of the file? Then 8(PC) will be out of range. Maybe try something like 0(PC)?

@benshi001 benshi001 changed the title cmd/asm/internal/asm/testdata/arm.s: Failure of test of legal ARM instructions cmd/asm/internal: Wrong encoded B* instructions Mar 7, 2017
@benshi001
Copy link
Member Author

The out of range warning is eliminated, but it seems wrong code is assembled.

With
BEQ 14(PC) // 0c00000a
BNE 13(PC) // 0b00001a
BCS 12(PC) // 0a00002a
BCC 11(PC) // 0900003a
BMI 10(PC) // 0800004a
BPL 9(PC) // 0700005a
BVS 8(PC) // 0600006a
BVC 7(PC) // 0500007a
BHI 6(PC) // 0400008a
BLS 5(PC) // 0300009a
BGE 4(PC) // 020000aa
BLT 3(PC) // 010000ba
BGT 2(PC) // 000000ca
BLE 1(PC) // ffffffda
B 0(PC) // feffffea

I get error like

endtoend_test.go:221: 02020 (testdata/arm.s:747)	BEQ	2076: have encoding feffff0a, want 0c00000a
endtoend_test.go:221: 02024 (testdata/arm.s:748)	BNE	2076: have encoding feffff1a, want 0b00001a
endtoend_test.go:221: 02028 (testdata/arm.s:749)	BCS	2076: have encoding feffff2a, want 0a00002a
endtoend_test.go:221: 02032 (testdata/arm.s:750)	BCC	2076: have encoding feffff3a, want 0900003a
endtoend_test.go:221: 02036 (testdata/arm.s:751)	BMI	2076: have encoding feffff4a, want 0800004a
endtoend_test.go:221: 02040 (testdata/arm.s:752)	BPL	2076: have encoding feffff5a, want 0700005a
endtoend_test.go:221: 02044 (testdata/arm.s:753)	BVS	2076: have encoding feffff6a, want 0600006a
endtoend_test.go:221: 02048 (testdata/arm.s:754)	BVC	2076: have encoding feffff7a, want 0500007a
endtoend_test.go:221: 02052 (testdata/arm.s:755)	BHI	2076: have encoding feffff8a, want 0400008a
endtoend_test.go:221: 02056 (testdata/arm.s:756)	BLS	2076: have encoding feffff9a, want 0300009a
endtoend_test.go:221: 02060 (testdata/arm.s:757)	BGE	2076: have encoding feffffaa, want 020000aa
endtoend_test.go:221: 02064 (testdata/arm.s:758)	BLT	2076: have encoding feffffba, want 010000ba
endtoend_test.go:221: 02068 (testdata/arm.s:759)	BGT	2076: have encoding feffffca, want 000000ca
endtoend_test.go:221: 02072 (testdata/arm.s:760)	BLE	2076: have encoding feffffda, want ffffffda

@benshi001 benshi001 changed the title cmd/asm/internal: Wrong encoded B* instructions cmd/internal/obj/arm: Wrongly Assembled ARM Branch Instructions Mar 7, 2017
@benshi001
Copy link
Member Author

It seems B* instructions will be mis-assembled when jumping forward, but correct jumping backward.

Here is my test case in cmd/src/asm/internal/asm/testdata/arm.s

    BEQ     14(PC) // BEQ 14(PC)   // 0c00000a
    BNE     13(PC) // BNE 13(PC)   // 0b00001a
    BCS     12(PC) // BCS 12(PC)   // 0a00002a
    BCC     11(PC) // BCC 11(PC)   // 0900003a
    BMI     10(PC) // BMI 10(PC)   // 0800004a
    BPL     9(PC)  // BPL 9(PC)    // 0700005a
    BVS     8(PC)  // BVS 8(PC)    // 0600006a
    BVC     7(PC)  // BVC 7(PC)    // 0500007a
    BHI     6(PC)  // BHI 6(PC)    // 0400008a
    BLS     5(PC)  // BLS 5(PC)    // 0300009a
    BGE     4(PC)  // BGE 4(PC)    // 020000aa
    BLT     3(PC)  // BLT 3(PC)    // 010000ba
    BGT     2(PC)  // BGT 2(PC)    // 000000ca
    BLE     1(PC)  // BLE 1(PC)    // ffffffda
    B       0(PC)  // JMP 0(PC)    // feffffea
    B       -1(PC) // JMP -1(PC)   // fdffffea
    B       -2(PC) // JMP -2(PC)   // fcffffea
    B       -3(PC) // JMP -3(PC)   // fbffffea
    B       -4(PC) // JMP -4(PC)   // faffffea
    B       -5(PC) // JMP -5(PC)   // f9ffffea
    BNE     jmp_label_0 // BNE     // 010000ea
    BNE     jmp_label_0 // BNE     // 000000ea
    BNE     jmp_label_0 // BNE     // ffffffea

jmp_label_0:
B jmp_label_0 // JMP // feffffea
BEQ jmp_label_0 // BEQ 521 // fdffff0a
BNE jmp_label_0 // BNE 521 // fcffff1a
BCS jmp_label_0 // BCS 521 // fbffff2a
BCC jmp_label_0 // BCC 521 // faffff3a
BMI jmp_label_0 // BMI 521 // f9ffff4a
BPL jmp_label_0 // BPL 521 // f8ffff5a
BVS jmp_label_0 // BVS 521 // f7ffff6a
BVC jmp_label_0 // BVC 521 // f6ffff7a
BHI jmp_label_0 // BHI 521 // f5ffff8a
BLS jmp_label_0 // BLS 521 // f4ffff9a
BGE jmp_label_0 // BGE 521 // f3ffffaa
BLT jmp_label_0 // BLT 521 // f2ffffba
BGT jmp_label_0 // BGT 521 // f1ffffca
BLE jmp_label_0 // BLE 521 // f0ffffda
B jmp_label_0 // JMP 521 // efffffea

I got
endtoend_test.go:221: 02020 (testdata/arm.s:747) BEQ 2076: have encoding feffff0a, want 0c00000a
endtoend_test.go:221: 02024 (testdata/arm.s:748) BNE 2076: have encoding feffff1a, want 0b00001a
endtoend_test.go:221: 02028 (testdata/arm.s:749) BCS 2076: have encoding feffff2a, want 0a00002a
endtoend_test.go:221: 02032 (testdata/arm.s:750) BCC 2076: have encoding feffff3a, want 0900003a
endtoend_test.go:221: 02036 (testdata/arm.s:751) BMI 2076: have encoding feffff4a, want 0800004a
endtoend_test.go:221: 02040 (testdata/arm.s:752) BPL 2076: have encoding feffff5a, want 0700005a
endtoend_test.go:221: 02044 (testdata/arm.s:753) BVS 2076: have encoding feffff6a, want 0600006a
endtoend_test.go:221: 02048 (testdata/arm.s:754) BVC 2076: have encoding feffff7a, want 0500007a
endtoend_test.go:221: 02052 (testdata/arm.s:755) BHI 2076: have encoding feffff8a, want 0400008a
endtoend_test.go:221: 02056 (testdata/arm.s:756) BLS 2076: have encoding feffff9a, want 0300009a
endtoend_test.go:221: 02060 (testdata/arm.s:757) BGE 2076: have encoding feffffaa, want 020000aa
endtoend_test.go:221: 02064 (testdata/arm.s:758) BLT 2076: have encoding feffffba, want 010000ba
endtoend_test.go:221: 02068 (testdata/arm.s:759) BGT 2076: have encoding feffffca, want 000000ca
endtoend_test.go:221: 02072 (testdata/arm.s:760) BLE 2076: have encoding feffffda, want ffffffda
endtoend_test.go:221: 02100 (testdata/arm.s:767) BNE 2112: have encoding feffff1a, want 010000ea
endtoend_test.go:221: 02104 (testdata/arm.s:768) BNE 2112: have encoding feffff1a, want 000000e
endtoend_test.go:221: 02108 (testdata/arm.s:769) BNE 2112: have encoding feffff1a, want ffffffea

All failures are related to forward jump in both "B off(PC)" and "B label" forms.

@benshi001
Copy link
Member Author

benshi001 commented Mar 10, 2017

But what's more strange, I find many forward jumps in src/runtime/vlop_arm.s, especially divu which is used widely as the division implementation of ARM.

Where is wrong in my test or understand?

@benshi001
Copy link
Member Author

It is my mistake, I am not familiar with the assembler's features.

@golang golang locked and limited conversation to collaborators Mar 10, 2018
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