Skip to content

Commit

Permalink
Minor tweaks to Choice API
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Feb 19, 2024
1 parent fe403f9 commit af00ec5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
10 changes: 4 additions & 6 deletions fidget/src/core/compiler/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ impl SsaOp {
| SsaOp::MaxRegReg(out, ..) => *out,
}
}
/// Returns the number of choices made by the given opcode
///
/// This is always zero or one.
pub fn choice_count(&self) -> usize {
/// Returns true if the given opcode is associated with a choice
pub fn has_choice(&self) -> bool {
match self {
SsaOp::Input(..)
| SsaOp::Var(..)
Expand All @@ -153,11 +151,11 @@ impl SsaOp {
| SsaOp::SubRegReg(..)
| SsaOp::DivRegReg(..)
| SsaOp::DivRegImm(..)
| SsaOp::DivImmReg(..) => 0,
| SsaOp::DivImmReg(..) => false,
SsaOp::MinRegImm(..)
| SsaOp::MaxRegImm(..)
| SsaOp::MinRegReg(..)
| SsaOp::MaxRegReg(..) => 1,
| SsaOp::MaxRegReg(..) => true,
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions fidget/src/core/vm/choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,27 @@ impl std::ops::BitOrAssign<Choice> for Choice {
}
}
}

impl std::ops::Not for Choice {
type Output = Choice;
fn not(self) -> Self {
match self {
Self::Unknown => Self::Both,
Self::Left => Self::Right,
Self::Right => Self::Left,
Self::Both => Self::Unknown,
}
}
}

impl std::ops::BitAndAssign<Choice> for Choice {
fn bitand_assign(&mut self, other: Self) {
*self = match (*self as u8) | ((!other as u8) & 0b11) {
0 => Self::Unknown,
1 => Self::Left,
2 => Self::Right,
3 => Self::Both,
_ => unreachable!(),
}
}
}
2 changes: 1 addition & 1 deletion fidget/src/core/vm/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<const N: u8> VmData<N> {
let index = op.output();

if workspace.active(index).is_none() {
for _ in 0..op.choice_count() {
if op.has_choice() {
choice_iter.next().unwrap();
}
continue;
Expand Down

0 comments on commit af00ec5

Please sign in to comment.