#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(clippy::struct_excessive_bools)]
pub struct FenceSet {
pub i: bool,
pub o: bool,
pub r: bool,
pub w: bool,
}
impl FenceSet {
pub const fn from_bits(bits: u8) -> Self {
Self {
i: bits & 0b1000 != 0,
o: bits & 0b0100 != 0,
r: bits & 0b0010 != 0,
w: bits & 0b0001 != 0,
}
}
pub const fn to_bits(self) -> u8 {
((self.i as u8) << 3) | ((self.o as u8) << 2) | ((self.r as u8) << 1) | (self.w as u8)
}
pub const fn is_empty(self) -> bool {
!self.i && !self.o && !self.r && !self.w
}
pub const fn is_full(self) -> bool {
self.i && self.o && self.r && self.w
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Fence {
pub pred: FenceSet,
pub succ: FenceSet,
}
impl Fence {
pub const fn decode(inst: u32) -> Self {
let pred_bits = ((inst >> 24) & 0xF) as u8;
let succ_bits = ((inst >> 20) & 0xF) as u8;
Self { pred: FenceSet::from_bits(pred_bits), succ: FenceSet::from_bits(succ_bits) }
}
pub const fn is_tso(&self) -> bool {
self.pred.r
&& self.pred.w
&& !self.pred.i
&& !self.pred.o
&& self.succ.r
&& self.succ.w
&& !self.succ.i
&& !self.succ.o
}
pub const fn is_nop(&self) -> bool {
self.pred.is_empty() && self.succ.is_empty()
}
pub const fn is_full_barrier(&self) -> bool {
self.pred.is_full() && self.succ.is_full()
}
}