binutils Newspaper
JUNE 15, 2026
risc-v Ready to Land

RISC-V: match_*() improvements

For RISC-V, macro instruction matching functions now assert macro-only usage and avoid potentially incorrect opcode matching due to macro enumeration changes.

This patch improves the RISC-V instruction matching functions. It adds an assertion to match_rs1_nonzero() to ensure it’s only used by macro instructions. It also skips match_opcode() for macro entries to prevent false negatives when the macro enumeration changes. This change ensures the matching functions behave as expected when dealing with macro instructions.

In the Thread 1 participant
  1. Jiawei <jiawei@iscas.ac.cn> reviewer

    Agrees with the changes, noting that skipping `match_opcode()` for macro entries is reasonable, and the assertion documents the macro-only use nicely.

    “LGTM. Skipping match_opcode() for macro entries looks reasonable to me, and the assertion in match_rs1_nonzero() documents its macro-only use nicely.”

In Details

The patch modifies functions like match_rd_even and match_rs1_nonzero in opcodes/riscv-opc.c. These functions are used during assembly to determine if an instruction matches a given pattern. The change ensures that macro instructions are handled correctly, avoiding potential errors due to changes in macro enumeration.

For Context

When assembling code, the assembler needs to determine which instruction matches the given input. This involves matching the instruction's opcode and operands against known patterns. This patch modifies the matching logic for RISC-V macro instructions in the GNU assembler (gas). It ensures that the matching process is accurate and avoids potential errors caused by changes in the set of defined macros.

Filed Under: risc-vassemblermacrosinstruction matching