[−][src]Struct kaze::Signal
Represents a collection of 1 or more bits driven by some source.
A Signal
can be created by several Module
methods (eg. lit
) or as a result of combining existing Signal
s (eg. concat
). Signal
s are local to their respective Module
s.
A Signal
behaves similarly to a wire
in verilog, except that it's always driven.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let a = m.lit(0xffu8, 8); // 8-bit signal let b = m.input("my_input", 27); // 27-bit signal let c = b.bits(7, 0); // 8-bit signal let d = a + c; // 8-bit signal m.output("my_output", d); // 8-bit output driven by d
Methods
impl<'a> Signal<'a>
[src]
#[must_use]
pub fn bit_width(&self) -> u32
[src]
Returns the bit width of the given Signal
.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); assert_eq!(m.lit(42u32, 7).bit_width(), 7); assert_eq!(m.input("i", 27).bit_width(), 27); assert_eq!(m.reg("some_reg", 46).value.bit_width(), 46); assert_eq!((!m.low()).bit_width(), 1); assert_eq!((m.lit(25u8, 8) + m.lit(42u8, 8)).bit_width(), 8); assert_eq!((m.high() & m.low()).bit_width(), 1); assert_eq!((m.high() | m.low()).bit_width(), 1); assert_eq!(m.lit(12u32, 100).bit(30).bit_width(), 1); assert_eq!(m.lit(1u32, 99).bits(37, 29).bit_width(), 9); assert_eq!(m.high().repeat(35).bit_width(), 35); assert_eq!(m.lit(1u32, 20).concat(m.high()).bit_width(), 21); assert_eq!(m.lit(0xaau32, 8).eq(m.lit(0xaau32, 8)).bit_width(), 1); assert_eq!(m.lit(0xaau32, 8).ne(m.lit(0xaau32, 8)).bit_width(), 1); assert_eq!(m.lit(0xaau32, 8).lt(m.lit(0xaau32, 8)).bit_width(), 1); assert_eq!(m.lit(0xaau32, 8).le(m.lit(0xaau32, 8)).bit_width(), 1); assert_eq!(m.lit(0xaau32, 8).gt(m.lit(0xaau32, 8)).bit_width(), 1); assert_eq!(m.lit(0xaau32, 8).ge(m.lit(0xaau32, 8)).bit_width(), 1); assert_eq!(m.mux(m.low(), m.lit(5u32, 4), m.lit(6u32, 4)).bit_width(), 4);
pub fn bit(&'a self, index: u32) -> &Signal<'a>
[src]
Creates a Signal
that represents the value of the single bit of this Signal
at index index
, where index
equal to 0
represents this Signal
's least significant bit.
Panics
Panics if index
is greater than or equal to this Signal
's bit_width
.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit = m.lit(0b0110u32, 4); let bit_0 = lit.bit(0); // Represents 0 let bit_1 = lit.bit(1); // Represents 1 let bit_2 = lit.bit(2); // Represents 1 let bit_3 = lit.bit(3); // Represents 0
pub fn bits(&'a self, range_high: u32, range_low: u32) -> &Signal<'a>
[src]
Creates a Signal
that represents a contiguous subset of the bits of this Signal
, starting at range_low
as the least significant bit and ending at range_high
as the most significant bit, inclusive.
Panics
Panics if either range_low
or range_high
is greater than or equal to the bit width of this Signal
, or if range_low
is greater than range_high
.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit = m.lit(0b0110u32, 4); let bits_210 = lit.bits(2, 0); // Represents 0b110 let bits_321 = lit.bits(3, 1); // Represents 0b011 let bits_10 = lit.bits(1, 0); // Represents 0b10 let bits_32 = lit.bits(3, 2); // Represents 0b01 let bits_2 = lit.bits(2, 2); // Represents 1, equivalent to lit.bit(2)
pub fn repeat(&'a self, count: u32) -> &Signal<'a>
[src]
Creates a Signal
that represents this Signal
repeated count
times.
Panics
Panics if self.bit_width() * count
is less than MIN_SIGNAL_BIT_WIDTH
or greater than MAX_SIGNAL_BIT_WIDTH
.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit = m.lit(0xau32, 4); let repeat_1 = lit.repeat(1); // Equivalent to just lit let repeat_2 = lit.repeat(2); // Equivalent to 8-bit lit with value 0xaa let repeat_5 = lit.repeat(5); // Equivalent to 20-bit lit with value 0xaaaaa let repeat_8 = lit.repeat(8); // Equivalent to 32-bit lit with value 0xaaaaaaaa
pub fn concat(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents this Signal
concatenated with rhs
.
self
represents the upper bits in the resulting Signal
, and rhs
represents the lower bits.
Panics
Panics if self.bit_width() + rhs.bit_width()
is greater than MAX_SIGNAL_BIT_WIDTH
.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xffu32, 8); let concat_1 = lit_a.concat(lit_b); // Equivalent to 12-bit lit with value 0xaff let concat_2 = lit_b.concat(lit_a); // Equivalent to 12-bit lit with value 0xffa let concat_3 = lit_a.concat(lit_a); // Equivalent to 8-bit lit with value 0xaa
pub fn eq(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of a bitwise boolean equality comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, or if the bit widths of self
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let eq_1 = lit_a.eq(lit_a); // Equivalent to m.high() let eq_2 = lit_b.eq(lit_b); // Equivalent to m.high() let eq_3 = lit_a.eq(lit_b); // Equivalent to m.low() let eq_4 = lit_b.eq(lit_a); // Equivalent to m.low()
pub fn ne(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of a bitwise boolean inequality comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, or if the bit widths of self
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let ne_1 = lit_a.ne(lit_a); // Equivalent to m.low() let ne_2 = lit_b.ne(lit_b); // Equivalent to m.low() let ne_3 = lit_a.ne(lit_b); // Equivalent to m.high() let ne_4 = lit_b.ne(lit_a); // Equivalent to m.high()
pub fn lt(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of an unsigned <
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, or if the bit widths of self
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let lt_1 = lit_a.lt(lit_a); // Equivalent to m.low() let lt_2 = lit_b.lt(lit_b); // Equivalent to m.low() let lt_3 = lit_a.lt(lit_b); // Equivalent to m.high() let lt_4 = lit_b.lt(lit_a); // Equivalent to m.low()
pub fn le(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of an unsigned <=
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, or if the bit widths of self
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let le_1 = lit_a.le(lit_a); // Equivalent to m.high() let le_2 = lit_b.le(lit_b); // Equivalent to m.high() let le_3 = lit_a.le(lit_b); // Equivalent to m.high() let le_4 = lit_b.le(lit_a); // Equivalent to m.low()
pub fn gt(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of an unsigned >
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, or if the bit widths of self
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let gt_1 = lit_a.gt(lit_a); // Equivalent to m.low() let gt_2 = lit_b.gt(lit_b); // Equivalent to m.low() let gt_3 = lit_a.gt(lit_b); // Equivalent to m.low() let gt_4 = lit_b.gt(lit_a); // Equivalent to m.high()
pub fn ge(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of an unsigned >=
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, or if the bit widths of self
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let ge_1 = lit_a.ge(lit_a); // Equivalent to m.high() let ge_2 = lit_b.ge(lit_b); // Equivalent to m.high() let ge_3 = lit_a.ge(lit_b); // Equivalent to m.low() let ge_4 = lit_b.ge(lit_a); // Equivalent to m.high()
pub fn lt_signed(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of a signed <
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, if the bit widths of self
and rhs
aren't equal, or if the bit widths of self
and rhs
are 1.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let lt_signed_1 = lit_a.lt_signed(lit_a); // Equivalent to m.low() let lt_signed_2 = lit_b.lt_signed(lit_b); // Equivalent to m.low() let lt_signed_3 = lit_a.lt_signed(lit_b); // Equivalent to m.high() let lt_signed_4 = lit_b.lt_signed(lit_a); // Equivalent to m.low()
pub fn le_signed(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of a signed <=
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, if the bit widths of self
and rhs
aren't equal, or if the bit widths of self
and rhs
are 1.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let le_signed_1 = lit_a.le_signed(lit_a); // Equivalent to m.high() let le_signed_2 = lit_b.le_signed(lit_b); // Equivalent to m.high() let le_signed_3 = lit_a.le_signed(lit_b); // Equivalent to m.high() let le_signed_4 = lit_b.le_signed(lit_a); // Equivalent to m.low()
pub fn gt_signed(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of a signed >
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, if the bit widths of self
and rhs
aren't equal, or if the bit widths of self
and rhs
are 1.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let gt_signed_1 = lit_a.gt_signed(lit_a); // Equivalent to m.low() let gt_signed_2 = lit_b.gt_signed(lit_b); // Equivalent to m.low() let gt_signed_3 = lit_a.gt_signed(lit_b); // Equivalent to m.low() let gt_signed_4 = lit_b.gt_signed(lit_a); // Equivalent to m.high()
pub fn ge_signed(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Creates a Signal
that represents the single-bit result of a signed >=
comparison between self
and rhs
.
Panics
Panics if self
and rhs
belong to different Module
s, if the bit widths of self
and rhs
aren't equal, or if the bit widths of self
and rhs
are 1.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lit_a = m.lit(0xau32, 4); let lit_b = m.lit(0xbu32, 4); let ge_signed_1 = lit_a.ge_signed(lit_a); // Equivalent to m.high() let ge_signed_2 = lit_b.ge_signed(lit_b); // Equivalent to m.high() let ge_signed_3 = lit_a.ge_signed(lit_b); // Equivalent to m.low() let ge_signed_4 = lit_b.ge_signed(lit_a); // Equivalent to m.high()
pub fn shr_arithmetic(&'a self, rhs: &'a Signal<'a>) -> &Signal<'a>
[src]
Combines two Signal
s, producing a new Signal
that represents self
arithmetically shifted right by rhs
bits.
The difference is truncated to self
's bit_width
. If rhs
specifies a value that's greater than or equal to self
's bit_width
, the resulting value will be all 1
bits.
Panics
Panics if lhs
and rhs
belong to different Module
s.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.lit(0x80000000u32, 32); let rhs = m.lit(1u32, 1); let shifted = lhs.shr_arithmetic(rhs); // Equivalent to m.lit(0xc0000000u32, 32)
pub fn mux(
&'a self,
when_true: &'a Signal<'a>,
when_false: &'a Signal<'a>
) -> &Signal<'a>
[src]
&'a self,
when_true: &'a Signal<'a>,
when_false: &'a Signal<'a>
) -> &Signal<'a>
Creates a 2:1 multiplexer that represents when_true
's value when self
is high, and when_false
's value when self
is low.
This is a convenience wrapper for Module
::mux
.
Panics
Panics if when_true
or when_false
belong to a different Module
than self
, if self
's bit width is not 1, or if the bit widths of when_true
and when_false
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let cond = m.input("cond", 1); let a = m.input("a", 8); let b = m.input("b", 8); m.output("my_output", cond.mux(a, b)); // Outputs a when cond is high, b otherwise
Trait Implementations
impl<'a> Add<&'a Signal<'a>> for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self
[src]
Combines two Signal
s, producing a new Signal
that represents the sum of the original two Signal
s.
The sum is truncated to the Signal
's bit_width
. If a carry bit is desired, the operands can be concat
enated with a 0
bit before the operation.
Panics
Panics if lhs
and rhs
belong to different Module
s, or if the bit widths of lhs
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.lit(1u32, 32); let rhs = m.lit(2u32, 32); let sum = lhs + rhs; // Equivalent to m.lit(3u32, 32) let lhs = m.low().concat(m.lit(0xffffffffu32, 32)); // Concat 0 bits with operands for carry let rhs = m.low().concat(m.lit(0x00000001u32, 32)); let carry_sum = lhs + rhs; // Equivalent to m.lit(0x100000000u64, 33) let sum = carry_sum.bits(31, 0); // Equivalent to m.lit(0u32, 32) let carry = carry_sum.bit(32); // Equivalent to m.lit(true, 1)
impl<'a> BitAnd<&'a Signal<'a>> for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the &
operator.
fn bitand(self, rhs: Self) -> Self
[src]
Combines two Signal
s, producing a new Signal
whose bits represent the bitwise &
of each of the bits of the original two Signal
s.
Panics
Panics if lhs
and rhs
belong to different Module
s, or if the bit widths of lhs
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.low(); let rhs = m.high(); let single_bitand = lhs & rhs; let lhs = m.input("in1", 3); let rhs = m.input("in2", 3); let multi_bitand = lhs & rhs;
impl<'a> BitOr<&'a Signal<'a>> for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the |
operator.
fn bitor(self, rhs: Self) -> Self
[src]
Combines two Signal
s, producing a new Signal
whose bits represent the bitwise |
of each of the bits of the original two Signal
s.
Panics
Panics if lhs
and rhs
belong to different Module
s, or if the bit widths of lhs
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.low(); let rhs = m.high(); let single_bitor = lhs | rhs; let lhs = m.input("in1", 3); let rhs = m.input("in2", 3); let multi_bitor = lhs | rhs;
impl<'a> BitXor<&'a Signal<'a>> for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the ^
operator.
fn bitxor(self, rhs: Self) -> Self
[src]
Combines two Signal
s, producing a new Signal
whose bits represent the bitwise ^
of each of the bits of the original two Signal
s.
Panics
Panics if lhs
and rhs
belong to different Module
s, or if the bit widths of lhs
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.low(); let rhs = m.high(); let single_bitxor = lhs ^ rhs; let lhs = m.input("in1", 3); let rhs = m.input("in2", 3); let multi_bitxor = lhs ^ rhs;
impl<'a> Eq for &'a Signal<'a>
[src]
impl<'a> Hash for &'a Signal<'a>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> Not for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the !
operator.
fn not(self) -> Self
[src]
Produces a new Signal
whose bits represent the bitwise !
of each of the bits of the original Signal
.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let input1 = m.input("input1", 1); let single_not = !input1; let input2 = m.input("input2", 6); let multi_not = !input2;
impl<'a> PartialEq<&'a Signal<'a>> for &'a Signal<'a>
[src]
impl<'a> Shl<&'a Signal<'a>> for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the <<
operator.
fn shl(self, rhs: Self) -> Self
[src]
Combines two Signal
s, producing a new Signal
that represents self
logically shifted left by rhs
bits.
The difference is truncated to self
's bit_width
. If rhs
specifies a value that's greater than or equal to self
's bit_width
, the resulting value will be zero.
Panics
Panics if lhs
and rhs
belong to different Module
s.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.lit(3u32, 32); let rhs = m.lit(2u32, 2); let shifted = lhs << rhs; // Equivalent to m.lit(12u32, 32)
impl<'a> Shr<&'a Signal<'a>> for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the >>
operator.
fn shr(self, rhs: Self) -> Self
[src]
Combines two Signal
s, producing a new Signal
that represents self
logically shifted right by rhs
bits.
The difference is truncated to self
's bit_width
. If rhs
specifies a value that's greater than or equal to self
's bit_width
, the resulting value will be zero.
Panics
Panics if lhs
and rhs
belong to different Module
s.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.lit(12u32, 32); let rhs = m.lit(2u32, 2); let shifted = lhs >> rhs; // Equivalent to m.lit(3u32, 32)
impl<'a> Sub<&'a Signal<'a>> for &'a Signal<'a>
[src]
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self
[src]
Combines two Signal
s, producing a new Signal
that represents the difference of the original two Signal
s.
The difference is truncated to the Signal
's bit_width
.
Panics
Panics if lhs
and rhs
belong to different Module
s, or if the bit widths of lhs
and rhs
aren't equal.
Examples
use kaze::*; let c = Context::new(); let m = c.module("MyModule"); let lhs = m.lit(3u32, 32); let rhs = m.lit(2u32, 32); let difference = lhs - rhs; // Equivalent to m.lit(1u32, 32)
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Signal<'a>
impl<'a> !Send for Signal<'a>
impl<'a> !Sync for Signal<'a>
impl<'a> Unpin for Signal<'a>
impl<'a> !UnwindSafe for Signal<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,