-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: some stubs for (ternary) bit vectors (#9)
- Loading branch information
1 parent
f841014
commit b89220d
Showing
6 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
pub struct BitVector { | ||
pub(crate) value: u64, | ||
} | ||
|
||
impl BitVector { | ||
#[allow(dead_code)] | ||
fn new(value: u64) -> Self { | ||
BitVector { value } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::ternary::TernaryBitVector; | ||
|
||
struct Machine { | ||
#[allow(dead_code)] | ||
regs: [TernaryBitVector; 32], | ||
} | ||
|
||
impl Machine { | ||
#[allow(dead_code)] | ||
fn new() -> Self { | ||
Machine { | ||
regs: [TernaryBitVector::new(0, u64::max_value()); 32], | ||
} | ||
} | ||
} | ||
|
||
// fn has_inv_value_for_addi(raw: IType) -> bool { | ||
// true | ||
// } | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use riscv_decode::types::*; | ||
use riscv_decode::Instruction; | ||
|
||
#[test] | ||
fn can_find_input_for_addi() { | ||
let machine = Machine::new(); | ||
|
||
let raw = IType(0); | ||
let _addi = Instruction::Addi(raw); | ||
|
||
let _rd = raw.rd(); | ||
let _rs1_value = machine.regs[raw.rs1() as usize]; | ||
|
||
let _s = raw.imm(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::bitvec::BitVector; | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
pub struct TernaryBitVector { | ||
xlo: u64, | ||
xhi: u64, | ||
} | ||
|
||
impl TernaryBitVector { | ||
pub fn new(xlo: u64, xhi: u64) -> Self { | ||
assert!(Self::valid(xlo, xhi), "is not a valid ternary bit vector"); | ||
Self { xlo, xhi } | ||
} | ||
|
||
/// verifies that these two values can form a valid ternary bit vector | ||
pub fn valid(xlo: u64, xhi: u64) -> bool { | ||
!xlo | xhi == u64::max_value() | ||
} | ||
|
||
/// verifies that all constant bits of a ternary bit vector match a bit vector | ||
#[allow(dead_code)] | ||
pub fn mcb(&self, other: &BitVector) -> bool { | ||
(self.xhi & other.value == other.value) && (self.xlo | other.value == other.value) | ||
} | ||
} |