Skip to main content

var_shr_with_sticky

Function var_shr_with_sticky 

Source
pub fn var_shr_with_sticky(
    b: &CircuitBuilder,
    x: Wire,
    d: Wire,
    saturate_at_63: bool,
) -> (Wire, Wire)
Expand description

Performs variable right shift with sticky bit tracking.

This implements a barrel shifter that can shift by any amount 0-63, with optional saturation. All bits shifted out are OR’d together to create a “sticky” bit that tracks whether any precision was lost.

§Parameters

  • x: Value to shift
  • d: Shift amount (0-63, or optionally saturated at 63)
  • saturate_at_63: If true, shifts >= 64 are treated as 63; if false, they wrap

§Returns

  • First wire: The shifted value
  • Second wire: Sticky bit (all-1 mask if any bits were lost, all-0 otherwise)