[PATCH v3 2/2] RISC-V: Add support for XAndesPerf extension
Kito Cheng
kito.cheng@gmail.com
Fri Nov 20 08:50:53 GMT 2026
Thanks for the patch. I have a few comments:
1. With -shared or -pie, ld does not report an error for
R_RISCV_NDS_GPREL_*, and silently produces wrong code. For example,
"nds.lwgp a0, extvar" against an undefined symbol links fine, and
there is no dynamic reloc. I suggest doing the same as for
R_RISCV_HI20: reject them in check_relocs with bad_static_reloc.
2. If __global_pointer$ is not defined, GPREL is computed with gp = 0.
If the data address happens to be in range, ld silently produces
wrong code. If it is out of range, ld only reports "relocation
truncated to fit", and the message does not say anything about gp.
I suggest reporting an error when gp is not defined.
3. "rel->r_addend -= riscv_global_pointer_value (info);" changes the
reloc itself, so with --emit-relocs the output addend already has gp
subtracted (for example "data - 118f4", where it should be
"data + 0"). I suggest adjusting relocation instead, and leaving
r_addend alone.
Ethan Y. C. Liang via Binutils <binutils@sourceware.org> 於
2026年10月22日週四 下午8:47寫道:
>
> The XAndesPerf extension provides performance enhancement instructions
> for Andes RISC-V processors, including branch instructions, load
> effective address instructions, GP-relative instructions, and string
> processing instructions [1].
>
> The branch and GP-relative instructions use the following Andes
> vendor-specific relocations:
>
> * R_RISCV_NDS_BRANCH_10 (241) for the 10-bit PC-relative branch offset
> of nds.bbc, nds.bbs, nds.beqc and nds.bnec.
> * R_RISCV_NDS_GPREL_* (246-253) for the GP-relative offsets of
> nds.addigp, nds.l[bhwd][u]gp and nds.s[bhwd]gp.
>
> Contributors:
> Ethan Y. C. Liang <ycl669@andestech.com>
> Yu-Qi Liu <yuqiliu@andestech.com>
>
> bfd/ChangeLog:
>
> * reloc.c (BFD_RELOC_RISCV_NDS_BRANCH_10)
> (BFD_RELOC_RISCV_NDS_GPREL_18S0_I, BFD_RELOC_RISCV_NDS_GPREL_17S1_I)
> (BFD_RELOC_RISCV_NDS_GPREL_17S2_I, BFD_RELOC_RISCV_NDS_GPREL_17S3_I)
> (BFD_RELOC_RISCV_NDS_GPREL_18S0_S, BFD_RELOC_RISCV_NDS_GPREL_17S1_S)
> (BFD_RELOC_RISCV_NDS_GPREL_17S2_S, BFD_RELOC_RISCV_NDS_GPREL_17S3_S):
> New.
> * bfd-in2.h: Regenerate.
> * libbfd.h: Regenerate.
> * elfnn-riscv.c (perform_relocation): Encode Andes relocations.
> (riscv_elf_relocate_section): Subtract the GP value for
> R_RISCV_NDS_GPREL_* relocations.
> * elfxx-riscv.c (howto_table_nds): New.
> (riscv_nds_reloc_map): New.
> (riscv_supported_vendor_x_ext): Add xandesperf.
> (riscv_multi_subset_supports): Handle INSN_CLASS_XANDESPERF.
> (riscv_multi_subset_supports_ext): Likewise.
>
> gas/ChangeLog:
>
> * config/tc-riscv.c (validate_riscv_insn): Handle Andes operands.
> (riscv_ip): Likewise.
> (md_apply_fix): Handle Andes relocations.
> * doc/c-riscv.texi: Document XAndesPerf.
> * testsuite/gas/riscv/march-help.l: Add xandesperf.
> * testsuite/gas/riscv/x-andes-perf.d: New test.
> * testsuite/gas/riscv/x-andes-perf.s: Likewise.
>
> include/ChangeLog:
>
> * elf/riscv.h (elf_riscv_nds_reloc_type): New relocation numbers.
> (RISCV_VENDORS): Add Andes.
> * opcode/riscv-opc.h: Add XAndesPerf instructions.
> * opcode/riscv.h (EXTRACT_NDS_*, ENCODE_NDS_*, VALID_NDS_*): New
> macros.
> (enum riscv_insn_class): Add INSN_CLASS_XANDESPERF.
>
> ld/ChangeLog:
>
> * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run new test.
> * testsuite/ld-riscv-elf/x-andes-perf-reloc.d: New test.
> * testsuite/ld-riscv-elf/x-andes-perf-reloc.ld: Likewise.
> * testsuite/ld-riscv-elf/x-andes-perf-reloc.s: Likewise.
>
> opcodes/ChangeLog:
>
> * riscv-dis.c (print_insn_args): Handle Andes operands.
> * riscv-opc.c (riscv_opcodes): Add XAndesPerf instructions.
>
> [1] https://github.com/andestech/andes-v5-isa/releases/download/ast-v5_4_0-release/AndeStar_V5_ISA_Spec_UM165-v1.5.08-20250317.pdf
> ---
> bfd/bfd-in2.h | 11 +
> bfd/elfnn-riscv.c | 78 +++++++
> bfd/elfxx-riscv.c | 173 +++++++++++++++
> bfd/libbfd.h | 9 +
> bfd/reloc.c | 21 ++
> gas/config/tc-riscv.c | 206 ++++++++++++++++++
> gas/doc/c-riscv.texi | 5 +
> gas/testsuite/gas/riscv/march-help.l | 1 +
> gas/testsuite/gas/riscv/x-andes-perf.d | 95 ++++++++
> gas/testsuite/gas/riscv/x-andes-perf.s | 46 ++++
> include/elf/riscv.h | 16 +-
> include/opcode/riscv-opc.h | 89 ++++++++
> include/opcode/riscv.h | 66 ++++++
> ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 1 +
> .../ld-riscv-elf/x-andes-perf-reloc.d | 28 +++
> .../ld-riscv-elf/x-andes-perf-reloc.ld | 10 +
> .../ld-riscv-elf/x-andes-perf-reloc.s | 26 +++
> opcodes/riscv-dis.c | 89 ++++++++
> opcodes/riscv-opc.c | 31 +++
> 19 files changed, 1000 insertions(+), 1 deletion(-)
> create mode 100644 gas/testsuite/gas/riscv/x-andes-perf.d
> create mode 100644 gas/testsuite/gas/riscv/x-andes-perf.s
> create mode 100644 ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.d
> create mode 100644 ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.ld
> create mode 100644 ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.s
>
> diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
> index cdc9c95f3c5..fd391de1730 100644
> --- a/bfd/bfd-in2.h
> +++ b/bfd/bfd-in2.h
> @@ -5380,6 +5380,17 @@ enum bfd_reloc_code_real
> BFD_RELOC_RISCV_SUB_ULEB128,
> BFD_RELOC_RISCV_VENDOR,
>
> + /* RISC-V vendor (Andes) relocations. */
> + BFD_RELOC_RISCV_NDS_BRANCH_10,
> + BFD_RELOC_RISCV_NDS_GPREL_18S0_I,
> + BFD_RELOC_RISCV_NDS_GPREL_17S1_I,
> + BFD_RELOC_RISCV_NDS_GPREL_17S2_I,
> + BFD_RELOC_RISCV_NDS_GPREL_17S3_I,
> + BFD_RELOC_RISCV_NDS_GPREL_18S0_S,
> + BFD_RELOC_RISCV_NDS_GPREL_17S1_S,
> + BFD_RELOC_RISCV_NDS_GPREL_17S2_S,
> + BFD_RELOC_RISCV_NDS_GPREL_17S3_S,
> +
> /* Renesas RL78 Relocations. */
> BFD_RELOC_RL78_NEG8,
> BFD_RELOC_RL78_NEG16,
> diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
> index 41279225d48..299684db268 100644
> --- a/bfd/elfnn-riscv.c
> +++ b/bfd/elfnn-riscv.c
> @@ -2525,6 +2525,67 @@ perform_relocation (const reloc_howto_type *howto,
> {
> switch (vendor_id)
> {
> + case RISCV_VENDOR_ID_NDS:
> + switch (ELFNN_R_TYPE (rel->r_info))
> + {
> + case R_RISCV_NDS_BRANCH_10:
> + if (!VALID_NDS_BRANCH_IMM10 (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_BRANCH_IMM10 (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_18S0_I:
> + if (!VALID_NDS_LBGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_LBGP_IMM (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_17S1_I:
> + if (!VALID_NDS_LHGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_LHGP_IMM (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_17S2_I:
> + if (!VALID_NDS_LWGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_LWGP_IMM (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_17S3_I:
> + if (!VALID_NDS_LDGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_LDGP_IMM (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_18S0_S:
> + if (!VALID_NDS_SBGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_SBGP_IMM (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_17S1_S:
> + if (!VALID_NDS_SHGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_SHGP_IMM (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_17S2_S:
> + if (!VALID_NDS_SWGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_SWGP_IMM (value);
> + break;
> +
> + case R_RISCV_NDS_GPREL_17S3_S:
> + if (!VALID_NDS_SDGP_IMM (value))
> + return bfd_reloc_overflow;
> + value = ENCODE_NDS_SDGP_IMM (value);
> + break;
> +
> + default:
> + return bfd_reloc_notsupported;
> + }
> + break;
> default:
> return bfd_reloc_notsupported;
> }
> @@ -3481,6 +3542,23 @@ riscv_elf_relocate_section (struct bfd_link_info *info,
> {
> switch (vendor_id)
> {
> + case RISCV_VENDOR_ID_NDS:
> + switch (r_type)
> + {
> + case R_RISCV_NDS_GPREL_18S0_I:
> + case R_RISCV_NDS_GPREL_17S1_I:
> + case R_RISCV_NDS_GPREL_17S2_I:
> + case R_RISCV_NDS_GPREL_17S3_I:
> + case R_RISCV_NDS_GPREL_18S0_S:
> + case R_RISCV_NDS_GPREL_17S1_S:
> + case R_RISCV_NDS_GPREL_17S2_S:
> + case R_RISCV_NDS_GPREL_17S3_S:
> + rel->r_addend -= riscv_global_pointer_value (info);
> + break;
> + default:
> + break;
> + }
> + break;
> default:
> break;
> }
> diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
> index 4b8c1c4e0b9..58d89cc894b 100644
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -1104,6 +1104,161 @@ static const reloc_howto_type howto_table_custom[] =
>
> #undef CUSTOM_HOWTO
>
> +/* Andes vendor-specific relocations. */
> +static const reloc_howto_type howto_table_nds[] =
> +{
> + EMPTY_HOWTO (192), EMPTY_HOWTO (193), EMPTY_HOWTO (194), EMPTY_HOWTO (195),
> + EMPTY_HOWTO (196), EMPTY_HOWTO (197), EMPTY_HOWTO (198), EMPTY_HOWTO (199),
> + EMPTY_HOWTO (200), EMPTY_HOWTO (201), EMPTY_HOWTO (202), EMPTY_HOWTO (203),
> + EMPTY_HOWTO (204), EMPTY_HOWTO (205), EMPTY_HOWTO (206), EMPTY_HOWTO (207),
> + EMPTY_HOWTO (208), EMPTY_HOWTO (209), EMPTY_HOWTO (210), EMPTY_HOWTO (211),
> + EMPTY_HOWTO (212), EMPTY_HOWTO (213), EMPTY_HOWTO (214), EMPTY_HOWTO (215),
> + EMPTY_HOWTO (216), EMPTY_HOWTO (217), EMPTY_HOWTO (218), EMPTY_HOWTO (219),
> + EMPTY_HOWTO (220), EMPTY_HOWTO (221), EMPTY_HOWTO (222), EMPTY_HOWTO (223),
> + EMPTY_HOWTO (224), EMPTY_HOWTO (225), EMPTY_HOWTO (226), EMPTY_HOWTO (227),
> + EMPTY_HOWTO (228), EMPTY_HOWTO (229), EMPTY_HOWTO (230), EMPTY_HOWTO (231),
> + EMPTY_HOWTO (232), EMPTY_HOWTO (233), EMPTY_HOWTO (234), EMPTY_HOWTO (235),
> + EMPTY_HOWTO (236), EMPTY_HOWTO (237), EMPTY_HOWTO (238), EMPTY_HOWTO (239),
> + EMPTY_HOWTO (240),
> +
> + /* 10-bit PC-relative branch offset. */
> + HOWTO (R_RISCV_NDS_BRANCH_10, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + true, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_BRANCH_10", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_BRANCH_IMM10 (-1U), /* dst_mask */
> + true), /* pcrel_offset */
> +
> + EMPTY_HOWTO (242), EMPTY_HOWTO (243), EMPTY_HOWTO (244), EMPTY_HOWTO (245),
> +
> + /* 18-bit GP-relative load offset. */
> + HOWTO (R_RISCV_NDS_GPREL_18S0_I, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_18S0_I", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_LBGP_IMM (-1U), /* dst_mask */
> + false), /* pcrel_offset */
> +
> + /* 17-bit, 2-byte aligned GP-relative load offset. */
> + HOWTO (R_RISCV_NDS_GPREL_17S1_I, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_17S1_I", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_LHGP_IMM (-1U), /* dst_mask */
> + false), /* pcrel_offset */
> +
> + /* 17-bit, 4-byte aligned GP-relative load offset. */
> + HOWTO (R_RISCV_NDS_GPREL_17S2_I, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_17S2_I", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_LWGP_IMM (-1U), /* dst_mask */
> + false), /* pcrel_offset */
> +
> + /* 17-bit, 8-byte aligned GP-relative load offset. */
> + HOWTO (R_RISCV_NDS_GPREL_17S3_I, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_17S3_I", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_LDGP_IMM (-1U), /* dst_mask */
> + false), /* pcrel_offset */
> +
> + /* 18-bit GP-relative store offset. */
> + HOWTO (R_RISCV_NDS_GPREL_18S0_S, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_18S0_S", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_SBGP_IMM (-1U), /* dst_mask */
> + false), /* pcrel_offset */
> +
> + /* 17-bit, 2-byte aligned GP-relative store offset. */
> + HOWTO (R_RISCV_NDS_GPREL_17S1_S, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_17S1_S", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_SHGP_IMM (-1U), /* dst_mask */
> + false), /* pcrel_offset */
> +
> + /* 17-bit, 4-byte aligned GP-relative store offset. */
> + HOWTO (R_RISCV_NDS_GPREL_17S2_S, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_17S2_S", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_SWGP_IMM (-1U), /* dst_mask */
> + false), /* pcrel_offset */
> +
> + /* 17-bit, 8-byte aligned GP-relative store offset. */
> + HOWTO (R_RISCV_NDS_GPREL_17S3_S, /* type */
> + 0, /* rightshift */
> + 4, /* size */
> + 32, /* bitsize */
> + false, /* pc_relative */
> + 0, /* bitpos */
> + complain_overflow_signed, /* complain_on_overflow */
> + bfd_elf_generic_reloc, /* special_function */
> + "R_RISCV_NDS_GPREL_17S3_S", /* name */
> + false, /* partial_inplace */
> + 0, /* src_mask */
> + ENCODE_NDS_SDGP_IMM (-1U), /* dst_mask */
> + false) /* pcrel_offset */
> +};
> +
> /* A mapping from BFD reloc types to RISC-V ELF reloc types. */
> struct elf_reloc_map
> {
> @@ -1167,6 +1322,19 @@ static const struct elf_reloc_map riscv_reloc_map[] =
> { BFD_RELOC_RISCV_VENDOR, R_RISCV_VENDOR },
> };
>
> +static const struct elf_reloc_map riscv_nds_reloc_map[] =
> +{
> + { BFD_RELOC_RISCV_NDS_BRANCH_10, R_RISCV_NDS_BRANCH_10 },
> + { BFD_RELOC_RISCV_NDS_GPREL_18S0_I, R_RISCV_NDS_GPREL_18S0_I },
> + { BFD_RELOC_RISCV_NDS_GPREL_17S1_I, R_RISCV_NDS_GPREL_17S1_I },
> + { BFD_RELOC_RISCV_NDS_GPREL_17S2_I, R_RISCV_NDS_GPREL_17S2_I },
> + { BFD_RELOC_RISCV_NDS_GPREL_17S3_I, R_RISCV_NDS_GPREL_17S3_I },
> + { BFD_RELOC_RISCV_NDS_GPREL_18S0_S, R_RISCV_NDS_GPREL_18S0_S },
> + { BFD_RELOC_RISCV_NDS_GPREL_17S1_S, R_RISCV_NDS_GPREL_17S1_S },
> + { BFD_RELOC_RISCV_NDS_GPREL_17S2_S, R_RISCV_NDS_GPREL_17S2_S },
> + { BFD_RELOC_RISCV_NDS_GPREL_17S3_S, R_RISCV_NDS_GPREL_17S3_S },
> +};
> +
> /* For looking up a vendor's relocations by its vendor symbol or by enum
> riscv_vendor_id. */
> static const struct
> @@ -1899,6 +2067,7 @@ static const struct riscv_supported_ext riscv_supported_std_zxm_ext[] =
>
> static const struct riscv_supported_ext riscv_supported_vendor_x_ext[] =
> {
> + {"xandesperf", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 },
> {"xandesbfhcvt", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 },
> {"xandesvbfhcvt", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 },
> {"xandesvsintload", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 },
> @@ -3341,6 +3510,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
> return riscv_subset_supports (rps, "svinval");
> case INSN_CLASS_H:
> return riscv_subset_supports (rps, "h");
> + case INSN_CLASS_XANDESPERF:
> + return riscv_subset_supports (rps, "xandesperf");
> case INSN_CLASS_XANDESBFHCVT:
> return riscv_subset_supports (rps, "xandesbfhcvt");
> case INSN_CLASS_XANDESVBFHCVT:
> @@ -3703,6 +3874,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
> return "svinval";
> case INSN_CLASS_H:
> return _("h");
> + case INSN_CLASS_XANDESPERF:
> + return "xandesperf";
> case INSN_CLASS_XANDESBFHCVT:
> return "xandesbfhcvt";
> case INSN_CLASS_XANDESVBFHCVT:
> diff --git a/bfd/libbfd.h b/bfd/libbfd.h
> index 20a494a5561..bf252f01914 100644
> --- a/bfd/libbfd.h
> +++ b/bfd/libbfd.h
> @@ -2334,6 +2334,15 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
> "BFD_RELOC_RISCV_SET_ULEB128",
> "BFD_RELOC_RISCV_SUB_ULEB128",
> "BFD_RELOC_RISCV_VENDOR",
> + "BFD_RELOC_RISCV_NDS_BRANCH_10",
> + "BFD_RELOC_RISCV_NDS_GPREL_18S0_I",
> + "BFD_RELOC_RISCV_NDS_GPREL_17S1_I",
> + "BFD_RELOC_RISCV_NDS_GPREL_17S2_I",
> + "BFD_RELOC_RISCV_NDS_GPREL_17S3_I",
> + "BFD_RELOC_RISCV_NDS_GPREL_18S0_S",
> + "BFD_RELOC_RISCV_NDS_GPREL_17S1_S",
> + "BFD_RELOC_RISCV_NDS_GPREL_17S2_S",
> + "BFD_RELOC_RISCV_NDS_GPREL_17S3_S",
> "BFD_RELOC_RL78_NEG8",
> "BFD_RELOC_RL78_NEG16",
> "BFD_RELOC_RL78_NEG24",
> diff --git a/bfd/reloc.c b/bfd/reloc.c
> index 1d7201044a8..48a8cf5cb45 100644
> --- a/bfd/reloc.c
> +++ b/bfd/reloc.c
> @@ -4758,6 +4758,27 @@ ENUMX
> ENUMDOC
> RISC-V relocations.
>
> +ENUM
> + BFD_RELOC_RISCV_NDS_BRANCH_10
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_18S0_I
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_17S1_I
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_17S2_I
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_17S3_I
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_18S0_S
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_17S1_S
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_17S2_S
> +ENUMX
> + BFD_RELOC_RISCV_NDS_GPREL_17S3_S
> +ENUMDOC
> + RISC-V vendor (Andes) relocations.
> +
> ENUM
> BFD_RELOC_RL78_NEG8
> ENUMX
> diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
> index 6120131198c..259ceccdbed 100644
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -1708,6 +1708,66 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
> case 'X': /* Vendor-specific operands. */
> switch (*++oparg)
> {
> + case 'a': /* Vendor-specific (Andes) operands. */
> + switch (*++oparg)
> + {
> + case 'g':
> + used_bits |= ENCODE_NDS_BRANCH_IMM10 (-1U);
> + break;
> + case 'h':
> + used_bits |= ENCODE_NDS_BFO_IMM6H (-1U);
> + break;
> + case 'i':
> + used_bits |= ENCODE_NDS_BRANCH_IMM7 (-1U);
> + break;
> + case 'k':
> + used_bits |= ENCODE_NDS_BRANCH_IMM6 (-1U);
> + break;
> + case 'l':
> + used_bits |= ENCODE_NDS_BFO_IMM6L (-1U);
> + break;
> + case 'G':
> + switch (*++oparg)
> + {
> + case 'b':
> + used_bits |= ENCODE_NDS_LBGP_IMM (-1U);
> + break;
> + case 'h':
> + used_bits |= ENCODE_NDS_LHGP_IMM (-1U);
> + break;
> + case 'w':
> + used_bits |= ENCODE_NDS_LWGP_IMM (-1U);
> + break;
> + case 'd':
> + used_bits |= ENCODE_NDS_LDGP_IMM (-1U);
> + break;
> + default:
> + goto unknown_validate_operand;
> + }
> + break;
> + case 'H':
> + switch (*++oparg)
> + {
> + case 'b':
> + used_bits |= ENCODE_NDS_SBGP_IMM (-1U);
> + break;
> + case 'h':
> + used_bits |= ENCODE_NDS_SHGP_IMM (-1U);
> + break;
> + case 'w':
> + used_bits |= ENCODE_NDS_SWGP_IMM (-1U);
> + break;
> + case 'd':
> + used_bits |= ENCODE_NDS_SDGP_IMM (-1U);
> + break;
> + default:
> + goto unknown_validate_operand;
> + }
> + break;
> + default:
> + goto unknown_validate_operand;
> + }
> + break;
> case 't': /* Vendor-specific (T-head) operands. */
> {
> size_t n;
> @@ -4116,6 +4176,124 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
> case 'X': /* Vendor-specific operands. */
> switch (*++oparg)
> {
> + case 'a': /* Vendor-specific (Andes) operands. */
> + switch (*++oparg)
> + {
> + case 'g':
> + my_getExpression (imm_expr, asarg, force_reloc);
> + *imm_reloc = BFD_RELOC_RISCV_NDS_BRANCH_10;
> + asarg = expr_parse_end;
> + continue;
> + case 'h':
> + my_getExpression (imm_expr, asarg, force_reloc);
> + if (imm_expr->X_op != O_constant
> + || imm_expr->X_add_number >= xlen
> + || imm_expr->X_add_number < 0)
> + break;
> + ip->insn_opcode
> + |= ENCODE_NDS_BFO_IMM6H (imm_expr->X_add_number);
> + imm_expr->X_op = O_absent;
> + asarg = expr_parse_end;
> + continue;
> + case 'i':
> + my_getExpression (imm_expr, asarg, force_reloc);
> + if (imm_expr->X_op != O_constant
> + || !VALID_NDS_BRANCH_IMM7 (imm_expr->X_add_number))
> + break;
> + ip->insn_opcode
> + |= ENCODE_NDS_BRANCH_IMM7 (imm_expr->X_add_number);
> + imm_expr->X_op = O_absent;
> + asarg = expr_parse_end;
> + continue;
> + case 'k':
> + my_getExpression (imm_expr, asarg, force_reloc);
> + if (imm_expr->X_op != O_constant
> + || imm_expr->X_add_number >= xlen
> + || imm_expr->X_add_number < 0)
> + break;
> + ip->insn_opcode
> + |= ENCODE_NDS_BRANCH_IMM6 (imm_expr->X_add_number);
> + imm_expr->X_op = O_absent;
> + asarg = expr_parse_end;
> + continue;
> + case 'l':
> + my_getExpression (imm_expr, asarg, force_reloc);
> + if (imm_expr->X_op != O_constant
> + || imm_expr->X_add_number >= xlen
> + || imm_expr->X_add_number < 0)
> + break;
> + ip->insn_opcode
> + |= ENCODE_NDS_BFO_IMM6L (imm_expr->X_add_number);
> + imm_expr->X_op = O_absent;
> + asarg = expr_parse_end;
> + continue;
> + case 'G':
> + case 'H':
> + {
> + bool store = *oparg == 'H';
> + bfd_reloc_code_real_type reloc;
> + offsetT n;
> + insn_t bits;
> + bool valid;
> +
> + my_getExpression (imm_expr, asarg, force_reloc);
> + n = imm_expr->X_add_number;
> + switch (*++oparg)
> + {
> + case 'b':
> + valid = store ? VALID_NDS_SBGP_IMM (n)
> + : VALID_NDS_LBGP_IMM (n);
> + bits = store ? ENCODE_NDS_SBGP_IMM (n)
> + : ENCODE_NDS_LBGP_IMM (n);
> + reloc = store ? BFD_RELOC_RISCV_NDS_GPREL_18S0_S
> + : BFD_RELOC_RISCV_NDS_GPREL_18S0_I;
> + break;
> + case 'h':
> + valid = store ? VALID_NDS_SHGP_IMM (n)
> + : VALID_NDS_LHGP_IMM (n);
> + bits = store ? ENCODE_NDS_SHGP_IMM (n)
> + : ENCODE_NDS_LHGP_IMM (n);
> + reloc = store ? BFD_RELOC_RISCV_NDS_GPREL_17S1_S
> + : BFD_RELOC_RISCV_NDS_GPREL_17S1_I;
> + break;
> + case 'w':
> + valid = store ? VALID_NDS_SWGP_IMM (n)
> + : VALID_NDS_LWGP_IMM (n);
> + bits = store ? ENCODE_NDS_SWGP_IMM (n)
> + : ENCODE_NDS_LWGP_IMM (n);
> + reloc = store ? BFD_RELOC_RISCV_NDS_GPREL_17S2_S
> + : BFD_RELOC_RISCV_NDS_GPREL_17S2_I;
> + break;
> + case 'd':
> + valid = store ? VALID_NDS_SDGP_IMM (n)
> + : VALID_NDS_LDGP_IMM (n);
> + bits = store ? ENCODE_NDS_SDGP_IMM (n)
> + : ENCODE_NDS_LDGP_IMM (n);
> + reloc = store ? BFD_RELOC_RISCV_NDS_GPREL_17S3_S
> + : BFD_RELOC_RISCV_NDS_GPREL_17S3_I;
> + break;
> + default:
> + goto unknown_riscv_ip_operand;
> + }
> +
> + if (imm_expr->X_op == O_constant)
> + {
> + if (!valid)
> + break;
> + ip->insn_opcode |= bits;
> + imm_expr->X_op = O_absent;
> + }
> + else if (imm_expr->X_op == O_symbol)
> + *imm_reloc = reloc;
> + else
> + break;
> + asarg = expr_parse_end;
> + continue;
> + }
> + default:
> + goto unknown_riscv_ip_operand;
> + }
> + break;
> case 't': /* Vendor-specific (T-head) operands. */
> {
> size_t n;
> @@ -5298,6 +5476,34 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg)
> case BFD_RELOC_RISCV_ALIGN:
> break;
>
> + case BFD_RELOC_RISCV_NDS_BRANCH_10:
> + if (fixP->fx_addsy)
> + {
> + /* Fill in a tentative value to improve objdump readability. */
> + bfd_vma target = S_GET_VALUE (fixP->fx_addsy) + *valP;
> + bfd_vma delta = target - md_pcrel_from (fixP);
> + bfd_putl32 (bfd_getl32 (buf) | ENCODE_NDS_BRANCH_IMM10 (delta), buf);
> + if (!riscv_opts.relax && S_IS_LOCAL (fixP->fx_addsy))
> + {
> + if (!VALID_NDS_BRANCH_IMM10 (delta))
> + as_bad_where (fixP->fx_file, fixP->fx_line,
> + _("invalid NDS_BRANCH_10 offset (%+lld)"),
> + (long long) delta);
> + fixP->fx_done = 1;
> + }
> + }
> + break;
> +
> + case BFD_RELOC_RISCV_NDS_GPREL_18S0_I:
> + case BFD_RELOC_RISCV_NDS_GPREL_17S1_I:
> + case BFD_RELOC_RISCV_NDS_GPREL_17S2_I:
> + case BFD_RELOC_RISCV_NDS_GPREL_17S3_I:
> + case BFD_RELOC_RISCV_NDS_GPREL_18S0_S:
> + case BFD_RELOC_RISCV_NDS_GPREL_17S1_S:
> + case BFD_RELOC_RISCV_NDS_GPREL_17S2_S:
> + case BFD_RELOC_RISCV_NDS_GPREL_17S3_S:
> + break;
> +
> default:
> /* We ignore generic BFD relocations we don't know about. */
> if (bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type) != NULL)
> diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi
> index 200a723f1a0..22d70eef206 100644
> --- a/gas/doc/c-riscv.texi
> +++ b/gas/doc/c-riscv.texi
> @@ -766,6 +766,11 @@ extensions supported and provides the location of their
> publicly-released documentation:
>
> @table @r
> +@item XAndesPerf
> +The XAndesPerf extension provides performance enhancement instructions, including branch instructions, load effective address instructions, GP-relative instructions, and string processing instructions.
> +
> +It is documented in @url{https://github.com/andestech/andes-v5-isa/releases/download/ast-v5_4_0-release/AndeStar_V5_ISA_Spec_UM165-v1.5.08-20250317.pdf}.
> +
> @item XAndesBFHCvt
> The XAndesBFHCvt extension provides scalar BF16 and FP32 conversion instructions.
>
> diff --git a/gas/testsuite/gas/riscv/march-help.l b/gas/testsuite/gas/riscv/march-help.l
> index 90afc2e195f..ebaab1f4520 100644
> --- a/gas/testsuite/gas/riscv/march-help.l
> +++ b/gas/testsuite/gas/riscv/march-help.l
> @@ -173,6 +173,7 @@ All available -march extensions for RISC-V:
> smmpm 1.0
> sspm 1.0
> supm 1.0
> + xandesperf 5.0
> xandesbfhcvt 5.0
> xandesvbfhcvt 5.0
> xandesvsintload 5.0
> diff --git a/gas/testsuite/gas/riscv/x-andes-perf.d b/gas/testsuite/gas/riscv/x-andes-perf.d
> new file mode 100644
> index 00000000000..7d21f646edd
> --- /dev/null
> +++ b/gas/testsuite/gas/riscv/x-andes-perf.d
> @@ -0,0 +1,95 @@
> +#as: -march=rv64i_xandesperf
> +#source: x-andes-perf.s
> +#objdump: -dr
> +
> +.*:[ ]+file format .*
> +
> +
> +Disassembly of section .text:
> +
> +0+000 <target>:
> +[ ]+[0-9a-f]+:[ ]+01f570db[ ]+nds\.bbc[ ]+a0,63,0.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]target
> +[ ]+[0-9a-f]+:[ ]+01f570db[ ]+nds\.bbc[ ]+a0,63,4.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]\*ABS\*\+0x1000
> +[ ]+[0-9a-f]+:[ ]+fff57cdb[ ]+nds\.bbs[ ]+a0,63,0.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]target
> +[ ]+[0-9a-f]+:[ ]+41f570db[ ]+nds\.bbs[ ]+a0,63,c.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]\*ABS\*\+0x1000
> +[ ]+[0-9a-f]+:[ ]+fff558db[ ]+nds\.beqc[ ]+a0,127,0.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]target
> +[ ]+[0-9a-f]+:[ ]+41f550db[ ]+nds\.beqc[ ]+a0,127,14.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]\*ABS\*\+0x1000
> +[ ]+[0-9a-f]+:[ ]+fff564db[ ]+nds\.bnec[ ]+a0,127,0.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]target
> +[ ]+[0-9a-f]+:[ ]+41f560db[ ]+nds\.bnec[ ]+a0,127,1c.*
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_BRANCH_10[ ]\*ABS\*\+0x1000
> +[ ]+[0-9a-f]+:[ ]+fc15b55b[ ]+nds\.bfos[ ]+a0,a1,63,1
> +[ ]+[0-9a-f]+:[ ]+07f5a55b[ ]+nds\.bfoz[ ]+a0,a1,1,63
> +[ ]+[0-9a-f]+:[ ]+0ac5855b[ ]+nds\.lea\.h[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+0cc5855b[ ]+nds\.lea\.w[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+0ec5855b[ ]+nds\.lea\.d[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+10c5855b[ ]+nds\.lea\.b\.ze[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+12c5855b[ ]+nds\.lea\.h\.ze[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+14c5855b[ ]+nds\.lea\.w\.ze[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+16c5855b[ ]+nds\.lea\.d\.ze[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+0000150b[ ]+nds\.addigp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_18S0_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffffd50b[ ]+nds\.addigp[ ]+a0,-1
> +[ ]+[0-9a-f]+:[ ]+0000050b[ ]+nds\.lbgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_18S0_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffffc50b[ ]+nds\.lbgp[ ]+a0,-1
> +[ ]+[0-9a-f]+:[ ]+0000250b[ ]+nds\.lbugp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_18S0_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffffe50b[ ]+nds\.lbugp[ ]+a0,-1
> +[ ]+[0-9a-f]+:[ ]+0000152b[ ]+nds\.lhgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S1_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffff952b[ ]+nds\.lhgp[ ]+a0,-2
> +[ ]+[0-9a-f]+:[ ]+0000552b[ ]+nds\.lhugp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S1_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffffd52b[ ]+nds\.lhugp[ ]+a0,-2
> +[ ]+[0-9a-f]+:[ ]+0000252b[ ]+nds\.lwgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S2_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffffa52b[ ]+nds\.lwgp[ ]+a0,-4
> +[ ]+[0-9a-f]+:[ ]+0000652b[ ]+nds\.lwugp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S2_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffffe52b[ ]+nds\.lwugp[ ]+a0,-4
> +[ ]+[0-9a-f]+:[ ]+0000352b[ ]+nds\.ldgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S3_I[ ]target
> +[ ]+[0-9a-f]+:[ ]+ffffb52b[ ]+nds\.ldgp[ ]+a0,-8
> +[ ]+[0-9a-f]+:[ ]+00a0300b[ ]+nds\.sbgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_18S0_S[ ]target
> +[ ]+[0-9a-f]+:[ ]+feafff8b[ ]+nds\.sbgp[ ]+a0,-1
> +[ ]+[0-9a-f]+:[ ]+00a0002b[ ]+nds\.shgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S1_S[ ]target
> +[ ]+[0-9a-f]+:[ ]+feaf8fab[ ]+nds\.shgp[ ]+a0,-2
> +[ ]+[0-9a-f]+:[ ]+00a0402b[ ]+nds\.swgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S2_S[ ]target
> +[ ]+[0-9a-f]+:[ ]+feafcfab[ ]+nds\.swgp[ ]+a0,-4
> +[ ]+[0-9a-f]+:[ ]+00a0702b[ ]+nds\.sdgp[ ]+a0,0
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_VENDOR[ ]ANDES
> +[ ]+[0-9a-f]+:[ ]+R_RISCV_NDS_GPREL_17S3_S[ ]target
> +[ ]+[0-9a-f]+:[ ]+feafffab[ ]+nds\.sdgp[ ]+a0,-8
> +[ ]+[0-9a-f]+:[ ]+20c5855b[ ]+nds\.ffb[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+22c5855b[ ]+nds\.ffzmism[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+24c5855b[ ]+nds\.ffmism[ ]+a0,a1,a2
> +[ ]+[0-9a-f]+:[ ]+26c5855b[ ]+nds\.flmism[ ]+a0,a1,a2
> diff --git a/gas/testsuite/gas/riscv/x-andes-perf.s b/gas/testsuite/gas/riscv/x-andes-perf.s
> new file mode 100644
> index 00000000000..38c45ce0157
> --- /dev/null
> +++ b/gas/testsuite/gas/riscv/x-andes-perf.s
> @@ -0,0 +1,46 @@
> +target:
> + nds.bbc a0, 63, target
> + nds.bbc a0, 63, 0x1000
> + nds.bbs a0, 63, target
> + nds.bbs a0, 63, 0x1000
> + nds.beqc a0, 127, target
> + nds.beqc a0, 127, 0x1000
> + nds.bnec a0, 127, target
> + nds.bnec a0, 127, 0x1000
> + nds.bfos a0, a1, 63, 1
> + nds.bfoz a0, a1, 1, 63
> + nds.lea.h a0, a1, a2
> + nds.lea.w a0, a1, a2
> + nds.lea.d a0, a1, a2
> + nds.lea.b.ze a0, a1, a2
> + nds.lea.h.ze a0, a1, a2
> + nds.lea.w.ze a0, a1, a2
> + nds.lea.d.ze a0, a1, a2
> + nds.addigp a0, target
> + nds.addigp a0, -1
> + nds.lbgp a0, target
> + nds.lbgp a0, -1
> + nds.lbugp a0, target
> + nds.lbugp a0, -1
> + nds.lhgp a0, target
> + nds.lhgp a0, -2
> + nds.lhugp a0, target
> + nds.lhugp a0, -2
> + nds.lwgp a0, target
> + nds.lwgp a0, -4
> + nds.lwugp a0, target
> + nds.lwugp a0, -4
> + nds.ldgp a0, target
> + nds.ldgp a0, -8
> + nds.sbgp a0, target
> + nds.sbgp a0, -1
> + nds.shgp a0, target
> + nds.shgp a0, -2
> + nds.swgp a0, target
> + nds.swgp a0, -4
> + nds.sdgp a0, target
> + nds.sdgp a0, -8
> + nds.ffb a0, a1, a2
> + nds.ffzmism a0, a1, a2
> + nds.ffmism a0, a1, a2
> + nds.flmism a0, a1, a2
> diff --git a/include/elf/riscv.h b/include/elf/riscv.h
> index a9f9aae77a0..10f3be6360f 100644
> --- a/include/elf/riscv.h
> +++ b/include/elf/riscv.h
> @@ -99,6 +99,19 @@ START_RELOC_NUMBERS (elf_riscv_reloc_type)
> RELOC_NUMBER (R_RISCV_VENDOR, 191)
> END_RELOC_NUMBERS ()
>
> +/* Andes vendor-specific relocations. */
> +START_RELOC_NUMBERS (elf_riscv_nds_reloc_type)
> + RELOC_NUMBER (R_RISCV_NDS_BRANCH_10, 241)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_18S0_I, 246)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_17S1_I, 247)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_17S2_I, 248)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_17S3_I, 249)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_18S0_S, 250)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_17S1_S, 251)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_17S2_S, 252)
> + RELOC_NUMBER (R_RISCV_NDS_GPREL_17S3_S, 253)
> +END_RELOC_NUMBERS ()
> +
> /* Internal relocations used exclusively by the relaxation pass. */
> #define R_RISCV_DELETE (R_RISCV_INTERNAL_FIRST)
> #define R_RISCV_DELETE_AND_RELAX (R_RISCV_INTERNAL_FIRST + 1)
> @@ -130,7 +143,8 @@ END_RELOC_NUMBERS ()
> #define RISCV_VENDORS(VENDOR) \
> VENDOR (NDS, nds, "ANDES") \
> VENDOR (QC, qc, "QUALCOMM") */
> -#define RISCV_VENDORS(VENDOR)
> +#define RISCV_VENDORS(VENDOR) \
> + VENDOR (NDS, nds, "ANDES")
>
> /* Used for readelf. */
> #ifdef RELOC_MACROS_GEN_FUNC
> diff --git a/include/opcode/riscv-opc.h b/include/opcode/riscv-opc.h
> index 6b5004772a1..3a12e0f65c4 100644
> --- a/include/opcode/riscv-opc.h
> +++ b/include/opcode/riscv-opc.h
> @@ -2607,6 +2607,65 @@
> #define MASK_VFQWBDOTA_ALT_VV 0xfc00707f
> #define MATCH_VFBDOTA_VV 0xac001077
> #define MASK_VFBDOTA_VV 0xfc00707f
> +/* Vendor-specific (Andes) XAndesPerf instructions. */
> +#define MATCH_NDS_BBC 0x705b
> +#define MASK_NDS_BBC 0x4000707f
> +#define MATCH_NDS_BBS 0x4000705b
> +#define MASK_NDS_BBS 0x4000707f
> +#define MATCH_NDS_BEQC 0x505b
> +#define MASK_NDS_BEQC 0x707f
> +#define MATCH_NDS_BNEC 0x605b
> +#define MASK_NDS_BNEC 0x707f
> +#define MATCH_NDS_BFOS 0x305b
> +#define MASK_NDS_BFOS 0x707f
> +#define MATCH_NDS_BFOZ 0x205b
> +#define MASK_NDS_BFOZ 0x707f
> +#define MATCH_NDS_LEA_H 0xa00005b
> +#define MASK_NDS_LEA_H 0xfe00707f
> +#define MATCH_NDS_LEA_W 0xc00005b
> +#define MASK_NDS_LEA_W 0xfe00707f
> +#define MATCH_NDS_LEA_D 0xe00005b
> +#define MASK_NDS_LEA_D 0xfe00707f
> +#define MATCH_NDS_LEA_B_ZE 0x1000005b
> +#define MASK_NDS_LEA_B_ZE 0xfe00707f
> +#define MATCH_NDS_LEA_H_ZE 0x1200005b
> +#define MASK_NDS_LEA_H_ZE 0xfe00707f
> +#define MATCH_NDS_LEA_W_ZE 0x1400005b
> +#define MASK_NDS_LEA_W_ZE 0xfe00707f
> +#define MATCH_NDS_LEA_D_ZE 0x1600005b
> +#define MASK_NDS_LEA_D_ZE 0xfe00707f
> +#define MATCH_NDS_ADDIGP 0x100b
> +#define MASK_NDS_ADDIGP 0x307f
> +#define MATCH_NDS_LBGP 0xb
> +#define MASK_NDS_LBGP 0x307f
> +#define MATCH_NDS_LBUGP 0x200b
> +#define MASK_NDS_LBUGP 0x307f
> +#define MATCH_NDS_LHGP 0x102b
> +#define MASK_NDS_LHGP 0x707f
> +#define MATCH_NDS_LHUGP 0x502b
> +#define MASK_NDS_LHUGP 0x707f
> +#define MATCH_NDS_LWGP 0x202b
> +#define MASK_NDS_LWGP 0x707f
> +#define MATCH_NDS_LWUGP 0x602b
> +#define MASK_NDS_LWUGP 0x707f
> +#define MATCH_NDS_LDGP 0x302b
> +#define MASK_NDS_LDGP 0x707f
> +#define MATCH_NDS_SBGP 0x300b
> +#define MASK_NDS_SBGP 0x307f
> +#define MATCH_NDS_SHGP 0x2b
> +#define MASK_NDS_SHGP 0x707f
> +#define MATCH_NDS_SWGP 0x402b
> +#define MASK_NDS_SWGP 0x707f
> +#define MATCH_NDS_SDGP 0x702b
> +#define MASK_NDS_SDGP 0x707f
> +#define MATCH_NDS_FFB 0x2000005b
> +#define MASK_NDS_FFB 0xfe00707f
> +#define MATCH_NDS_FFZMISM 0x2200005b
> +#define MASK_NDS_FFZMISM 0xfe00707f
> +#define MATCH_NDS_FFMISM 0x2400005b
> +#define MASK_NDS_FFMISM 0xfe00707f
> +#define MATCH_NDS_FLMISM 0x2600005b
> +#define MASK_NDS_FLMISM 0xfe00707f
> /* Vendor-specific (Andes) XAndesBFHCvt instructions. */
> #define MATCH_NDS_FCVT_S_BF16 0x1405b
> #define MASK_NDS_FCVT_S_BF16 0xfe0ff07f
> @@ -5150,6 +5209,36 @@ DECLARE_INSN(sd_rl, MATCH_SDR, MASK_SDR)
> DECLARE_INSN(sctrclr, MATCH_SCTRCLR, MASK_SCTRCLR)
> /* Smrnmi instruction */
> DECLARE_INSN(mnret, MATCH_MNRET, MASK_MNRET)
> +/* Vendor-specific (Andes) XAndesPerf instructions. */
> +DECLARE_INSN(nds_bbc, MATCH_NDS_BBC, MASK_NDS_BBC)
> +DECLARE_INSN(nds_bbs, MATCH_NDS_BBS, MASK_NDS_BBS)
> +DECLARE_INSN(nds_beqc, MATCH_NDS_BEQC, MASK_NDS_BEQC)
> +DECLARE_INSN(nds_bnec, MATCH_NDS_BNEC, MASK_NDS_BNEC)
> +DECLARE_INSN(nds_bfos, MATCH_NDS_BFOS, MASK_NDS_BFOS)
> +DECLARE_INSN(nds_bfoz, MATCH_NDS_BFOZ, MASK_NDS_BFOZ)
> +DECLARE_INSN(nds_lea_h, MATCH_NDS_LEA_H, MASK_NDS_LEA_H)
> +DECLARE_INSN(nds_lea_w, MATCH_NDS_LEA_W, MASK_NDS_LEA_W)
> +DECLARE_INSN(nds_lea_d, MATCH_NDS_LEA_D, MASK_NDS_LEA_D)
> +DECLARE_INSN(nds_lea_b_ze, MATCH_NDS_LEA_B_ZE, MASK_NDS_LEA_B_ZE)
> +DECLARE_INSN(nds_lea_h_ze, MATCH_NDS_LEA_H_ZE, MASK_NDS_LEA_H_ZE)
> +DECLARE_INSN(nds_lea_w_ze, MATCH_NDS_LEA_W_ZE, MASK_NDS_LEA_W_ZE)
> +DECLARE_INSN(nds_lea_d_ze, MATCH_NDS_LEA_D_ZE, MASK_NDS_LEA_D_ZE)
> +DECLARE_INSN(nds_addigp, MATCH_NDS_ADDIGP, MASK_NDS_ADDIGP)
> +DECLARE_INSN(nds_lbgp, MATCH_NDS_LBGP, MASK_NDS_LBGP)
> +DECLARE_INSN(nds_lbugp, MATCH_NDS_LBUGP, MASK_NDS_LBUGP)
> +DECLARE_INSN(nds_lhgp, MATCH_NDS_LHGP, MASK_NDS_LHGP)
> +DECLARE_INSN(nds_lhugp, MATCH_NDS_LHUGP, MASK_NDS_LHUGP)
> +DECLARE_INSN(nds_lwgp, MATCH_NDS_LWGP, MASK_NDS_LWGP)
> +DECLARE_INSN(nds_lwugp, MATCH_NDS_LWUGP, MASK_NDS_LWUGP)
> +DECLARE_INSN(nds_ldgp, MATCH_NDS_LDGP, MASK_NDS_LDGP)
> +DECLARE_INSN(nds_sbgp, MATCH_NDS_SBGP, MASK_NDS_SBGP)
> +DECLARE_INSN(nds_shgp, MATCH_NDS_SHGP, MASK_NDS_SHGP)
> +DECLARE_INSN(nds_swgp, MATCH_NDS_SWGP, MASK_NDS_SWGP)
> +DECLARE_INSN(nds_sdgp, MATCH_NDS_SDGP, MASK_NDS_SDGP)
> +DECLARE_INSN(nds_ffb, MATCH_NDS_FFB, MASK_NDS_FFB)
> +DECLARE_INSN(nds_ffzmism, MATCH_NDS_FFZMISM, MASK_NDS_FFZMISM)
> +DECLARE_INSN(nds_ffmism, MATCH_NDS_FFMISM, MASK_NDS_FFMISM)
> +DECLARE_INSN(nds_flmism, MATCH_NDS_FLMISM, MASK_NDS_FLMISM)
> /* Vendor-specific (Andes) XAndesBFHCvt instructions. */
> DECLARE_INSN(nds_fcvt_s_bf16, MATCH_NDS_FCVT_S_BF16, MASK_NDS_FCVT_S_BF16)
> DECLARE_INSN(nds_fcvt_bf16_s, MATCH_NDS_FCVT_BF16_S, MASK_NDS_FCVT_BF16_S)
> diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h
> index a4a89ddda8d..306a4d5d824 100644
> --- a/include/opcode/riscv.h
> +++ b/include/opcode/riscv.h
> @@ -117,6 +117,33 @@ static inline unsigned int riscv_insn_length (insn_t insn)
> (RV_X(x, 2, 2) << 4)
> #define EXTRACT_ZCMT_INDEX(x) \
> (RV_X(x, 2, 8))
> +/* Vendor-specific (Andes) extract macros. */
> +#define EXTRACT_NDS_BRANCH_IMM6(x) \
> + (RV_X(x, 20, 5) | (RV_X(x, 7, 1) << 5))
> +#define EXTRACT_NDS_BRANCH_IMM7(x) \
> + (RV_X(x, 20, 5) | (RV_X(x, 7, 1) << 5) | (RV_X(x, 30, 1) << 6))
> +#define EXTRACT_NDS_BRANCH_IMM10(x) \
> + ((RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 5) << 5) | (RV_IMM_SIGN(x) << 10))
> +#define EXTRACT_NDS_BFO_IMM6H(x) \
> + (RV_X(x, 26, 6))
> +#define EXTRACT_NDS_BFO_IMM6L(x) \
> + (RV_X(x, 20, 6))
> +#define EXTRACT_NDS_LBGP_IMM(x) \
> + (RV_X(x, 14, 1) | (RV_X(x, 21, 10) << 1) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_IMM_SIGN(x) << 17))
> +#define EXTRACT_NDS_LHGP_IMM(x) \
> + ((RV_X(x, 21, 10) << 1) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_IMM_SIGN(x) << 17))
> +#define EXTRACT_NDS_LWGP_IMM(x) \
> + ((RV_X(x, 22, 9) << 2) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 21, 1) << 17) | (RV_IMM_SIGN(x) << 18))
> +#define EXTRACT_NDS_LDGP_IMM(x) \
> + ((RV_X(x, 23, 8) << 3) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 21, 2) << 17) | (RV_IMM_SIGN(x) << 19))
> +#define EXTRACT_NDS_SBGP_IMM(x) \
> + ((RV_X(x, 14, 1)) | (RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_IMM_SIGN(x) << 17))
> +#define EXTRACT_NDS_SHGP_IMM(x) \
> + ((RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_IMM_SIGN(x) << 17))
> +#define EXTRACT_NDS_SWGP_IMM(x) \
> + ((RV_X(x, 9, 3) << 2) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 8, 1) << 17) | (RV_IMM_SIGN(x) << 18))
> +#define EXTRACT_NDS_SDGP_IMM(x) \
> + ((RV_X(x, 10, 2) << 3) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_X(x, 17, 3) << 12) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 8, 2) << 17) | (RV_IMM_SIGN(x) << 19))
> /* Vendor-specific (CORE-V) extract macros. */
> #define EXTRACT_CV_IS2_UIMM5(x) \
> (RV_X(x, 20, 5))
> @@ -199,6 +226,33 @@ static inline unsigned int riscv_insn_length (insn_t insn)
> (RV_X(x, 4, 2) << 2)
> #define ENCODE_ZCMT_INDEX(x) \
> (RV_X(x, 0, 8) << 2)
> +/* Vendor-specific (Andes) encode macros. */
> +#define ENCODE_NDS_BRANCH_IMM6(x) \
> + ((RV_X(x, 0, 5) << 20) | (RV_X(x, 5, 1) << 7))
> +#define ENCODE_NDS_BRANCH_IMM7(x) \
> + ((RV_X(x, 0, 5) << 20) | (RV_X(x, 5, 1) << 7) | (RV_X(x, 6, 1) << 30))
> +#define ENCODE_NDS_BRANCH_IMM10(x) \
> + ((RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 5) << 25) | (RV_X(x, 10, 1) << 31))
> +#define ENCODE_NDS_BFO_IMM6H(x) \
> + (RV_X(x, 0, 6) << 26)
> +#define ENCODE_NDS_BFO_IMM6L(x) \
> + (RV_X(x, 0, 6) << 20)
> +#define ENCODE_NDS_LBGP_IMM(x) \
> + ((RV_X(x, 0, 1) << 14) | (RV_X(x, 1, 10) << 21) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 1) << 31))
> +#define ENCODE_NDS_LHGP_IMM(x) \
> + ((RV_X(x, 1, 10) << 21) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 1) << 31))
> +#define ENCODE_NDS_LWGP_IMM(x) \
> + ((RV_X(x, 2, 9) << 22) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 1) << 21) | (RV_X(x, 18, 1) << 31))
> +#define ENCODE_NDS_LDGP_IMM(x) \
> + ((RV_X(x, 3, 8) << 23) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 2) << 21) | (RV_X(x, 19, 1) << 31))
> +#define ENCODE_NDS_SBGP_IMM(x) \
> + ((RV_X(x, 0, 1) << 14) | (RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 1) << 31))
> +#define ENCODE_NDS_SHGP_IMM(x) \
> + ((RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 1) << 31))
> +#define ENCODE_NDS_SWGP_IMM(x) \
> + ((RV_X(x, 2, 3) << 9) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 1) << 8) | (RV_X(x, 18, 1) << 31))
> +#define ENCODE_NDS_SDGP_IMM(x) \
> + ((RV_X(x, 3, 2) << 10) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 3) << 17) | (RV_X(x, 15, 2) << 15) | (RV_X(x, 17, 2) << 8) | (RV_X(x, 19, 1) << 31))
> /* Vendor-specific (CORE-V) encode macros. */
> #define ENCODE_CV_IS2_UIMM5(x) \
> (RV_X(x, 0, 5) << 20)
> @@ -249,6 +303,17 @@ static inline unsigned int riscv_insn_length (insn_t insn)
> #define VALID_ZCB_BYTE_UIMM(x) (EXTRACT_ZCB_BYTE_UIMM(ENCODE_ZCB_BYTE_UIMM(x)) == (x))
> #define VALID_ZCB_HALFWORD_UIMM(x) (EXTRACT_ZCB_HALFWORD_UIMM(ENCODE_ZCB_HALFWORD_UIMM(x)) == (x))
> #define VALID_ZCMP_SPIMM(x) (EXTRACT_ZCMP_SPIMM(ENCODE_ZCMP_SPIMM(x)) == (x))
> +/* Vendor-specific (Andes) valid macros. */
> +#define VALID_NDS_BRANCH_IMM7(x) (EXTRACT_NDS_BRANCH_IMM7(ENCODE_NDS_BRANCH_IMM7(x)) == (x))
> +#define VALID_NDS_BRANCH_IMM10(x) (EXTRACT_NDS_BRANCH_IMM10(ENCODE_NDS_BRANCH_IMM10(x)) == (x))
> +#define VALID_NDS_LBGP_IMM(x) (EXTRACT_NDS_LBGP_IMM(ENCODE_NDS_LBGP_IMM(x)) == (x))
> +#define VALID_NDS_LHGP_IMM(x) (EXTRACT_NDS_LHGP_IMM(ENCODE_NDS_LHGP_IMM(x)) == (x))
> +#define VALID_NDS_LWGP_IMM(x) (EXTRACT_NDS_LWGP_IMM(ENCODE_NDS_LWGP_IMM(x)) == (x))
> +#define VALID_NDS_LDGP_IMM(x) (EXTRACT_NDS_LDGP_IMM(ENCODE_NDS_LDGP_IMM(x)) == (x))
> +#define VALID_NDS_SBGP_IMM(x) (EXTRACT_NDS_SBGP_IMM(ENCODE_NDS_SBGP_IMM(x)) == (x))
> +#define VALID_NDS_SHGP_IMM(x) (EXTRACT_NDS_SHGP_IMM(ENCODE_NDS_SHGP_IMM(x)) == (x))
> +#define VALID_NDS_SWGP_IMM(x) (EXTRACT_NDS_SWGP_IMM(ENCODE_NDS_SWGP_IMM(x)) == (x))
> +#define VALID_NDS_SDGP_IMM(x) (EXTRACT_NDS_SDGP_IMM(ENCODE_NDS_SDGP_IMM(x)) == (x))
>
> #define RISCV_RTYPE(insn, rd, rs1, rs2) \
> ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2))
> @@ -606,6 +671,7 @@ enum riscv_insn_class
> INSN_CLASS_ZACAS,
> INSN_CLASS_ZABHA_AND_ZACAS,
> INSN_CLASS_H,
> + INSN_CLASS_XANDESPERF,
> INSN_CLASS_XANDESBFHCVT,
> INSN_CLASS_XANDESVBFHCVT,
> INSN_CLASS_XANDESVSINTLOAD,
> diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> index 9503e4b3935..bea6e05a477 100644
> --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> @@ -156,6 +156,7 @@ if [istarget "riscv*-*-*"] {
> run_dump_test "align-small-region"
> run_dump_test "vendor-relocs"
> run_dump_test "vendor-relocs-r"
> + run_dump_test "x-andes-perf-reloc"
> run_dump_test "call-relax"
> run_dump_test "jal-to-cjal"
> run_dump_test "j-to-cj-32"
> diff --git a/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.d b/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.d
> new file mode 100644
> index 00000000000..83b59e62795
> --- /dev/null
> +++ b/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.d
> @@ -0,0 +1,28 @@
> +#source: x-andes-perf-reloc.s
> +#as: -march=rv64i_xandesperf
> +#ld: -m[riscv_choose_lp64_emul] -Tx-andes-perf-reloc.ld
> +#objdump: -d
> +
> +.*:[ ]+file format .*
> +
> +
> +Disassembly of section .text:
> +
> +[0-9a-f]+ <_start>:
> +.*:[ ]+[0-9a-f]+[ ]+nds\.bbc[ ]+a0,0,10040 <target>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.bbs[ ]+a0,0,10040 <target>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.beqc[ ]+a0,0,10040 <target>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.bnec[ ]+a0,0,10040 <target>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.addigp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.lbgp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.lbugp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.lhgp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.lhugp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.lwgp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.lwugp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.ldgp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.sbgp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.shgp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.swgp[ ]+a0,-2048 # 20000 <data>
> +.*:[ ]+[0-9a-f]+[ ]+nds\.sdgp[ ]+a0,-2048 # 20000 <data>
> +#pass
> diff --git a/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.ld b/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.ld
> new file mode 100644
> index 00000000000..19deafdfd3a
> --- /dev/null
> +++ b/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.ld
> @@ -0,0 +1,10 @@
> +ENTRY(_start)
> +SECTIONS {
> + .text 0x10000 : {
> + *(.text*)
> + }
> + .sdata 0x20000 : {
> + *(.sdata*)
> + }
> + __global_pointer$ = 0x20800;
> +}
> diff --git a/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.s b/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.s
> new file mode 100644
> index 00000000000..4006eb69a6b
> --- /dev/null
> +++ b/ld/testsuite/ld-riscv-elf/x-andes-perf-reloc.s
> @@ -0,0 +1,26 @@
> + .text
> + .globl _start
> + .type _start,@function
> +_start:
> + nds.bbc a0, 0, target
> + nds.bbs a0, 0, target
> + nds.beqc a0, 0, target
> + nds.bnec a0, 0, target
> + nds.addigp a0, data
> + nds.lbgp a0, data
> + nds.lbugp a0, data
> + nds.lhgp a0, data
> + nds.lhugp a0, data
> + nds.lwgp a0, data
> + nds.lwugp a0, data
> + nds.ldgp a0, data
> + nds.sbgp a0, data
> + nds.shgp a0, data
> + nds.swgp a0, data
> + nds.sdgp a0, data
> +target:
> + ret
> +
> + .section .sdata, "aw"
> +data:
> + .dword 0
> diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
> index 9c7dc881069..2c66a0c06ed 100644
> --- a/opcodes/riscv-dis.c
> +++ b/opcodes/riscv-dis.c
> @@ -849,6 +849,95 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
> case 'X': /* Vendor-specific operands. */
> switch (*++oparg)
> {
> + case 'a': /* Vendor-specific (Andes) operands. */
> + switch (*++oparg)
> + {
> + case 'g':
> + info->target = EXTRACT_NDS_BRANCH_IMM10 (l) + pc;
> + (*info->print_address_func) (info->target, info);
> + break;
> + case 'h':
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_BFO_IMM6H (l));
> + break;
> + case 'i':
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_BRANCH_IMM7 (l));
> + break;
> + case 'k':
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_BRANCH_IMM6 (l));
> + break;
> + case 'l':
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_BFO_IMM6L (l));
> + break;
> + case 'G':
> + switch (*++oparg)
> + {
> + case 'b':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_LBGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_LBGP_IMM (l));
> + break;
> + case 'h':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_LHGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_LHGP_IMM (l));
> + break;
> + case 'w':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_LWGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_LWGP_IMM (l));
> + break;
> + case 'd':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_LDGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_LDGP_IMM (l));
> + break;
> + default:
> + goto undefined_modifier;
> + }
> + break;
> + case 'H':
> + switch (*++oparg)
> + {
> + case 'b':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_SBGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_SBGP_IMM (l));
> + break;
> + case 'h':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_SHGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_SHGP_IMM (l));
> + break;
> + case 'w':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_SWGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_SWGP_IMM (l));
> + break;
> + case 'd':
> + maybe_print_address (pd, X_GP, EXTRACT_NDS_SDGP_IMM (l),
> + 0);
> + print (info->stream, dis_style_immediate, "%d",
> + (int)EXTRACT_NDS_SDGP_IMM (l));
> + break;
> + default:
> + goto undefined_modifier;
> + }
> + break;
> + default:
> + goto undefined_modifier;
> + }
> + break;
> case 't': /* Vendor-specific (T-head) operands. */
> {
> size_t n;
> diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c
> index bab27dfb209..53a29b8188b 100644
> --- a/opcodes/riscv-opc.c
> +++ b/opcodes/riscv-opc.c
> @@ -2354,6 +2354,37 @@ const struct riscv_opcode riscv_opcodes[] =
> {"hsv.w", 0, INSN_CLASS_H, "t,0(s)", MATCH_HSV_W, MASK_HSV_W, match_opcode, INSN_DREF|INSN_4_BYTE },
> {"hsv.d", 64, INSN_CLASS_H, "t,0(s)", MATCH_HSV_D, MASK_HSV_D, match_opcode, INSN_DREF|INSN_8_BYTE },
>
> +/* Vendor-specific (Andes) XAndesPerf instructions. */
> +{"nds.bbc", 0, INSN_CLASS_XANDESPERF, "s,Xak,Xag", MATCH_NDS_BBC, MASK_NDS_BBC, match_opcode, INSN_CONDBRANCH},
> +{"nds.bbs", 0, INSN_CLASS_XANDESPERF, "s,Xak,Xag", MATCH_NDS_BBS, MASK_NDS_BBS, match_opcode, INSN_CONDBRANCH},
> +{"nds.beqc", 0, INSN_CLASS_XANDESPERF, "s,Xai,Xag", MATCH_NDS_BEQC, MASK_NDS_BEQC, match_opcode, INSN_CONDBRANCH},
> +{"nds.bnec", 0, INSN_CLASS_XANDESPERF, "s,Xai,Xag", MATCH_NDS_BNEC, MASK_NDS_BNEC, match_opcode, INSN_CONDBRANCH},
> +{"nds.bfos", 0, INSN_CLASS_XANDESPERF, "d,s,Xah,Xal", MATCH_NDS_BFOS, MASK_NDS_BFOS, match_opcode, 0},
> +{"nds.bfoz", 0, INSN_CLASS_XANDESPERF, "d,s,Xah,Xal", MATCH_NDS_BFOZ, MASK_NDS_BFOZ, match_opcode, 0},
> +{"nds.lea.h", 0, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_LEA_H, MASK_NDS_LEA_H, match_opcode, 0},
> +{"nds.lea.w", 0, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_LEA_W, MASK_NDS_LEA_W, match_opcode, 0},
> +{"nds.lea.d", 0, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_LEA_D, MASK_NDS_LEA_D, match_opcode, 0},
> +{"nds.lea.b.ze", 64, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_LEA_B_ZE, MASK_NDS_LEA_B_ZE, match_opcode, 0},
> +{"nds.lea.h.ze", 64, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_LEA_H_ZE, MASK_NDS_LEA_H_ZE, match_opcode, 0},
> +{"nds.lea.w.ze", 64, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_LEA_W_ZE, MASK_NDS_LEA_W_ZE, match_opcode, 0},
> +{"nds.lea.d.ze", 64, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_LEA_D_ZE, MASK_NDS_LEA_D_ZE, match_opcode, 0},
> +{"nds.addigp", 0, INSN_CLASS_XANDESPERF, "d,XaGb", MATCH_NDS_ADDIGP, MASK_NDS_ADDIGP, match_opcode, 0},
> +{"nds.lbgp", 0, INSN_CLASS_XANDESPERF, "d,XaGb", MATCH_NDS_LBGP, MASK_NDS_LBGP, match_opcode, INSN_DREF|INSN_1_BYTE},
> +{"nds.lbugp", 0, INSN_CLASS_XANDESPERF, "d,XaGb", MATCH_NDS_LBUGP, MASK_NDS_LBUGP, match_opcode, INSN_DREF|INSN_1_BYTE},
> +{"nds.lhgp", 0, INSN_CLASS_XANDESPERF, "d,XaGh", MATCH_NDS_LHGP, MASK_NDS_LHGP, match_opcode, INSN_DREF|INSN_2_BYTE},
> +{"nds.lhugp", 0, INSN_CLASS_XANDESPERF, "d,XaGh", MATCH_NDS_LHUGP, MASK_NDS_LHUGP, match_opcode, INSN_DREF|INSN_2_BYTE},
> +{"nds.lwgp", 0, INSN_CLASS_XANDESPERF, "d,XaGw", MATCH_NDS_LWGP, MASK_NDS_LWGP, match_opcode, INSN_DREF|INSN_4_BYTE},
> +{"nds.lwugp", 64, INSN_CLASS_XANDESPERF, "d,XaGw", MATCH_NDS_LWUGP, MASK_NDS_LWUGP, match_opcode, INSN_DREF|INSN_4_BYTE},
> +{"nds.ldgp", 64, INSN_CLASS_XANDESPERF, "d,XaGd", MATCH_NDS_LDGP, MASK_NDS_LDGP, match_opcode, INSN_DREF|INSN_8_BYTE},
> +{"nds.sbgp", 0, INSN_CLASS_XANDESPERF, "t,XaHb", MATCH_NDS_SBGP, MASK_NDS_SBGP, match_opcode, INSN_DREF|INSN_1_BYTE},
> +{"nds.shgp", 0, INSN_CLASS_XANDESPERF, "t,XaHh", MATCH_NDS_SHGP, MASK_NDS_SHGP, match_opcode, INSN_DREF|INSN_2_BYTE},
> +{"nds.swgp", 0, INSN_CLASS_XANDESPERF, "t,XaHw", MATCH_NDS_SWGP, MASK_NDS_SWGP, match_opcode, INSN_DREF|INSN_4_BYTE},
> +{"nds.sdgp", 64, INSN_CLASS_XANDESPERF, "t,XaHd", MATCH_NDS_SDGP, MASK_NDS_SDGP, match_opcode, INSN_DREF|INSN_8_BYTE},
> +{"nds.ffb", 0, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_FFB, MASK_NDS_FFB, match_opcode, 0},
> +{"nds.ffzmism", 0, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_FFZMISM, MASK_NDS_FFZMISM, match_opcode, 0},
> +{"nds.ffmism", 0, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_FFMISM, MASK_NDS_FFMISM, match_opcode, 0},
> +{"nds.flmism", 0, INSN_CLASS_XANDESPERF, "d,s,t", MATCH_NDS_FLMISM, MASK_NDS_FLMISM, match_opcode, 0},
> +
> /* Vendor-specific (Andes) XAndesBFHCvt instructions. */
> {"nds.fcvt.s.bf16", 0, INSN_CLASS_XANDESBFHCVT, "D,T", MATCH_NDS_FCVT_S_BF16, MASK_NDS_FCVT_S_BF16, match_opcode, 0},
> {"nds.fcvt.bf16.s", 0, INSN_CLASS_XANDESBFHCVT, "D,T", MATCH_NDS_FCVT_BF16_S, MASK_NDS_FCVT_BF16_S, match_opcode, 0},
> --
> 2.54.0
>
More information about the Binutils
mailing list