use core::ops::{BitAnd, BitOr, BitOrAssign};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Exceptions(pub u8);
impl Exceptions {
pub const IE: Exceptions = Exceptions(1 << 0);
pub const DE: Exceptions = Exceptions(1 << 1);
pub const ZE: Exceptions = Exceptions(1 << 2);
pub const OE: Exceptions = Exceptions(1 << 3);
pub const UE: Exceptions = Exceptions(1 << 4);
pub const PE: Exceptions = Exceptions(1 << 5);
pub const NONE: Exceptions = Exceptions(0);
pub const ALL: Exceptions = Exceptions(0x3F);
#[inline]
pub fn contains(self, other: Exceptions) -> bool {
self.0 & other.0 == other.0
}
#[inline]
pub fn when(self, condition: bool) -> Exceptions {
Exceptions(self.0 & u8::from(condition).wrapping_neg())
}
#[inline]
pub fn pre_computation(self) -> Exceptions {
Exceptions(self.0 & 0b000_111)
}
#[inline]
pub fn post_computation(self) -> Exceptions {
Exceptions(self.0 & 0b111_000)
}
}
impl From<crate::Flags> for Exceptions {
#[inline]
fn from(flags: crate::Flags) -> Exceptions {
let bits = flags.bits();
Exceptions((bits & 1) | (bits & 0b1_1110) << 1)
}
}
impl BitOr for Exceptions {
type Output = Exceptions;
#[inline]
fn bitor(self, other: Exceptions) -> Exceptions {
Exceptions(self.0 | other.0)
}
}
impl BitAnd for Exceptions {
type Output = Exceptions;
#[inline]
fn bitand(self, other: Exceptions) -> Exceptions {
Exceptions(self.0 & other.0)
}
}
impl BitOrAssign for Exceptions {
#[inline]
fn bitor_assign(&mut self, other: Exceptions) {
self.0 |= other.0;
}
}