cmd/internal/obj/arm64: add assembler support for load with register offset

The patch adds support for LDR(register offset) instruction.
And add the test cases and negative tests.

Change-Id: I5b32c6a5065afc4571116d4896f7ebec3c0416d3
Reviewed-on: https://go-review.googlesource.com/87955
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
fanzha02 2017-12-08 08:19:32 +00:00 committed by Brad Fitzpatrick
parent 14393c5cd4
commit 31700b83b5
9 changed files with 251 additions and 87 deletions

View file

@ -214,7 +214,12 @@ func Dconv(p *Prog, a *Addr) string {
case TYPE_MEM:
str = Mconv(a)
if a.Index != REG_NONE {
str += fmt.Sprintf("(%v*%d)", Rconv(int(a.Index)), int(a.Scale))
if a.Scale == 0 {
// arm64 shifted or extended register offset, scale = 0.
str += fmt.Sprintf("(%v)", Rconv(int(a.Index)))
} else {
str += fmt.Sprintf("(%v*%d)", Rconv(int(a.Index)), int(a.Scale))
}
}
case TYPE_CONST:
@ -294,7 +299,17 @@ func Mconv(a *Addr) string {
case a.Offset == 0:
str = fmt.Sprintf("(%v)", Rconv(int(a.Reg)))
case a.Offset != 0:
str = fmt.Sprintf("%d(%v)", a.Offset, Rconv(int(a.Reg)))
switch objabi.GOARCH {
case "arm64":
// the register and the extension/shift are encoded in a.Offset.
if a.Index != 0 {
str = fmt.Sprintf("(%v)", Rconv(int(a.Reg)))
return str
}
fallthrough
default:
str = fmt.Sprintf("%d(%v)", a.Offset, Rconv(int(a.Reg)))
}
}
// Note: a.Reg == REG_NONE encodes the default base register for the NAME_ type.