1+ use crate :: jit:: assembler:: arm:: alu_assembler:: AluShiftImm ;
12use crate :: jit:: assembler:: block_asm:: { BlockAsm , BLOCK_LOG } ;
23use crate :: jit:: assembler:: block_inst:: { BlockAluOp , BlockAluSetCond , BlockSystemRegOp , BlockTransferOp } ;
34use crate :: jit:: assembler:: block_inst_list:: { BlockInstList , BlockInstListEntry } ;
45use crate :: jit:: assembler:: block_reg_set:: BlockRegSet ;
5- use crate :: jit:: assembler:: { BlockAsmBuf , BlockInstKind } ;
6+ use crate :: jit:: assembler:: { BlockAsmBuf , BlockInstKind , BlockLabel } ;
67use crate :: jit:: reg:: { Reg , RegReserve } ;
78use crate :: jit:: { MemoryAmount , ShiftType } ;
89use crate :: IS_DEBUG ;
@@ -14,6 +15,9 @@ pub struct BasicBlock {
1415 pub block_entry_start : * mut BlockInstListEntry ,
1516 pub block_entry_end : * mut BlockInstListEntry ,
1617
18+ pub pad_label : Option < BlockLabel > ,
19+ pub pad_size : usize ,
20+
1721 pub guest_regs_resolved : bool ,
1822 pub guest_regs_input_dirty : RegReserve ,
1923 pub guest_regs_output_dirty : RegReserve ,
@@ -27,6 +31,8 @@ pub struct BasicBlock {
2731 pub insts_link : BlockInstList ,
2832
2933 pub start_pc : u32 ,
34+
35+ pub opcodes : Vec < u32 > ,
3036}
3137
3238impl BasicBlock {
@@ -37,6 +43,9 @@ impl BasicBlock {
3743 block_entry_start,
3844 block_entry_end,
3945
46+ pad_label : None ,
47+ pad_size : 0 ,
48+
4049 guest_regs_resolved : false ,
4150 guest_regs_input_dirty : RegReserve :: new ( ) ,
4251 guest_regs_output_dirty : RegReserve :: new ( ) ,
@@ -50,6 +59,8 @@ impl BasicBlock {
5059 insts_link : BlockInstList :: new ( ) ,
5160
5261 start_pc : 0 ,
62+
63+ opcodes : Vec :: new ( ) ,
5364 }
5465 }
5566
@@ -113,6 +124,7 @@ impl BasicBlock {
113124 add_inst = false ;
114125 }
115126 BlockInstKind :: SaveReg { .. } | BlockInstKind :: MarkRegDirty { .. } => { }
127+ BlockInstKind :: PadBlock ( label) => self . pad_label = Some ( * label) ,
116128 _ => {
117129 let ( inputs, _) = asm. buf . insts [ i] . get_io ( ) ;
118130 for guest_reg in inputs. get_guests ( ) {
@@ -300,36 +312,48 @@ impl BasicBlock {
300312 }
301313 }
302314
303- pub fn emit_opcodes ( & self , asm : & mut BlockAsm , opcodes_offset : usize , used_host_regs : RegReserve ) -> Vec < u32 > {
304- let mut opcodes = Vec :: new ( ) ;
315+ pub fn emit_opcodes ( & mut self , asm : & mut BlockAsm , opcodes_offset : usize , block_index : usize , used_host_regs : RegReserve ) {
316+ if IS_DEBUG && unsafe { BLOCK_LOG } && opcodes_offset != 0 {
317+ self . opcodes . clear ( ) ;
318+ }
319+
320+ if !self . opcodes . is_empty ( ) {
321+ return ;
322+ }
323+
324+ asm. buf . branch_placeholders [ block_index] . clear ( ) ;
325+
305326 let mut inst_opcodes = Vec :: new ( ) ;
306327 for entry in self . insts_link . iter ( ) {
307328 let inst = & mut asm. buf . insts [ entry. value ] ;
308329 if inst. skip {
309330 continue ;
310331 }
311332
312- if IS_DEBUG && unsafe { BLOCK_LOG } {
333+ if IS_DEBUG && unsafe { BLOCK_LOG } && opcodes_offset != 0 {
313334 match & inst. kind {
314335 BlockInstKind :: GuestPc ( pc) => {
315- println ! ( "(0x{:x}, 0x{pc:x})," , opcodes. len( ) + opcodes_offset) ;
336+ println ! ( "(0x{:x}, 0x{pc:x})," , self . opcodes. len( ) + opcodes_offset) ;
316337 }
317338 BlockInstKind :: Label { guest_pc : Some ( pc) , .. } => {
318- println ! ( "(0x{:x}, 0x{pc:x})," , opcodes. len( ) + opcodes_offset) ;
339+ println ! ( "(0x{:x}, 0x{pc:x})," , self . opcodes. len( ) + opcodes_offset) ;
319340 }
320341 _ => { }
321342 }
322343 }
323344
324345 inst_opcodes. clear ( ) ;
325346 inst. kind
326- . emit_opcode ( & mut inst_opcodes, opcodes. len ( ) , & mut asm. buf . branch_placeholders , opcodes_offset , used_host_regs) ;
347+ . emit_opcode ( & mut inst_opcodes, self . opcodes . len ( ) , & mut asm. buf . branch_placeholders [ block_index ] , used_host_regs) ;
327348 for opcode in & mut inst_opcodes {
328349 * opcode = ( * opcode & !( 0xF << 28 ) ) | ( ( inst. cond as u32 ) << 28 ) ;
329350 }
330- opcodes. extend ( & inst_opcodes) ;
351+ self . opcodes . extend ( & inst_opcodes) ;
352+ }
353+
354+ for _ in self . opcodes . len ( ) ..self . pad_size {
355+ self . opcodes . push ( AluShiftImm :: mov_al ( Reg :: R0 , Reg :: R0 ) ) ;
331356 }
332- opcodes
333357 }
334358}
335359
0 commit comments