RISC-V uses inverted logical instructions for constants with Zbkb.
RISC-V now uses inverted logical instructions for constants with the Zbkb extension, optimizing mask operations.
The RISC-V architecture can now leverage the Zbkb extension for logical operations with complemented constants. This change optimizes mask operations, such as ~0xf000UL, by using a single lui instruction combined with an andn operation, reducing instruction count and improving efficiency. The compiler now handles these inverted logical operations for Zbkb, aligning with the cost model of the Zbb extension.
In Details
The RISC-V bitmanip extension (Zbkb) introduces bitwise logical operations with immediate operands. This commit modifies the riscv.cc implementation to recognize and synthesize inverted logical operations (e.g., AND NOT, OR NOT, XOR NOT) using complemented constants. For instance, a mask like ~0xf000UL can now be implemented with lui and andn, incurring the same cost as Zbb operations. The bitmanip.md file is updated to enable the constant IOR/XOR splitter for Zbkb.
- Zbkb
- A RISC-V bit manipulation extension that adds instructions for bitwise logical operations (AND, OR, XOR) with immediate values. It enhances efficiency for bitwise tasks.
- ANDN
- Bitwise AND NOT operation. For operands A and B, the result is A AND (NOT B).
- lui
- Load Upper Immediate. A RISC-V instruction that loads a 20-bit immediate value into the upper 20 bits of a 32-bit register, zeroing the lower 12 bits.
- LUI
- Load Upper Immediate. A RISC-V instruction that loads a 20-bit immediate value into the upper 20 bits of a 32-bit register, zeroing the lower 12 bits.
- Zbb
- A RISC-V bit manipulation extension providing basic bitwise operations like AND, OR, XOR, and NOT with register operands.