wire / wire-format / barrel-shifter
A barrel shifter shifts/rotates an n-bit value by any amount in a single cycle. It uses log2(n) stages of 2:1 multiplexers. Stage i shifts by 2^i if the corresponding bit of the shift amount is 1. Supports: SHL (shift left logical), SHR (shift right logical), SAR (shift right arithmetic), ROL (rotate left), ROR (rotate right).
aka: Barrel shifter
spec: Digital logic design
A barrel shifter shifts/rotates an n-bit value by any amount in a single cycle. It uses log2(n) stages of 2:1 multiplexers. Stage i shifts by 2^i if the corresponding bit of the shift amount is 1. Supports: SHL (shift left logical), SHR (shift right logical), SAR (shift right arithmetic), ROL (rotate left), ROR (rotate right).
| field | size | meaning |
|---|---|---|
| Stage 0 | n 2:1 muxes | Shift by 0 or 1 bit (controlled by shift_amount[0]). |
| Stage 1 | n 2:1 muxes | Shift by 0 or 2 bits (controlled by shift_amount[1]). |
| Stage i | n 2:1 muxes | Shift by 0 or 2^i bits (controlled by shift_amount[i]). |
| Total stages | log2(n) | For 32-bit: 5 stages. For 64-bit: 6 stages. |
| Total muxes | n * log2(n) | For 32-bit: 32 * 5 = 160 muxes. |
| Shift amount | log2(n) bits | For 32-bit: 5 bits (0-31). For 64-bit: 6 bits (0-63). |
example:
00 00 00 00
Barrel shifter (placeholder)
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/barrel-shifter
or /wire-format/barrel-shifter.json