Inline all the things (ProgPoint edition)

This commit is contained in:
Chris Fallin
2021-05-07 17:55:04 -07:00
parent 4f6346768e
commit df59b5ede4

View File

@@ -808,21 +808,26 @@ impl std::fmt::Debug for ProgPoint {
} }
impl ProgPoint { impl ProgPoint {
#[inline(always)]
pub fn new(inst: Inst, pos: InstPosition) -> Self { pub fn new(inst: Inst, pos: InstPosition) -> Self {
let bits = ((inst.0 as u32) << 1) | (pos as u8 as u32); let bits = ((inst.0 as u32) << 1) | (pos as u8 as u32);
Self { bits } Self { bits }
} }
#[inline(always)]
pub fn before(inst: Inst) -> Self { pub fn before(inst: Inst) -> Self {
Self::new(inst, InstPosition::Before) Self::new(inst, InstPosition::Before)
} }
#[inline(always)]
pub fn after(inst: Inst) -> Self { pub fn after(inst: Inst) -> Self {
Self::new(inst, InstPosition::After) Self::new(inst, InstPosition::After)
} }
#[inline(always)]
pub fn inst(self) -> Inst { pub fn inst(self) -> Inst {
// Cast to i32 to do an arithmetic right-shift, which will // Cast to i32 to do an arithmetic right-shift, which will
// preserve an `Inst::invalid()` (which is -1, or all-ones). // preserve an `Inst::invalid()` (which is -1, or all-ones).
Inst::new(((self.bits as i32) >> 1) as usize) Inst::new(((self.bits as i32) >> 1) as usize)
} }
#[inline(always)]
pub fn pos(self) -> InstPosition { pub fn pos(self) -> InstPosition {
match self.bits & 1 { match self.bits & 1 {
0 => InstPosition::Before, 0 => InstPosition::Before,
@@ -830,23 +835,23 @@ impl ProgPoint {
_ => unreachable!(), _ => unreachable!(),
} }
} }
#[inline(always)]
pub fn next(self) -> ProgPoint { pub fn next(self) -> ProgPoint {
Self { Self {
bits: self.bits + 1, bits: self.bits + 1,
} }
} }
#[inline(always)]
pub fn prev(self) -> ProgPoint { pub fn prev(self) -> ProgPoint {
Self { Self {
bits: self.bits - 1, bits: self.bits - 1,
} }
} }
#[inline(always)]
pub fn to_index(self) -> u32 { pub fn to_index(self) -> u32 {
self.bits self.bits
} }
#[inline(always)]
pub fn from_index(index: u32) -> Self { pub fn from_index(index: u32) -> Self {
Self { bits: index } Self { bits: index }
} }