Skip to main content

Module shift

Module shift 

Source
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:

§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_bits bits.
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_bits bits.
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_bits bits.
var_srl_bytes
Variable-amount logical right shift by whole bytes.