The alphabetical reference begins: the logical-with-negate flagship and the seven Zbs single-bit operations. All are one-cycle R-type (or OP-IMM shamt-type) instructions.
| Semantics | funct7 / funct3 | In | |
|---|---|---|---|
| andn rd, rs1, rs2 | rd = rs1 & ~rs2 — the mask-off idiom without a NOT. | 0100000 / 111 | Zbb, Zbkb |
| bclr rd, rs1, rs2 | rd = rs1 & ~(1 << (rs2 mod XLEN)) — clear one bit by index. | 0100100 / 001 | Zbs |
| bclri rd, rs1, shamt | Immediate-index clear. | OP-IMM, 0100100 / 001 | Zbs |
| bext rd, rs1, rs2 | rd = (rs1 >> (rs2 mod XLEN)) & 1 — EXTRACT the bit to position 0. The single-bit test. | 0100100 / 101 | Zbs |
| bexti rd, rs1, shamt | Immediate-index extract. | OP-IMM, 0100100 / 101 | Zbs |
| binv rd, rs1, rs2 | rd = rs1 ^ (1 << (rs2 mod XLEN)) — flip one bit. | 0110100 / 001 | Zbs |
| binvi rd, rs1, shamt | Immediate-index invert. | OP-IMM, 0110100 / 001 | Zbs |
| bset rd, rs1, rs2 | rd = rs1 | (1 << (rs2 mod XLEN)) — set one bit. | 0010100 / 001 | Zbs |
Idioms these erase: andn kills the not t0, rs2; and rd, rs1, t0
pair everywhere a mask is applied inverted (branch-free selects,
bitboard code); the Zbs quartet replaces li t0, 1; sll t0, t0, idx; op three-instruction sequences for every dynamic flag operation —
and bexti is the classic “test bit n” in one instruction with the
result ready for a branch.
Hardware Designer Notes
Everything on this page is decode plus a handful of gates on paths you already own. The single-bit one-hot decoder is the only new structure, and it’s a 6-to-64 decoder you likely have in the shifter already.
Minimal Linux-boot hart MUST
- Route the rs2-inverter (shared with the subtractor per the spec’s own hint) for andn/orn/xnor
- Build the one-hot decoder (1 << index-mod-XLEN) once and share it across bclr/binv/bset; bext reuses the existing shifter’s LSB tap
MAY simplify / trap-and-emulate
- Fuse bexti + beqz/bnez into a test-bit-and-branch macro-op — the dominant use pattern
Check yourself — andn & single-bit ops
1.How does bext rd, rs1, rs2 differ from bclr?
2.Why does the RV64 encoding of bclri/bexti/binvi/bseti eat one bit of funct7?
3.What hardware does andn (and orn/xnor) actually cost?