Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Grarak committed Oct 29, 2024
1 parent 6fc7ebc commit 885cdce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/jit/assembler/block_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,28 @@ pub struct BranchEncoding {

#[derive(Clone)]
pub struct BlockInst {
pub cond: Cond,
pub kind: BlockInstKind,
io_cache: RefCell<Option<(BlockRegSet, BlockRegSet)>>,
}

impl BlockInst {
pub fn new(kind: BlockInstKind) -> Self {
BlockInst { kind, io_cache: RefCell::new(None) }
pub fn new(cond: Cond, kind: BlockInstKind) -> Self {
BlockInst {
cond,
kind,
io_cache: RefCell::new(None),
}
}

pub fn get_io(&self) -> (BlockRegSet, BlockRegSet) {
let mut cached_io = self.io_cache.borrow_mut();
match *cached_io {
None => {
let io = self.kind.get_io();
*cached_io = Some(io);
io
let (mut inputs, outputs) = self.kind.get_io();
inputs.add_guests(outputs.get_guests());
*cached_io = Some((inputs, outputs));
(inputs, outputs)
}
Some(cache) => cache,
}
Expand All @@ -109,13 +115,13 @@ impl BlockInst {

impl From<BlockInstKind> for BlockInst {
fn from(value: BlockInstKind) -> Self {
BlockInst::new(value)
BlockInst::new(Cond::AL, value)
}
}

impl Debug for BlockInst {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.kind)
write!(f, "{:?} {:?}", self.cond, self.kind)
}
}

Expand Down Expand Up @@ -186,7 +192,6 @@ pub enum BlockInstKind {
Branch {
label: BlockLabel,
block_index: usize,
cond: Cond,
},

SaveContext {
Expand Down Expand Up @@ -679,10 +684,10 @@ impl BlockInstKind {
}
},

BlockInstKind::Branch { block_index, cond, .. } => {
BlockInstKind::Branch { block_index, .. } => {
// Encode label
// Branch offset can only be figured out later
opcodes.push(BranchEncoding::new(u26::new(*block_index as u32), false, false, u4::new(*cond as u8)).into());
opcodes.push(BranchEncoding::new(u26::new(*block_index as u32), false, false, u4::new(Cond::AL as u8)).into());
branch_placeholders.push(opcodes_offset + opcode_index);
}

Expand Down Expand Up @@ -860,7 +865,7 @@ impl Debug for BlockInstKind {
};
write!(f, "Label {label:?}{guest_pc}")
}
BlockInstKind::Branch { label, block_index, cond } => write!(f, "B{cond:?} {label:?}, block index: {block_index}"),
BlockInstKind::Branch { label, block_index } => write!(f, "B {label:?}, block index: {block_index}"),
BlockInstKind::SaveContext { .. } => write!(f, "SaveContext"),
BlockInstKind::SaveReg { guest_reg, reg_mapped, .. } => write!(f, "SaveReg {guest_reg:?}, mapped: {reg_mapped:?}"),
BlockInstKind::RestoreReg { guest_reg, reg_mapped, .. } => write!(f, "RestoreReg {guest_reg:?}, mapped: {reg_mapped:?}"),
Expand Down
6 changes: 6 additions & 0 deletions src/jit/assembler/block_reg_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ impl BlockRegSet {
(sum - (self.0 .0[0] & ((1 << FIXED_REGS_OVERFLOW) - 1)).count_ones()) as usize
}

pub const fn add_guests(&mut self, reg_reserve: RegReserve) {
self.0 .0[0] |= reg_reserve.0 << Reg::None as u8;
let spilled_over_count = Reg::None as u8 * 2 - 32;
self.0 .0[1] |= reg_reserve.0 >> (Reg::None as u8 - spilled_over_count);
}

pub const fn remove_guests(&mut self, reg_reserve: RegReserve) {
self.0 .0[0] &= !(reg_reserve.0 << Reg::None as u8);
let spilled_over_count = Reg::None as u8 * 2 - 32;
Expand Down

0 comments on commit 885cdce

Please sign in to comment.