mirror of https://github.com/golang/go.git
cmd/internal/obj/arm64: optimize constant pool
"MOVD $0xaaaaaaaa, R2" "MOVD $-0x55555555, R3" For the above instructions, 64-bit constants 0x00000000 aaaaaaaa and 0xffffffff aaaaaaab are stored in the constant pool. This CL optimizes them to "MOVWU $0xaaaaaaaa, R2" "MOVW $-0x05555555, R3" and 32-bit constants 0xaaaaaaaa and 0xaaaaaaab are stored in the constant pool. There is a little size reduction (about total 5KB) in both the go executable and the library files. Change-Id: I7c4bfa6cd9c07da99c69a8f9c15010a0cce3b735 Reviewed-on: https://go-review.googlesource.com/105775 Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c1ed1f3c80
commit
9be1921042
|
|
@ -933,6 +933,11 @@ func (c *ctxt7) flushpool(p *obj.Prog, skip int) {
|
|||
}
|
||||
|
||||
/*
|
||||
* MOVD foo(SB), R is actually
|
||||
* MOVD addr, REGTMP
|
||||
* MOVD REGTMP, R
|
||||
* where addr is the address of the DWORD containing the address of foo.
|
||||
*
|
||||
* TODO: hash
|
||||
*/
|
||||
func (c *ctxt7) addpool(p *obj.Prog, a *obj.Addr) {
|
||||
|
|
@ -942,11 +947,17 @@ func (c *ctxt7) addpool(p *obj.Prog, a *obj.Addr) {
|
|||
t.As = AWORD
|
||||
sz := 4
|
||||
|
||||
// MOVD foo(SB), R is actually
|
||||
// MOVD addr, REGTMP
|
||||
// MOVD REGTMP, R
|
||||
// where addr is the address of the DWORD containing the address of foo.
|
||||
if p.As == AMOVD && a.Type != obj.TYPE_MEM || cls == C_ADDR || cls == C_VCON || lit != int64(int32(lit)) || uint64(lit) != uint64(uint32(lit)) {
|
||||
if p.As == AMOVD && a.Type == obj.TYPE_CONST {
|
||||
// simplify MOVD to MOVW/MOVWU to reduce constant pool size
|
||||
if lit == int64(int32(lit)) { // -0x80000000 ~ 0x7fffffff
|
||||
p.As = AMOVW
|
||||
} else if uint64(lit) == uint64(uint32(lit)) { // 0 ~ 0xffffffff
|
||||
p.As = AMOVWU
|
||||
} else { // 64-bit
|
||||
t.As = ADWORD
|
||||
sz = 8
|
||||
}
|
||||
} else if p.As == AMOVD && a.Type != obj.TYPE_MEM || cls == C_ADDR || cls == C_VCON || lit != int64(int32(lit)) || uint64(lit) != uint64(uint32(lit)) {
|
||||
// conservative: don't know if we want signed or unsigned extension.
|
||||
// in case of ambiguity, store 64-bit
|
||||
t.As = ADWORD
|
||||
|
|
|
|||
Loading…
Reference in New Issue