From 9d6ed4af66e588cf7e9b45e397b53c80bacdc951 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 23 Feb 2015 11:49:36 -0800 Subject: [PATCH] [dev.cc] cmd/asm: add end to end test for amd64 Change-Id: I40839c2d1c0c105a5ba9aadcb55a13693bf4afa6 Reviewed-on: https://go-review.googlesource.com/5592 Reviewed-by: Russ Cox --- src/cmd/asm/internal/asm/endtoend_test.go | 4 + src/cmd/asm/internal/asm/testdata/amd64.out | 56 +++++++++++ src/cmd/asm/internal/asm/testdata/amd64.s | 93 +++++++++++++++++ src/cmd/asm/internal/asm/testdata/arm.out | 106 ++++++++++---------- src/cmd/asm/internal/asm/testdata/arm.s | 4 + src/cmd/asm/internal/asm/testdata/ppc64.s | 4 +- 6 files changed, 212 insertions(+), 55 deletions(-) create mode 100644 src/cmd/asm/internal/asm/testdata/amd64.out create mode 100644 src/cmd/asm/internal/asm/testdata/amd64.s diff --git a/src/cmd/asm/internal/asm/endtoend_test.go b/src/cmd/asm/internal/asm/endtoend_test.go index 5ee6e80d2b..de80563a7c 100644 --- a/src/cmd/asm/internal/asm/endtoend_test.go +++ b/src/cmd/asm/internal/asm/endtoend_test.go @@ -77,3 +77,7 @@ func TestPPC64EndToEnd(t *testing.T) { func TestARMEndToEnd(t *testing.T) { testEndToEnd(t, "arm") } + +func TestAMD64EndToEnd(t *testing.T) { + testEndToEnd(t, "amd64") +} diff --git a/src/cmd/asm/internal/asm/testdata/amd64.out b/src/cmd/asm/internal/asm/testdata/amd64.out new file mode 100644 index 0000000000..725c3dfa5d --- /dev/null +++ b/src/cmd/asm/internal/asm/testdata/amd64.out @@ -0,0 +1,56 @@ +5 00001 (testdata/amd64.s:5) TEXT foo+0(SB),$0 +8 00002 (testdata/amd64.s:8) NEGQ ,R11 +9 00003 (testdata/amd64.s:9) NEGQ ,4(R11) +10 00004 (testdata/amd64.s:10) NEGQ ,foo+4(SB) +13 00005 (testdata/amd64.s:13) INT $4, +14 00006 (testdata/amd64.s:14) DIVB R11, +15 00007 (testdata/amd64.s:15) DIVB 4(R11), +16 00008 (testdata/amd64.s:16) DIVB foo+4(SB), +19 00009 (testdata/amd64.s:19) SUBQ $4,DI +20 00010 (testdata/amd64.s:20) SUBQ R11,DI +21 00011 (testdata/amd64.s:21) SUBQ 4(R11),DI +22 00012 (testdata/amd64.s:22) SUBQ foo+4(SB),DI +23 00013 (testdata/amd64.s:23) SUBQ $4,8(R12) +24 00014 (testdata/amd64.s:24) SUBQ R11,8(R12) +25 00015 (testdata/amd64.s:25) SUBQ R11,foo+4(SB) +28 00016 (testdata/amd64.s:28) CMPB CX,$4 +32 00017 (testdata/amd64.s:32) JCS ,13(PC) +33 00018 (testdata/amd64.s:33) JCS ,17 +36 00019 (testdata/amd64.s:36) JMP ,15(PC) +37 00020 (testdata/amd64.s:37) JMP ,17 +38 00021 (testdata/amd64.s:38) JMP ,foo+4(SB) +39 00022 (testdata/amd64.s:39) JMP ,bar<>+4(SB) +40 00023 (testdata/amd64.s:40) JMP ,bar<>+4(SB)(R11*4) +41 00024 (testdata/amd64.s:41) JMP ,4(SP) +42 00025 (testdata/amd64.s:42) JMP ,(R12) +44 00026 (testdata/amd64.s:44) JMP ,(R12)(R13*4) +45 00027 (testdata/amd64.s:45) JMP ,(AX) +46 00028 (testdata/amd64.s:46) JMP ,(SP) +48 00029 (testdata/amd64.s:48) JMP ,(AX)(AX*4) +49 00030 (testdata/amd64.s:49) JMP ,4(SP) +50 00031 (testdata/amd64.s:50) JMP ,(R12) +52 00032 (testdata/amd64.s:52) JMP ,(R12)(R13*4) +53 00033 (testdata/amd64.s:53) JMP ,(AX) +54 00034 (testdata/amd64.s:54) JMP ,(SP) +56 00035 (testdata/amd64.s:56) JMP ,(AX)(AX*4) +57 00036 (testdata/amd64.s:57) JMP ,R13 +60 00037 (testdata/amd64.s:60) NOP , +61 00038 (testdata/amd64.s:61) NOP AX, +62 00039 (testdata/amd64.s:62) NOP foo+4(SB), +65 00040 (testdata/amd64.s:65) SHLL R11,R12 +66 00041 (testdata/amd64.s:66) SHLL R11,foo+4(SB) +67 00042 (testdata/amd64.s:67) SHLL R11,R11:AX +70 00043 (testdata/amd64.s:70) MOVL AX,R11 +71 00044 (testdata/amd64.s:71) MOVL $4,R11 +72 00045 (testdata/amd64.s:72) MOVL AX,AX:CS +75 00046 (testdata/amd64.s:75) IMULB $4, +76 00047 (testdata/amd64.s:76) IMULB R11, +77 00048 (testdata/amd64.s:77) IMULB $4,R11 +78 00049 (testdata/amd64.s:78) IMULB R11,R12 +79 00050 (testdata/amd64.s:79) IMULB R11,foo+4(SB) +82 00051 (testdata/amd64.s:82) CMPPD R11,$4,R12 +83 00052 (testdata/amd64.s:83) CMPPD R11,foo+4(SB) +86 00053 (testdata/amd64.s:86) PINSRW R11,$4,AX +87 00054 (testdata/amd64.s:87) PINSRW foo+4(SB),$4,AX +90 00055 (testdata/amd64.s:90) RETFL $4, +93 00056 (testdata/amd64.s:93) RET , diff --git a/src/cmd/asm/internal/asm/testdata/amd64.s b/src/cmd/asm/internal/asm/testdata/amd64.s new file mode 100644 index 0000000000..cb925f2475 --- /dev/null +++ b/src/cmd/asm/internal/asm/testdata/amd64.s @@ -0,0 +1,93 @@ +// This input was created by taking the instruction productions in +// the old assembler's (6a's) grammar and hand-writing complete +// instructions for each rule, to guarantee we cover the same space. + +TEXT foo(SB), 0, $0 + +// LTYPE1 nonrem { outcode($1, &$2); } + NEGQ R11 + NEGQ 4(R11) + NEGQ foo+4(SB) + +// LTYPE2 rimnon { outcode($1, &$2); } + INT $4 + DIVB R11 + DIVB 4(R11) + DIVB foo+4(SB) + +// LTYPE3 rimrem { outcode($1, &$2); } + SUBQ $4, DI + SUBQ R11, DI + SUBQ 4(R11), DI + SUBQ foo+4(SB), DI + SUBQ $4, 8(R12) + SUBQ R11, 8(R12) + SUBQ R11, foo+4(SB) + +// LTYPE4 remrim { outcode($1, &$2); } + CMPB CX, $4 + +// LTYPER nonrel { outcode($1, &$2); } +label: + JB -4(PC) + JB label + +// LTYPEC spec3 { outcode($1, &$2); } + JMP -4(PC) + JMP label + JMP foo+4(SB) + JMP bar<>+4(SB) + JMP bar<>+4(SB)(R11*4) + JMP *4(SP) + JMP *(R12) + JMP *(R12*4) + JMP *(R12)(R13*4) + JMP *(AX) + JMP *(SP) + JMP *(AX*4) + JMP *(AX)(AX*4) + JMP 4(SP) + JMP (R12) + JMP (R12*4) + JMP (R12)(R13*4) + JMP (AX) + JMP (SP) + JMP (AX*4) + JMP (AX)(AX*4) + JMP R13 + +// LTYPEN spec4 { outcode($1, &$2); } + NOP + NOP AX + NOP foo+4(SB) + +// LTYPES spec5 { outcode($1, &$2); } + SHLL R11, R12 + SHLL R11, foo+4(SB) + SHLL R11, R11:AX + +// LTYPEM spec6 { outcode($1, &$2); } + MOVL AX, R11 + MOVL $4, R11 + MOVL AX, AX:CS + +// LTYPEI spec7 { outcode($1, &$2); } + IMULB $4 + IMULB R11 + IMULB $4, R11 + IMULB R11, R12 + IMULB R11, foo+4(SB) + +// LTYPEXC spec8 { outcode($1, &$2); } + CMPPD R11, R12, 4 + CMPPD R11, foo+4(SB), 4 + +// LTYPEX spec9 { outcode($1, &$2); } + PINSRW $4, R11, AX + PINSRW $4, foo+4(SB), AX + +// LTYPERT spec10 { outcode($1, &$2); } + RETFL $4 + +// LTYPE0 nonnon { outcode($1, &$2); } + RET diff --git a/src/cmd/asm/internal/asm/testdata/arm.out b/src/cmd/asm/internal/asm/testdata/arm.out index 88309bd5a4..7728e09a45 100644 --- a/src/cmd/asm/internal/asm/testdata/arm.out +++ b/src/cmd/asm/internal/asm/testdata/arm.out @@ -1,53 +1,53 @@ -1 00001 (testdata/arm.s:1) TEXT foo+0(SB),0,$0 -10 00002 (testdata/arm.s:10) ADD $1,R2,R3 -11 00003 (testdata/arm.s:11) ADD R1<>R2,R3,R4 -13 00005 (testdata/arm.s:13) ADD R1@>R2,R3,R4 -14 00006 (testdata/arm.s:14) ADD R1->R2,R3,R4 -15 00007 (testdata/arm.s:15) ADD R1,R2,R3 -16 00008 (testdata/arm.s:16) ADD R1<>R2,R3 -29 00012 (testdata/arm.s:29) ADD R1@>R2,R3 -30 00013 (testdata/arm.s:30) ADD R1->R2,R3 -31 00014 (testdata/arm.s:31) ADD R1,R2 -40 00015 (testdata/arm.s:40) CLZ.S R1,R2 -49 00016 (testdata/arm.s:49) MOVW.S R1,R2 -50 00017 (testdata/arm.s:50) MOVW.S $1,R2 -51 00018 (testdata/arm.s:51) MOVW.S R1<+0(SB) -77 00023 (testdata/arm.s:77) BX 0(R2), -86 00024 (testdata/arm.s:86) BEQ ,25(PC) -95 00025 (testdata/arm.s:95) SWI.S ,R1 -96 00026 (testdata/arm.s:96) SWI.S ,0(R1) -97 00027 (testdata/arm.s:97) SWI.S ,foo+0(SB) -106 00028 (testdata/arm.s:106) CMP.S $1,R2, -107 00029 (testdata/arm.s:107) CMP.S R1<>R2,R3,R4 +17 00005 (testdata/arm.s:17) ADD R1@>R2,R3,R4 +18 00006 (testdata/arm.s:18) ADD R1->R2,R3,R4 +19 00007 (testdata/arm.s:19) ADD R1,R2,R3 +20 00008 (testdata/arm.s:20) ADD R1<>R2,R3 +33 00012 (testdata/arm.s:33) ADD R1@>R2,R3 +34 00013 (testdata/arm.s:34) ADD R1->R2,R3 +35 00014 (testdata/arm.s:35) ADD R1,R2 +44 00015 (testdata/arm.s:44) CLZ.S R1,R2 +53 00016 (testdata/arm.s:53) MOVW.S R1,R2 +54 00017 (testdata/arm.s:54) MOVW.S $1,R2 +55 00018 (testdata/arm.s:55) MOVW.S R1<+0(SB) +81 00023 (testdata/arm.s:81) BX 0(R2), +90 00024 (testdata/arm.s:90) BEQ ,25(PC) +99 00025 (testdata/arm.s:99) SWI.S ,R1 +100 00026 (testdata/arm.s:100) SWI.S ,0(R1) +101 00027 (testdata/arm.s:101) SWI.S ,foo+0(SB) +110 00028 (testdata/arm.s:110) CMP.S $1,R2, +111 00029 (testdata/arm.s:111) CMP.S R1<