diff options
| author | Joel Sing <joel@sing.id.au> | 2023-08-28 02:14:22 +1000 |
|---|---|---|
| committer | Joel Sing <joel@sing.id.au> | 2023-09-08 04:20:37 +0000 |
| commit | 13d5ca42fdbbbd4e3f104928f945a266642857dd (patch) | |
| tree | 580a16a30c7dc9657f0e012a7d4a451d76bf2146 /src/cmd/internal/obj | |
| parent | 834a6f9a338b25543cb736ebef03488e8d30a839 (diff) | |
| download | go-13d5ca42fdbbbd4e3f104928f945a266642857dd.tar.xz | |
cmd/internal/obj/riscv: simplify instructionsForMOV
Rather than handling shift based scaling in two locations, rework logic
so there is a single exit path.
Change-Id: I832b4932d53183736050059a11019ced08281b3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/523455
Reviewed-by: M Zhuo <mzh@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/internal/obj')
| -rw-r--r-- | src/cmd/internal/obj/riscv/obj.go | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 776c3a8df6..36812833a9 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -1992,20 +1992,15 @@ func instructionsForMOV(p *obj.Prog) []*instruction { ins.as, ins.rs1, ins.rs2, ins.imm = AADDI, REG_ZERO, obj.REG_NONE, low // LUI is only necessary if the constant does not fit in 12 bits. - if high == 0 { - if insSLLI != nil { - inss = append(inss, insSLLI) + if high != 0 { + // LUI top20bits(c), R + // ADD bottom12bits(c), R, R + insLUI := &instruction{as: ALUI, rd: ins.rd, imm: high} + inss = []*instruction{insLUI} + if low != 0 { + ins.as, ins.rs1 = AADDIW, ins.rd + inss = append(inss, ins) } - break - } - - // LUI top20bits(c), R - // ADD bottom12bits(c), R, R - insLUI := &instruction{as: ALUI, rd: ins.rd, imm: high} - inss = []*instruction{insLUI} - if low != 0 { - ins.as, ins.rs1 = AADDIW, ins.rd - inss = append(inss, ins) } if insSLLI != nil { inss = append(inss, insSLLI) |
