From: Joel Sing Date: Sun, 27 Aug 2023 16:14:22 +0000 (+1000) Subject: cmd/internal/obj/riscv: simplify instructionsForMOV X-Git-Tag: go1.22rc1~949 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=13d5ca42fdbbbd4e3f104928f945a266642857dd;p=gostls13.git 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 Reviewed-by: Cherry Mui Run-TryBot: Joel Sing Reviewed-by: Dmitri Shuralyov Reviewed-by: Mark Ryan TryBot-Result: Gopher Robot --- 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)