RISC-V Zba shift-add optimized for division and remainder
RISC-V Zba extension's shift-add instructions are now combined with word division and remainder operations for improved efficiency.
This commit enhances the RISC-V Zba extension by optimizing the combination of shift-add operations with word division and remainder instructions. The change extends existing optimizations for unsigned division and remainder operations. It recognizes that these division/remainder instructions only use the lower word of inputs and sign-extend their results. Consequently, an XLEN-wide shift-add instruction can now precede the division or remainder, replacing a sequence of word shifts and additions, leading to more efficient code generation.
In Details
This patch updates gcc/config/riscv/bitmanip.md to leverage the any_div intrinsic for unsigned division and remainder operations within the Zba extension. Previously, sequences involving word-sized shifts and adds were used before division/remainder. The optimization recognizes that division/remainder instructions effectively operate on a word-sized input and sign-extend their output. Thus, an XLEN-wide shift-add instruction (shNadd) can now be used to replace the preceding word-shift-add sequence, simplifying the instruction stream and potentially improving instruction cache utilizatio…
- RISC-V
- An open-standard instruction set architecture based on Reduced Instruction Set Computing principles. It is modular and extensible, allowing for custom extensions like bit manipulation.
- Zba
- A standard RISC-V extension that adds bit manipulation instructions, specifically focusing on operations like shifts, adds, and their combinations, often used for efficient arithmetic and bitwise operations.
- shift-add
- An operation that combines a bit shift with an addition. In RISC-V's Zba extension, specific instructions like shNadd perform a shift followed by an add, useful for address calculations or certain arithmetic manipulations.
- word division/remainder
- Operations that divide a larger integer by another, producing a quotient and a remainder. In the context of RISC-V, 'word' division/remainder implies operations that may only consider the lower XLEN bits of the operands.
- XLEN
- A parameter in the RISC-V architecture that defines the register and memory address size. For RV32, XLEN is 32; for RV64, XLEN is 64.
- any_div
- A placeholder or intrinsic used in GCC's internal representation to signify a division or remainder operation that can be satisfied by various available instructions, possibly including those that operate on word-sized inputs.