From 6602c86a38ff0d8889257e908489162de38ebbd8 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Tue, 14 Sep 2021 02:21:22 +1000 Subject: [PATCH] cmd/internal/obj/riscv: improve instruction validation Ensure that rs2 is none for various instruction encodings. Fix a couple of cases where it should have been but is not. Change-Id: I9f8211a0257e49643dbbc89e158e048050ebe6f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/349649 Trust: Joel Sing Reviewed-by: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Go Bot --- src/cmd/internal/obj/riscv/obj.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 62d44d8a3f2..f0ea21de97f 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -1003,6 +1003,7 @@ func validateII(ctxt *obj.Link, ins *instruction) { wantImmI(ctxt, ins.as, ins.imm, 12) wantIntReg(ctxt, ins.as, "rd", ins.rd) wantIntReg(ctxt, ins.as, "rs1", ins.rs1) + wantNoneReg(ctxt, ins.as, "rs2", ins.rs2) wantNoneReg(ctxt, ins.as, "rs3", ins.rs3) } @@ -1010,6 +1011,7 @@ func validateIF(ctxt *obj.Link, ins *instruction) { wantImmI(ctxt, ins.as, ins.imm, 12) wantFloatReg(ctxt, ins.as, "rd", ins.rd) wantIntReg(ctxt, ins.as, "rs1", ins.rs1) + wantNoneReg(ctxt, ins.as, "rs2", ins.rs2) wantNoneReg(ctxt, ins.as, "rs3", ins.rs3) } @@ -1017,6 +1019,7 @@ func validateSI(ctxt *obj.Link, ins *instruction) { wantImmI(ctxt, ins.as, ins.imm, 12) wantIntReg(ctxt, ins.as, "rd", ins.rd) wantIntReg(ctxt, ins.as, "rs1", ins.rs1) + wantNoneReg(ctxt, ins.as, "rs2", ins.rs2) wantNoneReg(ctxt, ins.as, "rs3", ins.rs3) } @@ -1024,6 +1027,7 @@ func validateSF(ctxt *obj.Link, ins *instruction) { wantImmI(ctxt, ins.as, ins.imm, 12) wantIntReg(ctxt, ins.as, "rd", ins.rd) wantFloatReg(ctxt, ins.as, "rs1", ins.rs1) + wantNoneReg(ctxt, ins.as, "rs2", ins.rs2) wantNoneReg(ctxt, ins.as, "rs3", ins.rs3) } @@ -1567,7 +1571,7 @@ func instructionForProg(p *obj.Prog) *instruction { func instructionsForOpImmediate(p *obj.Prog, as obj.As, rs int16) []*instruction { // $imm, REG, TO ins := instructionForProg(p) - ins.as, ins.rs1 = as, uint32(rs) + ins.as, ins.rs1, ins.rs2 = as, uint32(rs), obj.REG_NONE low, high, err := Split32BitImmediate(ins.imm) if err != nil { @@ -1990,7 +1994,7 @@ func instructionsForProg(p *obj.Prog) []*instruction { case ASEQZ: // SEQZ rs, rd -> SLTIU $1, rs, rd ins.as = ASLTIU - ins.rs1 = uint32(p.From.Reg) + ins.rs1, ins.rs2 = uint32(p.From.Reg), obj.REG_NONE ins.imm = 1 case ASNEZ: