Skip to content

Commit 885cdce

Browse files
committed
WIP
1 parent 6fc7ebc commit 885cdce

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/jit/assembler/block_inst.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,28 @@ pub struct BranchEncoding {
7575

7676
#[derive(Clone)]
7777
pub struct BlockInst {
78+
pub cond: Cond,
7879
pub kind: BlockInstKind,
7980
io_cache: RefCell<Option<(BlockRegSet, BlockRegSet)>>,
8081
}
8182

8283
impl BlockInst {
83-
pub fn new(kind: BlockInstKind) -> Self {
84-
BlockInst { kind, io_cache: RefCell::new(None) }
84+
pub fn new(cond: Cond, kind: BlockInstKind) -> Self {
85+
BlockInst {
86+
cond,
87+
kind,
88+
io_cache: RefCell::new(None),
89+
}
8590
}
8691

8792
pub fn get_io(&self) -> (BlockRegSet, BlockRegSet) {
8893
let mut cached_io = self.io_cache.borrow_mut();
8994
match *cached_io {
9095
None => {
91-
let io = self.kind.get_io();
92-
*cached_io = Some(io);
93-
io
96+
let (mut inputs, outputs) = self.kind.get_io();
97+
inputs.add_guests(outputs.get_guests());
98+
*cached_io = Some((inputs, outputs));
99+
(inputs, outputs)
94100
}
95101
Some(cache) => cache,
96102
}
@@ -109,13 +115,13 @@ impl BlockInst {
109115

110116
impl From<BlockInstKind> for BlockInst {
111117
fn from(value: BlockInstKind) -> Self {
112-
BlockInst::new(value)
118+
BlockInst::new(Cond::AL, value)
113119
}
114120
}
115121

116122
impl Debug for BlockInst {
117123
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
118-
write!(f, "{:?}", self.kind)
124+
write!(f, "{:?} {:?}", self.cond, self.kind)
119125
}
120126
}
121127

@@ -186,7 +192,6 @@ pub enum BlockInstKind {
186192
Branch {
187193
label: BlockLabel,
188194
block_index: usize,
189-
cond: Cond,
190195
},
191196

192197
SaveContext {
@@ -679,10 +684,10 @@ impl BlockInstKind {
679684
}
680685
},
681686

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

@@ -860,7 +865,7 @@ impl Debug for BlockInstKind {
860865
};
861866
write!(f, "Label {label:?}{guest_pc}")
862867
}
863-
BlockInstKind::Branch { label, block_index, cond } => write!(f, "B{cond:?} {label:?}, block index: {block_index}"),
868+
BlockInstKind::Branch { label, block_index } => write!(f, "B {label:?}, block index: {block_index}"),
864869
BlockInstKind::SaveContext { .. } => write!(f, "SaveContext"),
865870
BlockInstKind::SaveReg { guest_reg, reg_mapped, .. } => write!(f, "SaveReg {guest_reg:?}, mapped: {reg_mapped:?}"),
866871
BlockInstKind::RestoreReg { guest_reg, reg_mapped, .. } => write!(f, "RestoreReg {guest_reg:?}, mapped: {reg_mapped:?}"),

src/jit/assembler/block_reg_set.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ impl BlockRegSet {
6464
(sum - (self.0 .0[0] & ((1 << FIXED_REGS_OVERFLOW) - 1)).count_ones()) as usize
6565
}
6666

67+
pub const fn add_guests(&mut self, reg_reserve: RegReserve) {
68+
self.0 .0[0] |= reg_reserve.0 << Reg::None as u8;
69+
let spilled_over_count = Reg::None as u8 * 2 - 32;
70+
self.0 .0[1] |= reg_reserve.0 >> (Reg::None as u8 - spilled_over_count);
71+
}
72+
6773
pub const fn remove_guests(&mut self, reg_reserve: RegReserve) {
6874
self.0 .0[0] &= !(reg_reserve.0 << Reg::None as u8);
6975
let spilled_over_count = Reg::None as u8 * 2 - 32;

0 commit comments

Comments
 (0)