1
0
Fork 0

riscv64-asm.c: correct check for 12-bit immediate

asm_emit_cj: correct check for offset size
This commit is contained in:
noneofyourbusiness 2023-12-09 00:57:52 +01:00
parent 275dfbea20
commit 279dbb94e2
No known key found for this signature in database
GPG Key ID: FF810A8659912F5A
1 changed files with 4 additions and 9 deletions

View File

@ -184,7 +184,7 @@ static void parse_operand(TCCState *s1, Operand *op)
op->e = e;
/* compare against unsigned 12-bit maximum */
if (!op->e.sym) {
if (op->e.v < 0x2000)
if (op->e.v < 0x1000)
op->type = OP_IM12S;
} else
expect("operand");
@ -1176,19 +1176,14 @@ static void asm_emit_cj(int token, uint16_t opcode, const Operand *imm)
{
uint32_t offset;
if (imm->type != OP_IM12S && imm->type != OP_IM32) {
tcc_error("'%s': Expected source operand that is an immediate value", get_tok_str(token, NULL));
/* +-2 KiB range */
if (imm->type != OP_IM12S) {
tcc_error("'%s': Expected source operand that is a 12-bit immediate value", get_tok_str(token, NULL));
return;
}
offset = imm->e.v;
/* +-2 KiB range; max. 0x7fe min. 0xffe (-0x7fe) */
if (offset > 0x1fff) {
tcc_error("'%s': Expected source operand that is an immediate value between 0 and 0x1fff", get_tok_str(token, NULL));
return;
}
if (offset & 1) {
tcc_error("'%s': Expected source operand that is an even immediate value", get_tok_str(token, NULL));
return;