diff --git a/src/cmd/asm/internal/asm/testdata/riscv64validation.s b/src/cmd/asm/internal/asm/testdata/riscv64validation.s index 65497659167..c8ae4c92114 100644 --- a/src/cmd/asm/internal/asm/testdata/riscv64validation.s +++ b/src/cmd/asm/internal/asm/testdata/riscv64validation.s @@ -12,6 +12,9 @@ TEXT validation(SB),$0 SRLI $1, X5, F1 // ERROR "expected integer register in rd position but got non-integer register F1" SRLI $1, F1, X5 // ERROR "expected integer register in rs1 position but got non-integer register F1" + WORD $-1 // ERROR "must be in range [0x0, 0xffffffff]" + WORD $0x100000000 // ERROR "must be in range [0x0, 0xffffffff]" + // // "V" Standard Extension for Vector Operations, Version 1.0 // diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 8c4140ec5c6..e55c206a98e 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -1419,9 +1419,7 @@ func validateVsetvl(ctxt *obj.Link, ins *instruction) { func validateRaw(ctxt *obj.Link, ins *instruction) { // Treat the raw value specially as a 32-bit unsigned integer. // Nobody wants to enter negative machine code. - if ins.imm < 0 || 1<<32 <= ins.imm { - ctxt.Diag("%v: immediate %d in raw position cannot be larger than 32 bits", ins.as, ins.imm) - } + wantImmU(ctxt, ins, ins.imm, 32) } // extractBitAndShift extracts the specified bit from the given immediate, @@ -1706,10 +1704,7 @@ func encodeVsetvl(ins *instruction) uint32 { func encodeRawIns(ins *instruction) uint32 { // Treat the raw value specially as a 32-bit unsigned integer. // Nobody wants to enter negative machine code. - if ins.imm < 0 || 1<<32 <= ins.imm { - panic(fmt.Sprintf("immediate %d cannot fit in 32 bits", ins.imm)) - } - return uint32(ins.imm) + return immU(ins.as, ins.imm, 32) } func EncodeBImmediate(imm int64) (int64, error) {