2021-03-30 Jim Wilson <jimw@sifive.com>
Kito Cheng <kito.cheng@sifive.com>
Nelson Chu <nelson.chu@sifive.com>
This patch is porting from the following riscv github,
https://github.com/riscv/riscv-binutils-gdb/tree/rvv-1.0.x
And here is the vector draft spec,
https://github.com/riscv/riscv-v-spec
The match_func in opcodes/riscv-opc.c have many purposes. One of them is
checking the instruction constraints. But we got the request before that
the assembler constraint checkings break some hardware exception testcases,
which are written by assmebly code. Therefore, we add new assembler options
and .option directives to let users can disable/enable the rvv constraints.
For now the constraints are disabled by default, but should we default
enable them for safety? Besides, the match_func will return different
error constriant messages, so that we can report the details to users.
This should be more user-friendly.
bfd/
* elfxx-riscv.c (riscv_supported_std_ext): Updated the draft
version of v.
(riscv_supported_std_z_ext): Added draft zvamo and zvlsseg.
gas/
* config/tc-riscv.c (enum DRAFT_EXT): Added.
(enum riscv_extended_csr_class): Added CSR_CLASS_V for rvv CSRs.
(enum reg_extended_class): Added vector registers.
(op_draft_hash): Added draft hash table for rvv.
(md_begin): Init op_draft_hash and register hash for rvv.
(riscv_extended_subset_supports): Handle INSN_CLASS_V*.
(riscv_extended_csr_class_check): Handle CSR_CLASS_V.
(validate_riscv_extended_insn): Check if the rvv instructions are valid.
(riscv_find_extended_opcode_hash): Search instruction opcode from
op_draft_hash.
(vector_macro): Call macro_build to expand rvv macros into instructions.
(extended_macro_build): Handle rvv operands for macro_build.
(extended_macro): Handle M_VMSGE and M_VMSGEU.
(my_getVsetvliExpression): Similar to my_getVsetvliExpression, but used
for parsing vsetvli operands.
(riscv_parse_extended_operands): Handle rvv operands. Pass ®no from
riscv_ip, otherwise we will get fail when parsing Vf operand for AMO VS3.
(riscv_ip): Add two new arguments to match_func, check_constraints and
&error. We can disbale the match_func check by setting check_constraints
to zero; The part of match_func will set different error messages to the
&error, and them we can report more details to users.
(riscv_set_options, riscv_opts, s_riscv_option): Add .option
checkconstraints and nocheckconstraints, to enable/disable the
match_func constraints checking. Disable it by default.
(enum options, md_longopts, md_parse_option): Add assembler options
m[no-]check-constraints.
* testsuite/gas/riscv/extended/extended.exp: Updated.
* testsuite/gas/riscv/extended/extended-csr.d: New testcase for rvv CSRs.
* testsuite/gas/riscv/extended/extended-csr.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-fixp.d:
New testcase for rvv constriants.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-fixp.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-fixp.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-floatp.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-floatp.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-floatp.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-int.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-int.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-int.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-narrow.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-narrow.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-narrow.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-widen.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-widen.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-arith-widen.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-load-store.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-load-store.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-load-store.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-mask.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-mask.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-mask.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-permutation.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-permutation.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-permutation.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-zvamo.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-zvamo.l: Likewise.
* testsuite/gas/riscv/extended/vector-insns-fail-zvamo.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-vmsgtvx.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-vmsgtvx.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns-zero-imm.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns-zero-imm.s: Likewise.
* testsuite/gas/riscv/extended/vector-insns.d: Likewise.
* testsuite/gas/riscv/extended/vector-insns.s: Likewise.
include/
* opcode/riscv-opc-extended.h: Added rvv encoding macros and CSRs.
* opcode/riscv.h: Added rvv immediate encodings and fields.
(struct riscv_opcode): Updated match_func.
(enum riscv_extended_insn_class): Added INSN_CLASS_V*.
(enum M_VMSGE, M_VMSGEU): Added.
opcodes/
* riscv-dis.c (print_extended_insn_args): Handle rvv operands.
(riscv_disassemble_opcode): Updated match_func.
* riscv-opc.c (match_*): Updated since two new parameters.
(riscv_vecr_names_numeric): Added rvv register names.
(riscv_vecm_names_numeric): Added rvv mask register name.
(riscv_vsew, riscv_vlmul, riscv_vta, riscv_vma): Added for vsetvli.
(MASK_VD, MASK_VS1, MASK_VS2, MASK_VMASK): Added for rvv match_func.
(match_vs1_eq_vs2, match_vs1_eq_vs2_neq_vm, match_vd_eq_vs1_eq_vs2):
Added to check special register usage, cannot be disabled.
(match_widen_vd_neq_vs1_neq_vs2_neq_vm): The rvv constraint check,
can be disabled/enabled by m[no-]check-constraints or .option
[no]checkconstraints.
(match_widen_vd_neq_vs1_neq_vm): Likewise.
(match_widen_vd_neq_vs2_neq_vm): Likewise.
(match_widen_vd_neq_vm): Likewise.
(match_narrow_vd_neq_vs2_neq_vm): Likewise.
(match_vd_neq_vs1_neq_vs2): Likewise.
(match_vd_neq_vs1_neq_vs2_neq_vm): Likewise.
(match_vd_neq_vs2_neq_vm): Likewise.
(match_vd_neq_vm): Likewise.
(match_vls_nf_rv): Likewise.
(match_vmv_nf_rv): Likewise.
(riscv_draft_opcodes): Added rvv v0.10 instructions.
(riscv_extended_opcodes): Updated.