BinaryGadgets

Trait BinaryGadgets 

Source
pub trait BinaryGadgets: FancyBinary + BundleGadgets {
Show 26 methods // Provided methods fn bin_constant_bundle( &mut self, val: u128, nbits: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_output( &mut self, x: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Option<u128>> { ... } fn bin_outputs( &mut self, xs: &[BinaryBundle<Self::Item>], channel: &mut Channel<'_>, ) -> Result<Option<Vec<u128>>> { ... } fn bin_xor( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, ) -> BinaryBundle<Self::Item> { ... } fn bin_and( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_or( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_addition( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<(BinaryBundle<Self::Item>, Self::Item)> { ... } fn bin_addition_no_carry( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_multiplication_lower_half( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_mul( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_div( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_twos_complement( &mut self, xs: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_subtraction( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<(BinaryBundle<Self::Item>, Self::Item)> { ... } fn bin_multiplex_constant_bits( &mut self, x: &Self::Item, c1: u128, c2: u128, nbits: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_multiplex( &mut self, b: &Self::Item, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_cmul( &mut self, x: &BinaryBundle<Self::Item>, c: u128, nbits: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_abs( &mut self, x: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_lt_signed( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item> { ... } fn bin_lt( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item> { ... } fn bin_geq( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item> { ... } fn bin_max( &mut self, xs: &[BinaryBundle<Self::Item>], channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_demux( &mut self, x: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Vec<Self::Item>> { ... } fn bin_rsa( &mut self, x: &BinaryBundle<Self::Item>, c: usize, ) -> BinaryBundle<Self::Item> { ... } fn bin_rsl( &mut self, x: &BinaryBundle<Self::Item>, c: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>> { ... } fn bin_shr( &mut self, x: &BinaryBundle<Self::Item>, c: usize, pad: &Self::Item, ) -> BinaryBundle<Self::Item> { ... } fn bin_eq_bundles( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item> { ... }
}
Expand description

Extension trait for Fancy providing gadgets that operate over bundles of mod2 wires.

Provided Methods§

Source

fn bin_constant_bundle( &mut self, val: u128, nbits: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Create a constant bundle using base 2 inputs.

Source

fn bin_output( &mut self, x: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Option<u128>>

Output a binary bundle and interpret the result as a u128.

Source

fn bin_outputs( &mut self, xs: &[BinaryBundle<Self::Item>], channel: &mut Channel<'_>, ) -> Result<Option<Vec<u128>>>

Output a slice of binary bundles and interpret the results as a u128.

Source

fn bin_xor( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, ) -> BinaryBundle<Self::Item>

Xor the bits of two bundles together pairwise.

Source

fn bin_and( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

And the bits of two bundles together pairwise.

Source

fn bin_or( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Or the bits of two bundles together pairwise.

Source

fn bin_addition( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<(BinaryBundle<Self::Item>, Self::Item)>

Binary addition. Returns the result and the carry.

§Panics

This panics if xs and ys do not have equal moduli.

Source

fn bin_addition_no_carry( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Binary addition. Avoids creating extra gates for the final carry.

§Panics

This panics if xs and ys do not have equal moduli.

Source

fn bin_multiplication_lower_half( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Binary multiplication.

Returns the lower-order half of the output bits, ie a number with the same number of bits as the inputs.

§Panics

This panics if xs and ys do not have equal moduli.

Source

fn bin_mul( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Full multiplier.

§Panics

This panics if xs and ys do not have equal moduli.

Source

fn bin_div( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Divider.

§Panics

This panics if xs and ys do not have equal moduli.

Source

fn bin_twos_complement( &mut self, xs: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Compute the twos complement of the input bundle (which must be base 2).

Source

fn bin_subtraction( &mut self, xs: &BinaryBundle<Self::Item>, ys: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<(BinaryBundle<Self::Item>, Self::Item)>

Subtract two binary bundles. Returns the result and whether it underflowed.

Due to the way that twos_complement(0) = 0, underflow indicates y != 0 && x >= y.

Source

fn bin_multiplex_constant_bits( &mut self, x: &Self::Item, c1: u128, c2: u128, nbits: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

If x=0 return c1 as a bundle of constant bits, else return c2.

Source

fn bin_multiplex( &mut self, b: &Self::Item, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Multiplex gadget for binary bundles

Source

fn bin_cmul( &mut self, x: &BinaryBundle<Self::Item>, c: u128, nbits: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Write the constant in binary and that gives you the shift amounts, Eg.. 7x is 4x+2x+x.

Source

fn bin_abs( &mut self, x: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Compute the absolute value of a binary bundle.

Source

fn bin_lt_signed( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Returns 1 if x < y (signed version)

Source

fn bin_lt( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Returns 1 if x < y.

Source

fn bin_geq( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Returns 1 if x >= y.

Source

fn bin_max( &mut self, xs: &[BinaryBundle<Self::Item>], channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

Compute the maximum bundle in xs.

§Panics

Panics if xs is empty.

Source

fn bin_demux( &mut self, x: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Vec<Self::Item>>

Demux a binary bundle into a unary vector.

§Panics

Panics if the length of x is greater than eight.

Source

fn bin_rsa( &mut self, x: &BinaryBundle<Self::Item>, c: usize, ) -> BinaryBundle<Self::Item>

arithmetic right shift (shifts the sign of the MSB into the new spaces)

Source

fn bin_rsl( &mut self, x: &BinaryBundle<Self::Item>, c: usize, channel: &mut Channel<'_>, ) -> Result<BinaryBundle<Self::Item>>

logical right shift (shifts 0 into the empty spaces)

Source

fn bin_shr( &mut self, x: &BinaryBundle<Self::Item>, c: usize, pad: &Self::Item, ) -> BinaryBundle<Self::Item>

shift a value right by a constant, filling space on the right by pad

Source

fn bin_eq_bundles( &mut self, x: &BinaryBundle<Self::Item>, y: &BinaryBundle<Self::Item>, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Compute x == y for binary bundles.

Implementors§