[PATCH v5] RISC-V: Add Zcmt instructions and csr.
Nelson Chu
nelson@rivosinc.com
Wed Nov 20 00:37:31 GMT 2024
On Tue, Nov 19, 2024 at 4:11 PM Jiawei <jiawei@iscas.ac.cn> wrote:
> @@ -3922,6 +3929,28 @@ riscv_ip (char *str, struct riscv_cl_insn *ip,
>> expressionS *imm_expr,
>> break;
>> INSERT_OPERAND (SREG2, *ip, regno % 8);
>> continue;
>> + case 'I': /* index operand of cm.jt. The range is
>> from 0 to 31. */
>> + my_getSmallExpression (imm_expr, imm_reloc, asarg,
>> p);
>> + if (imm_expr->X_op != O_constant
>> + || imm_expr->X_add_number < 0
>> + || imm_expr->X_add_number > 31)
>> + {
>> + as_bad ("bad index value for cm.jt, range: [0,
>> 31]");
>> + break;
>> + }
>> + ip->insn_opcode |= ENCODE_ZCMT_INDEX
>> (imm_expr->X_add_number);
>> + goto rvc_imm_done;
>> + case 'i': /* index operand of cm.jalt. The range is
>> from 32 to 255. */
>> + my_getSmallExpression (imm_expr, imm_reloc, asarg,
>> p);
>> + if (imm_expr->X_op != O_constant
>> + || imm_expr->X_add_number < 32
>> + || imm_expr->X_add_number > 255)
>> + {
>> + as_bad ("bad index value for cm.jalt, range:
>> [32, 255]");
>> + break;
>> + }
>> + ip->insn_opcode |= ENCODE_ZCMT_INDEX
>> (imm_expr->X_add_number);
>> + goto rvc_imm_done;
>> default:
>> goto unknown_riscv_ip_operand;
>> }
>>
>
> Since the imm range should already be checked here ...
>
>
>> diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
>> index 551d57e4cba..0dec8428a93 100644
>> --- a/opcodes/riscv-dis.c
>> +++ b/opcodes/riscv-dis.c
>> @@ -732,6 +732,11 @@ print_insn_args (const char *oparg, insn_t l,
>> bfd_vma pc, disassemble_info *info
>> print (info->stream, dis_style_immediate, "%d",
>> riscv_get_spimm (l));
>> break;
>> + case 'i':
>> + case 'I':
>> + print (info->stream, dis_style_address_offset,
>> + "%lu", EXTRACT_ZCMT_INDEX (l));
>> + break;
>> default:
>> goto undefined_modifier;
>> }
>> diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c
>> index 8d5c574da6e..787beb7c029 100644
>> --- a/opcodes/riscv-opc.c
>> +++ b/opcodes/riscv-opc.c
>> @@ -362,6 +362,25 @@ match_sreg1_not_eq_sreg2 (const struct riscv_opcode
>> *op, insn_t insn)
>> && (EXTRACT_OPERAND (SREG1, insn) != EXTRACT_OPERAND (SREG2,
>> insn));
>> }
>>
>> +/* This is used for cm.jt. This requires index operand to be less than
>> 32. */
>> +
>> +static int
>> +match_cm_jt (const struct riscv_opcode *op, insn_t insn)
>> +{
>> + return match_opcode (op, insn)
>> + && EXTRACT_ZCMT_INDEX (insn) < 32;
>> +}
>> +
>> +/* This is used for cm.jalt. This requires index operand to be in 32 to
>> 255. */
>> +
>> +static int
>> +match_cm_jalt (const struct riscv_opcode *op, insn_t insn)
>> +{
>> + return match_opcode (op, insn)
>> + && EXTRACT_ZCMT_INDEX (insn) >= 32
>> + && EXTRACT_ZCMT_INDEX (insn) < 256;
>> +}
>> +
>>
>
> ... Do we still need these match functions? Otherwise it looks good,
> thanks.
>
> Nelson
>
> I think yes, since they have the same match_opcode, but just can be
> distinguished by the input argument range.
> I tried don't use this, it will always generate cm.jt but no cm.jalt,
> thanks.
> Jiawei
>
Oh you are saying the dump situation right? Yeah we used not to check the
imm range in dis-assembler, and since cm.jalt and cm.jt have the same
encoding and belong to the same extension, and also it is worth to
have different operands `Wci' and `WcI' in assembler to have the range
check alerts, it seems there is no better solution that don't keep both
sides for now. Committed, thanks for this work.
Nelson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20241120/37e54eae/attachment-0001.htm>
More information about the Binutils
mailing list