Struct machine_check::BitvectorArray
source · 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 140)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
fn main() {
let toy_program = [
// (0) set r0 to zero
Bitvector::new(0b0100_0000_0000),
// (1) set r1 to one
Bitvector::new(0b0101_0000_0001),
// (2) set r2 to zero
Bitvector::new(0b0110_0000_0000),
// --- main loop ---
// (3) store r1 content to data location 0
Bitvector::new(0b1100_0000_0000),
// (4) store r2 content to data location 1
Bitvector::new(0b1100_0000_0001),
// (5) read input location 0 to r3
Bitvector::new(0b0011_0100_0000),
// (6) jump to (3) if r3 bit 0 is set
Bitvector::new(0b0011_1000_0011),
// (7) increment r2
Bitvector::new(0b0010_0000_1001),
// (8) store r2 content to data location 1
Bitvector::new(0b1110_0000_0001),
// (9) jump to (3)
Bitvector::new(0b0001_1000_0011),
];
// load toy program to program memory, filling unused locations with 0
let mut progmem = BitvectorArray::new_filled(Bitvector::new(0));
for (index, instruction) in toy_program.into_iter().enumerate() {
progmem[Bitvector::new(index as u64)] = instruction;
}
let system = machine_module::System { progmem };
machine_check::run(system);
}
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>
source§impl<const I: u32, const L: u32> PartialEq for BitvectorArray<I, L>
impl<const I: u32, const L: u32> PartialEq for BitvectorArray<I, L>
source§fn eq(&self, other: &BitvectorArray<I, L>) -> bool
fn eq(&self, other: &BitvectorArray<I, L>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.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> 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<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.