pub struct BitvectorArray<const I: u32, const L: u32> { /* private fields */ }
Expand description
Power-of-two array of bitvectors without signedness information.
The exponent of array size is specified in the first generic parameter I. Element length is specified in the second generic parameter L.
The array is indexed by bitvectors of length I, so no out-of-bound access can occur.
Implementations§
Source§impl<const I: u32, const L: u32> BitvectorArray<I, L>
impl<const I: u32, const L: u32> BitvectorArray<I, L>
Sourcepub fn new_filled(element: Bitvector<L>) -> Self
pub fn new_filled(element: Bitvector<L>) -> Self
Creates a new array filled with the given element.
Examples found in repository?
examples/simple_risc.rs (line 142)
116fn main() {
117 let toy_program = [
118 // (0) set r0 to zero
119 Bitvector::new(0b0100_0000_0000),
120 // (1) set r1 to one
121 Bitvector::new(0b0101_0000_0001),
122 // (2) set r2 to zero
123 Bitvector::new(0b0110_0000_0000),
124 // --- main loop ---
125 // (3) store r1 content to data location 0
126 Bitvector::new(0b1100_0000_0000),
127 // (4) store r2 content to data location 1
128 Bitvector::new(0b1100_0000_0001),
129 // (5) read input location 0 to r3
130 Bitvector::new(0b0011_0100_0000),
131 // (6) jump to (3) if r3 bit 0 is set
132 Bitvector::new(0b0011_1000_0011),
133 // (7) increment r2
134 Bitvector::new(0b0010_0000_1001),
135 // (8) store r2 content to data location 1
136 Bitvector::new(0b1110_0000_0001),
137 // (9) jump to (3)
138 Bitvector::new(0b0001_1000_0011),
139 ];
140
141 // load toy program to program memory, filling unused locations with 0
142 let mut progmem = BitvectorArray::new_filled(Bitvector::new(0));
143 for (index, instruction) in toy_program.into_iter().enumerate() {
144 progmem[Bitvector::new(index as u64)] = instruction;
145 }
146 let system = machine_module::System { progmem };
147 machine_check::run(system);
148}
Sourcepub fn from_slice(slice: &[Bitvector<L>]) -> Self
pub fn from_slice(slice: &[Bitvector<L>]) -> Self
Creates the bitvector array from a correctly sized slice of bitvectors.
Panics if the bitvector slice length is not equal to 2L.
Cannot be used within the machine_description macro.
Trait Implementations§
Source§impl<const I: u32, const L: u32> Clone for BitvectorArray<I, L>
impl<const I: u32, const L: u32> Clone for BitvectorArray<I, L>
Source§fn clone(&self) -> BitvectorArray<I, L>
fn clone(&self) -> BitvectorArray<I, L>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<const I: u32, const L: u32> IntoMck for BitvectorArray<I, L>
impl<const I: u32, const L: u32> IntoMck for BitvectorArray<I, L>
impl<const I: u32, const L: u32> Eq for BitvectorArray<I, L>
impl<const I: u32, const L: u32> StructuralPartialEq for BitvectorArray<I, L>
Auto Trait Implementations§
impl<const I: u32, const L: u32> Freeze for BitvectorArray<I, L>
impl<const I: u32, const L: u32> RefUnwindSafe for BitvectorArray<I, L>
impl<const I: u32, const L: u32> Send for BitvectorArray<I, L>
impl<const I: u32, const L: u32> Sync for BitvectorArray<I, L>
impl<const I: u32, const L: u32> Unpin for BitvectorArray<I, L>
impl<const I: u32, const L: u32> UnwindSafe for BitvectorArray<I, L>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.