]> Cypherpunks repositories - gostls13.git/commit
cmd/internal/obj/riscv: improve code generation for loading of constants
authorJoel Sing <joel@sing.id.au>
Mon, 9 Aug 2021 08:14:04 +0000 (08:14 +0000)
committerJoel Sing <joel@sing.id.au>
Sat, 4 Sep 2021 19:33:54 +0000 (19:33 +0000)
commit28dae3defb06fb18aaadce5269e928e8ca3769e1
treeb76fdda19e21b3382111b16b000ea75c42f616ea
parent37e9c1d6fe453458a203595277147ae713650a3a
cmd/internal/obj/riscv: improve code generation for loading of constants

Loading of constants that are 12 bits or smaller is currently performed using a single
ADDIW instruction, while constants between 13 bits and 32 bits are loaded using a
LUI+ADDIW pair.

Instead, use a single ADDI instruction for the 12 bits or smaller case - this
translates to the LI pseudo-instruction, making objdump more readable and giving:

   11c7c:       fff00293                li      t0,-1
   11c80:       00000313                li      t1,0

Rather than:

   11c7c:       fff0029b                addiw   t0,zero,-1
   11c80:       0000031b                sext.w  t1,zero

In the case where a constant exceeds 12 bits, an LUI instruction is required,
however if the lower 12 bits are zero, the ADDIW instruction can be omitted.
The same applies to the case where immediate splitting is performed for other
immediate instructions.

This removes around 900 instructions from the Go binary.

Change-Id: Id6c77774b3b429fa525da018a6926b85df838a2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/344457
Trust: Joel Sing <joel@sing.id.au>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/asm/internal/asm/testdata/riscv64.s
src/cmd/internal/obj/riscv/obj.go