Skip to content

Commit b41bfd5

Browse files
benshi001cherrymui
authored andcommitted
arm/armasm: rename VLDR/VSTR in plan9 syntax
Some load/store instructions are renamed in plan9 syntax, such as LDR -> MOVW STR -> MOVW LDRB -> MOVBU LDRSB -> MOVBS STRB -> MOVB LDRH -> MOVHU LDRSH -> MOVSH STRH -> MOVH And VLDR/VSTR also need to be renamed. VLDR.F32 -> MOVF (load from memory to single FP register) VLDR.F64 -> MOVD (load from memory to double FP register) VSTR.F32 -> MOVF (store single FP register to memory) VSTR.F64 -> MOVD (store double FP register to memory) This patch fixes this issue and adds corresponding tests. fixes golang/go#20897 Change-Id: I03aaad6379fa6f7c9b808d6a4795a06299fb7a18 Reviewed-on: https://go-review.googlesource.com/47360 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 28b9d4b commit b41bfd5

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

arm/armasm/plan9x.go

+48-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/binary"
1010
"fmt"
1111
"io"
12+
"math"
1213
"strings"
1314
)
1415

@@ -37,7 +38,7 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64), text
3738
op := inst.Op.String()
3839

3940
switch inst.Op &^ 15 {
40-
case LDR_EQ, LDRB_EQ, LDRH_EQ, LDRSB_EQ, LDRSH_EQ:
41+
case LDR_EQ, LDRB_EQ, LDRH_EQ, LDRSB_EQ, LDRSH_EQ, VLDR_EQ:
4142
// Check for RET
4243
reg, _ := inst.Args[0].(Reg)
4344
mem, _ := inst.Args[1].(Mem)
@@ -48,7 +49,7 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64), text
4849
// Check for PC-relative load.
4950
if mem.Base == PC && mem.Sign == 0 && mem.Mode == AddrOffset && text != nil {
5051
addr := uint32(pc) + 8 + uint32(mem.Offset)
51-
buf := make([]byte, 4)
52+
buf := make([]byte, 8)
5253
switch inst.Op &^ 15 {
5354
case LDRB_EQ, LDRSB_EQ:
5455
if _, err := text.ReadAt(buf[:1], int64(addr)); err != nil {
@@ -63,7 +64,7 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64), text
6364
args[1] = fmt.Sprintf("$%#x", binary.LittleEndian.Uint16(buf))
6465

6566
case LDR_EQ:
66-
if _, err := text.ReadAt(buf, int64(addr)); err != nil {
67+
if _, err := text.ReadAt(buf[:4], int64(addr)); err != nil {
6768
break
6869
}
6970
x := binary.LittleEndian.Uint32(buf)
@@ -72,14 +73,30 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64), text
7273
} else {
7374
args[1] = fmt.Sprintf("$%#x", x)
7475
}
76+
77+
case VLDR_EQ:
78+
switch {
79+
case strings.HasPrefix(args[0], "D"): // VLDR.F64
80+
if _, err := text.ReadAt(buf, int64(addr)); err != nil {
81+
break
82+
}
83+
args[1] = fmt.Sprintf("$%f", math.Float64frombits(binary.LittleEndian.Uint64(buf)))
84+
case strings.HasPrefix(args[0], "S"): // VLDR.F32
85+
if _, err := text.ReadAt(buf[:4], int64(addr)); err != nil {
86+
break
87+
}
88+
args[1] = fmt.Sprintf("$%f", math.Float32frombits(binary.LittleEndian.Uint32(buf)))
89+
default:
90+
panic(fmt.Sprintf("wrong FP register: %v", inst))
91+
}
7592
}
7693
}
7794
}
7895

7996
// Move addressing mode into opcode suffix.
8097
suffix := ""
8198
switch inst.Op &^ 15 {
82-
case LDR_EQ, LDRB_EQ, LDRSB_EQ, LDRH_EQ, LDRSH_EQ, STR_EQ, STRB_EQ, STRH_EQ:
99+
case LDR_EQ, LDRB_EQ, LDRSB_EQ, LDRH_EQ, LDRSH_EQ, STR_EQ, STRB_EQ, STRH_EQ, VLDR_EQ, VSTR_EQ:
83100
mem, _ := inst.Args[1].(Mem)
84101
switch mem.Mode {
85102
case AddrOffset, AddrLDM:
@@ -133,6 +150,19 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64), text
133150
op = "MOVHU" + op[4:] + suffix
134151
case LDRSH_EQ:
135152
op = "MOVHS" + op[5:] + suffix
153+
case VLDR_EQ:
154+
switch {
155+
case strings.HasPrefix(args[1], "D"): // VLDR.F64
156+
op = "MOVD" + op[4:] + suffix
157+
args[1] = "F" + args[1][1:] // Dx -> Fx
158+
case strings.HasPrefix(args[1], "S"): // VLDR.F32
159+
op = "MOVF" + op[4:] + suffix
160+
if inst.Args[0].(Reg)&1 == 0 { // Sx -> Fy, y = x/2, if x is even
161+
args[1] = fmt.Sprintf("F%d", (inst.Args[0].(Reg)-S0)/2)
162+
}
163+
default:
164+
panic(fmt.Sprintf("wrong FP register: %v", inst))
165+
}
136166

137167
case STR_EQ:
138168
op = "MOVW" + op[3:] + suffix
@@ -143,6 +173,20 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64), text
143173
case STRH_EQ:
144174
op = "MOVH" + op[4:] + suffix
145175
args[0], args[1] = args[1], args[0]
176+
case VSTR_EQ:
177+
switch {
178+
case strings.HasPrefix(args[1], "D"): // VSTR.F64
179+
op = "MOVD" + op[4:] + suffix
180+
args[1] = "F" + args[1][1:] // Dx -> Fx
181+
case strings.HasPrefix(args[1], "S"): // VSTR.F32
182+
op = "MOVF" + op[4:] + suffix
183+
if inst.Args[0].(Reg)&1 == 0 { // Sx -> Fy, y = x/2, if x is even
184+
args[1] = fmt.Sprintf("F%d", (inst.Args[0].(Reg)-S0)/2)
185+
}
186+
default:
187+
panic(fmt.Sprintf("wrong FP register: %v", inst))
188+
}
189+
args[0], args[1] = args[1], args[0]
146190
}
147191

148192
if args != nil {

arm/armasm/testdata/decode.txt

+24
Original file line numberDiff line numberDiff line change
@@ -1228,3 +1228,27 @@ f7f020e3| 1 plan9 DBG $7
12281228
58f07ff5| 1 plan9 DMB $8
12291229
49f07ff5| 1 plan9 DSB $9
12301230
62f07ff5| 1 plan9 ISB $2
1231+
009a94ed| 1 plan9 MOVF (R4), F9
1232+
009ad4ed| 1 plan9 MOVF (R4), S19
1233+
009b940d| 1 plan9 MOVD.EQ (R4), F9
1234+
003a9a1d| 1 plan9 MOVF.NE (R10), F3
1235+
003ada1d| 1 plan9 MOVF.NE (R10), S7
1236+
003b9aed| 1 plan9 MOVD (R10), F3
1237+
089a93ed| 1 plan9 MOVF 0x20(R3), F9
1238+
089ad3ed| 1 plan9 MOVF 0x20(R3), S19
1239+
089b940d| 1 plan9 MOVD.EQ 0x20(R4), F9
1240+
083a1a1d| 1 plan9 MOVF.NE -0x20(R10), F3
1241+
083a5a1d| 1 plan9 MOVF.NE -0x20(R10), S7
1242+
083b1aed| 1 plan9 MOVD -0x20(R10), F3
1243+
009a84ed| 1 plan9 MOVF F9, (R4)
1244+
009ac4ed| 1 plan9 MOVF S19, (R4)
1245+
009b840d| 1 plan9 MOVD.EQ F9, (R4)
1246+
003a8a1d| 1 plan9 MOVF.NE F3, (R10)
1247+
003aca1d| 1 plan9 MOVF.NE S7, (R10)
1248+
003b8aed| 1 plan9 MOVD F3, (R10)
1249+
089a83ed| 1 plan9 MOVF F9, 0x20(R3)
1250+
089ac3ed| 1 plan9 MOVF S19, 0x20(R3)
1251+
089b840d| 1 plan9 MOVD.EQ F9, 0x20(R4)
1252+
083a0a1d| 1 plan9 MOVF.NE F3, -0x20(R10)
1253+
083a4a1d| 1 plan9 MOVF.NE S7, -0x20(R10)
1254+
083b0aed| 1 plan9 MOVD F3, -0x20(R10)

0 commit comments

Comments
 (0)