Skip to main content

rotate_left_dynamic

Function rotate_left_dynamic 

Source
pub fn rotate_left_dynamic(
    b: &CircuitBuilder,
    words: &[Wire],
    shift: Wire,
    n_out: usize,
) -> Vec<Wire>
Expand description

Rotates words left by a dynamic word count, returning the first n_out positions.

out[i] is words[(shift + i) % words.len()]. A caller that only needs a prefix reads the wrap-around at positions past its own validity bound, so it must treat those as unconstrained.

§Arguments

  • b - Circuit builder
  • words - The array to rotate
  • shift - Rotate amount in words (only ceil(log2(len)) LSB bits are used)
  • n_out - Number of leading positions to return

§Implementation Details

One barrel stage per bit of shift, largest stage first so the working window shrinks as the stages are applied. That costs one select per position per stage, where a multiplexer per output position would instead cost words.len() - 1 selects each.

§Panics

  • If words is empty
  • If n_out exceeds words.len()