Expand description
Variable-amount shift gadgets.
CircuitBuilder only exposes shifts by a compile-time-constant amount. This module provides
barrel-shifter gadgets that shift by a runtime Wire amount:
var_sll,var_srl,var_sra— shift by the low 6 bits ofshift(full bit range for a 64-bit word).var_sll_blocks,var_srl_blocks,var_sra_blocks— most general: the actual bit-shift isshift * 2^block_bits, withshifttreated as ashift_bits-bit unsigned integer. Useful when the caller knows the shift is a multiple of a fixed power of two, or when only a narrow range of shifts is possible.var_sll_bytes,var_srl_bytes,var_sra_bytes— byte-granularity shifts (shift in0..8bytes).
§Precondition
For *_blocks, the shift amount is treated as a shift_bits-bit unsigned integer; bits above
position shift_bits - 1 are ignored. Callers must ensure shift < 2^shift_bits; this is
not checked by the gadget. The other variants impose the same precondition with shift_bits
fixed (6 for the base variants, 3 for the byte variants).
§Cost
*_blocks: 3 * shift_bits AND constraints. Base variants: 18. Byte variants: 9.
Functions§
- var_sll
- Variable-amount logical left shift.
- var_
sll_ blocks - Variable-amount logical left shift by blocks of
2^block_bitsbits. - var_
sll_ bytes - Variable-amount logical left shift by whole bytes.
- var_sra
- Variable-amount arithmetic right shift.
- var_
sra_ blocks - Variable-amount arithmetic right shift by blocks of
2^block_bitsbits. - var_
sra_ bytes - Variable-amount arithmetic right shift by whole bytes.
- var_srl
- Variable-amount logical right shift.
- var_
srl_ blocks - Variable-amount logical right shift by blocks of
2^block_bitsbits. - var_
srl_ bytes - Variable-amount logical right shift by whole bytes.