Skip to content

Commit 33454f5

Browse files
AntonJohanssonAnton Johansson
andauthored
Xqci: sign extend imm in qc.insbi/insbri (#900)
The 5-bit immediate argument needs to be sign extended to XLEN to account for larger than 5-bit subsets of a negative immediate. As an example consider and qc.e.ori and qc.insbi which here should produce the same output 0x1ffff li t1, 0x10000 qc.e.ori t0, t1, 0xffff ; -> t0 = 0x1ffff qc.insbi t1, -1, 16, 0 ; -> t1 = 0x1ffff for qc.insbi this only works if imm is sign extended 0x1f -> 0xffffffff, otherwise the subset inserted is simply 0x1f and we get 0x1001f as output. The same problem exists for qc.insbri. Signed-off-by: Anton Johansson <anjo@rev.ng> Co-authored-by: Anton Johansson <anjo@rev.ng>
1 parent be0871b commit 33454f5

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

spec/custom/isa/qc_iu/inst/Xqci/qc.insbi.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ operation(): |
3939
XReg width = width_minus1 + 1;
4040
XReg mask = ((32'b1 << width) - 1) << shamt;
4141
XReg orig_val = X[rd];
42-
X[rd] = (orig_val & ~mask) | ((imm << shamt) & mask);
42+
XReg src = $signed(imm);
43+
X[rd] = (orig_val & ~mask) | ((src << shamt) & mask);

spec/custom/isa/qc_iu/inst/Xqci/qc.insbri.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ operation(): |
4343
if (width > 0) {
4444
XReg mask = ((32'b1 << width) - 1) << shamt;
4545
XReg orig_val = X[rd];
46-
X[rd] = (orig_val & ~mask) | ((imm << shamt) & mask);
46+
XReg src = $signed(imm);
47+
X[rd] = (orig_val & ~mask) | ((src << shamt) & mask);
4748
}

0 commit comments

Comments
 (0)