Skip to content

Commit 279dbb9

Browse files
committed
riscv64-asm.c: correct check for 12-bit immediate
asm_emit_cj: correct check for offset size
1 parent 275dfbe commit 279dbb9

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

riscv64-asm.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static void parse_operand(TCCState *s1, Operand *op)
184184
op->e = e;
185185
/* compare against unsigned 12-bit maximum */
186186
if (!op->e.sym) {
187-
if (op->e.v < 0x2000)
187+
if (op->e.v < 0x1000)
188188
op->type = OP_IM12S;
189189
} else
190190
expect("operand");
@@ -1176,19 +1176,14 @@ static void asm_emit_cj(int token, uint16_t opcode, const Operand *imm)
11761176
{
11771177
uint32_t offset;
11781178

1179-
if (imm->type != OP_IM12S && imm->type != OP_IM32) {
1180-
tcc_error("'%s': Expected source operand that is an immediate value", get_tok_str(token, NULL));
1179+
/* +-2 KiB range */
1180+
if (imm->type != OP_IM12S) {
1181+
tcc_error("'%s': Expected source operand that is a 12-bit immediate value", get_tok_str(token, NULL));
11811182
return;
11821183
}
11831184

11841185
offset = imm->e.v;
11851186

1186-
/* +-2 KiB range; max. 0x7fe min. 0xffe (-0x7fe) */
1187-
if (offset > 0x1fff) {
1188-
tcc_error("'%s': Expected source operand that is an immediate value between 0 and 0x1fff", get_tok_str(token, NULL));
1189-
return;
1190-
}
1191-
11921187
if (offset & 1) {
11931188
tcc_error("'%s': Expected source operand that is an even immediate value", get_tok_str(token, NULL));
11941189
return;

0 commit comments

Comments
 (0)