RISC-V: Use zext.h for unsigned halfword extension with Zbkb
RISC-V compiler now uses the `zext.h` instruction for unsigned halfword extensions when Zbkb is enabled, improving instruction costing.
This commit enables the use of the zext.h pattern for unsigned halfword extensions on the RISC-V architecture when the Zbkb extension is active. It ensures that the compiler correctly utilizes the pack and packw instructions for this purpose and accurately accounts for the single instruction cost in register extension operations.
In Details
The RISC-V backend in GCC uses patterns defined in .md files to map operations to machine instructions. This patch modifies config/riscv/bitmanip.md and config/riscv/riscv.cc to leverage the zext.h pattern for unsigned halfword extensions when the Zbkb extension is enabled. For RV32, this corresponds to the pack instruction, and for RV64, the packw instruction, when the second source is x0. The riscv_extend_cost function is updated to correctly reflect the single instruction cost for these extensions under Zbkb.
- RISC-V
- An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computer principles, designed for modern processors.
- Zbkb
- A RISC-V bit manipulation extension that provides instructions for bitwise operations, including rotate and XOR, enhancing performance for tasks involving bit manipulation.
- halfword
- A unit of data consisting of 16 bits.
- unsigned extension
- An operation that increases the bit width of an unsigned integer value by padding the most significant bits with zeros.
- zext.h
- Likely refers to a GCC internal pattern name for a zero-extend operation specifically on halfwords, possibly leveraging bit manipulation instructions.
- RV32
- The 32-bit variant of the RISC-V architecture.
- RV64
- The 64-bit variant of the RISC-V architecture.