Disable a lot of dynarec sanity checks in release builds.

This commit is contained in:
SarahW 2020-09-17 20:37:30 +01:00
commit 6a09e9636c
4 changed files with 111 additions and 17 deletions

View file

@ -69,8 +69,10 @@ static int dirty_list_size = 0;
static void block_free_list_add(codeblock_t *block) static void block_free_list_add(codeblock_t *block)
{ {
#ifndef RELEASE_BUILD
if (block->flags & CODEBLOCK_IN_DIRTY_LIST) if (block->flags & CODEBLOCK_IN_DIRTY_LIST)
fatal("block_free_list_add: block=%p in dirty list\n", block); fatal("block_free_list_add: block=%p in dirty list\n", block);
#endif
if (block_free_list) if (block_free_list)
block->next = block_free_list; block->next = block_free_list;
else else
@ -82,8 +84,10 @@ static void block_free_list_add(codeblock_t *block)
static void block_dirty_list_add(codeblock_t *block) static void block_dirty_list_add(codeblock_t *block)
{ {
#ifndef RELEASE_BUILD
if (block->flags & CODEBLOCK_IN_DIRTY_LIST) if (block->flags & CODEBLOCK_IN_DIRTY_LIST)
fatal("block_dirty_list_add: block=%p already in dirty list\n", block); fatal("block_dirty_list_add: block=%p already in dirty list\n", block);
#endif
// pclog("block_dirty_list_add: block=%i size=%i %i head=%i tail=%i\n", get_block_nr(block), dirty_list_size, dirty_list_check_size(), block_dirty_list_head, block_dirty_list_tail); // pclog("block_dirty_list_add: block=%i size=%i %i head=%i tail=%i\n", get_block_nr(block), dirty_list_size, dirty_list_check_size(), block_dirty_list_head, block_dirty_list_tail);
if (block_dirty_list_head != BLOCK_INVALID) if (block_dirty_list_head != BLOCK_INVALID)
{ {
@ -108,12 +112,14 @@ static void block_dirty_list_add(codeblock_t *block)
/*Evict oldest block to the free list*/ /*Evict oldest block to the free list*/
codeblock_t *evict_block = &codeblock[block_dirty_list_tail]; codeblock_t *evict_block = &codeblock[block_dirty_list_tail];
#ifndef RELEASE_BUILD
if (!(evict_block->flags & CODEBLOCK_IN_DIRTY_LIST)) if (!(evict_block->flags & CODEBLOCK_IN_DIRTY_LIST))
fatal("block_dirty_list_add: evict_block=%p %x %x not in dirty list\n", evict_block, evict_block->phys, evict_block->flags); fatal("block_dirty_list_add: evict_block=%p %x %x not in dirty list\n", evict_block, evict_block->phys, evict_block->flags);
if (!block_dirty_list_tail) if (!block_dirty_list_tail)
fatal("block_dirty_list_add - !block_dirty_list_tail\n"); fatal("block_dirty_list_add - !block_dirty_list_tail\n");
if (evict_block->prev == BLOCK_INVALID) if (evict_block->prev == BLOCK_INVALID)
fatal("block_dirty_list_add - evict_block->prev == BLOCK_INVALID\n"); fatal("block_dirty_list_add - evict_block->prev == BLOCK_INVALID\n");
#endif
block_dirty_list_tail = evict_block->prev; block_dirty_list_tail = evict_block->prev;
codeblock[evict_block->prev].next = BLOCK_INVALID; codeblock[evict_block->prev].next = BLOCK_INVALID;
@ -132,8 +138,10 @@ static void block_dirty_list_remove(codeblock_t *block)
codeblock_t *prev_block = &codeblock[block->prev]; codeblock_t *prev_block = &codeblock[block->prev];
codeblock_t *next_block = &codeblock[block->next]; codeblock_t *next_block = &codeblock[block->next];
#ifndef RELEASE_BUILD
if (!(block->flags & CODEBLOCK_IN_DIRTY_LIST)) if (!(block->flags & CODEBLOCK_IN_DIRTY_LIST))
fatal("block_dirty_list_remove: block=%p not in dirty list\n", block); fatal("block_dirty_list_remove: block=%p not in dirty list\n", block);
#endif
/*Is block head of list*/ /*Is block head of list*/
if (block->prev == BLOCK_INVALID) if (block->prev == BLOCK_INVALID)
@ -148,8 +156,10 @@ static void block_dirty_list_remove(codeblock_t *block)
next_block->prev = block->prev; next_block->prev = block->prev;
dirty_list_size--; dirty_list_size--;
#ifndef RELEASE_BUILD
if (dirty_list_size < 0) if (dirty_list_size < 0)
fatal("remove - dirty_list_size < 0!\n"); fatal("remove - dirty_list_size < 0!\n");
#endif
block->flags &= ~CODEBLOCK_IN_DIRTY_LIST; block->flags &= ~CODEBLOCK_IN_DIRTY_LIST;
// pclog(" block_dirty_list_remove: %p flags = %x\n", block, block->flags); // pclog(" block_dirty_list_remove: %p flags = %x\n", block, block->flags);
} }
@ -180,9 +190,10 @@ static codeblock_t *block_free_list_get()
/*Free list is empty, check the dirty list*/ /*Free list is empty, check the dirty list*/
if (block_dirty_list_tail) if (block_dirty_list_tail)
{ {
#ifndef RELEASE_BUILD
if (dirty_list_size <= 0) if (dirty_list_size <= 0)
fatal("get - dirty_list_size <= 0!\n"); fatal("get - dirty_list_size <= 0!\n");
#endif
/*Reuse oldest block*/ /*Reuse oldest block*/
block = &codeblock[block_dirty_list_tail]; block = &codeblock[block_dirty_list_tail];
@ -310,9 +321,10 @@ static void add_to_block_list(codeblock_t *block)
uint16_t block_nr = get_block_nr(block); uint16_t block_nr = get_block_nr(block);
//pclog("Add to block list %p %08x %llx %x\n", block, block->phys, block->page_mask2, block->flags); //pclog("Add to block list %p %08x %llx %x\n", block, block->phys, block->page_mask2, block->flags);
#ifndef RELEASE_BUILD
if (!block->page_mask) if (!block->page_mask)
fatal("add_to_block_list - mask = 0 %llx %llx\n", block->page_mask,block->page_mask2); fatal("add_to_block_list - mask = 0 %llx %llx\n", block->page_mask,block->page_mask2);
#endif
if (block_prev_nr) if (block_prev_nr)
{ {
block->next = block_prev_nr; block->next = block_prev_nr;
@ -327,8 +339,10 @@ static void add_to_block_list(codeblock_t *block)
if (block->next) if (block->next)
{ {
#ifndef RELEASE_BUILD
if (codeblock[block->next].pc == BLOCK_PC_INVALID) if (codeblock[block->next].pc == BLOCK_PC_INVALID)
fatal("block->next->pc=BLOCK_PC_INVALID %p %p %x %x\n", (void *)&codeblock[block->next], (void *)codeblock, block_current, block_pos); fatal("block->next->pc=BLOCK_PC_INVALID %p %p %x %x\n", (void *)&codeblock[block->next], (void *)codeblock, block_current, block_pos);
#endif
} }
if (block->page_mask2) if (block->page_mask2)
@ -356,9 +370,10 @@ static void remove_from_block_list(codeblock_t *block, uint32_t pc)
{ {
if (!block->page_mask) if (!block->page_mask)
return; return;
#ifndef RELEASE_BUILD
if (block->flags & CODEBLOCK_IN_DIRTY_LIST) if (block->flags & CODEBLOCK_IN_DIRTY_LIST)
fatal("remove_from_block_list: in dirty list\n"); fatal("remove_from_block_list: in dirty list\n");
#endif
if (block->prev) if (block->prev)
{ {
codeblock[block->prev].next = block->next; codeblock[block->prev].next = block->next;
@ -376,8 +391,10 @@ static void remove_from_block_list(codeblock_t *block, uint32_t pc)
if (!(block->flags & CODEBLOCK_HAS_PAGE2)) if (!(block->flags & CODEBLOCK_HAS_PAGE2))
{ {
#ifndef RELEASE_BUILD
if (block->prev_2 || block->next_2) if (block->prev_2 || block->next_2)
fatal("Invalid block_2 %x %p %08x\n", block->flags, block, block->phys); fatal("Invalid block_2 %x %p %08x\n", block->flags, block, block->phys);
#endif
return; return;
} }
block->flags &= ~CODEBLOCK_HAS_PAGE2; block->flags &= ~CODEBLOCK_HAS_PAGE2;
@ -404,11 +421,12 @@ static void invalidate_block(codeblock_t *block)
{ {
uint32_t old_pc = block->pc; uint32_t old_pc = block->pc;
#ifndef RELEASE_BUILD
if (block->flags & CODEBLOCK_IN_DIRTY_LIST) if (block->flags & CODEBLOCK_IN_DIRTY_LIST)
fatal("invalidate_block: already in dirty list\n"); fatal("invalidate_block: already in dirty list\n");
if (block->pc == BLOCK_PC_INVALID) if (block->pc == BLOCK_PC_INVALID)
fatal("Invalidating deleted block\n"); fatal("Invalidating deleted block\n");
#endif
remove_from_block_list(block, old_pc); remove_from_block_list(block, old_pc);
block_dirty_list_add(block); block_dirty_list_add(block);
if (block->head_mem_block) if (block->head_mem_block)
@ -423,8 +441,10 @@ static void delete_block(codeblock_t *block)
if (block == &codeblock[codeblock_hash[HASH(block->phys)]]) if (block == &codeblock[codeblock_hash[HASH(block->phys)]])
codeblock_hash[HASH(block->phys)] = BLOCK_INVALID; codeblock_hash[HASH(block->phys)] = BLOCK_INVALID;
#ifndef RELEASE_BUILD
if (block->pc == BLOCK_PC_INVALID) if (block->pc == BLOCK_PC_INVALID)
fatal("Deleting deleted block\n"); fatal("Deleting deleted block\n");
#endif
block->pc = BLOCK_PC_INVALID; block->pc = BLOCK_PC_INVALID;
codeblock_tree_delete(block); codeblock_tree_delete(block);
@ -443,8 +463,10 @@ static void delete_dirty_block(codeblock_t *block)
if (block == &codeblock[codeblock_hash[HASH(block->phys)]]) if (block == &codeblock[codeblock_hash[HASH(block->phys)]])
codeblock_hash[HASH(block->phys)] = BLOCK_INVALID; codeblock_hash[HASH(block->phys)] = BLOCK_INVALID;
#ifndef RELEASE_BUILD
if (block->pc == BLOCK_PC_INVALID) if (block->pc == BLOCK_PC_INVALID)
fatal("Deleting deleted block\n"); fatal("Deleting deleted block\n");
#endif
block->pc = BLOCK_PC_INVALID; block->pc = BLOCK_PC_INVALID;
codeblock_tree_delete(block); codeblock_tree_delete(block);
@ -494,8 +516,10 @@ void codegen_check_flush(page_t *page, uint64_t mask, uint32_t phys_addr)
invalidate_block(block); invalidate_block(block);
cpu_recomp_evicted++; cpu_recomp_evicted++;
} }
#ifndef RELEASE_BUILD
if (block_nr == next_block) if (block_nr == next_block)
fatal("Broken 1\n"); fatal("Broken 1\n");
#endif
block_nr = next_block; block_nr = next_block;
} }
@ -512,8 +536,10 @@ void codegen_check_flush(page_t *page, uint64_t mask, uint32_t phys_addr)
invalidate_block(block); invalidate_block(block);
cpu_recomp_evicted++; cpu_recomp_evicted++;
} }
#ifndef RELEASE_BUILD
if (block_nr == next_block) if (block_nr == next_block)
fatal("Broken 2\n"); fatal("Broken 2\n");
#endif
block_nr = next_block; block_nr = next_block;
} }
@ -541,8 +567,10 @@ void codegen_block_init(uint32_t phys_addr)
if (!page->block) if (!page->block)
mem_flush_write_page(phys_addr, cs+cpu_state.pc); mem_flush_write_page(phys_addr, cs+cpu_state.pc);
block = block_free_list_get(); block = block_free_list_get();
#ifndef RELEASE_BUILD
if (!block) if (!block)
fatal("codegen_block_init: block_free_list_get() returned NULL\n"); fatal("codegen_block_init: block_free_list_get() returned NULL\n");
#endif
block_current = get_block_nr(block); block_current = get_block_nr(block);
block_num = HASH(phys_addr); block_num = HASH(phys_addr);
@ -582,10 +610,10 @@ void codegen_block_start_recompile(codeblock_t *block)
block_num = HASH(block->phys); block_num = HASH(block->phys);
block_current = get_block_nr(block);//block->pnt; block_current = get_block_nr(block);//block->pnt;
#ifndef RELEASE_BUILD
if (block->pc != cs + cpu_state.pc || (block->flags & CODEBLOCK_WAS_RECOMPILED)) if (block->pc != cs + cpu_state.pc || (block->flags & CODEBLOCK_WAS_RECOMPILED))
fatal("Recompile to used block!\n"); fatal("Recompile to used block!\n");
#endif
block->head_mem_block = codegen_allocator_allocate(NULL, block_current); block->head_mem_block = codegen_allocator_allocate(NULL, block_current);
block->data = codeblock_allocator_get_ptr(block->head_mem_block); block->data = codeblock_allocator_get_ptr(block->head_mem_block);
@ -695,6 +723,7 @@ void codegen_block_generate_end_mask_recompile()
if (!pages[block->phys_2 >> 12].block_2) if (!pages[block->phys_2 >> 12].block_2)
mem_flush_write_page(block->phys_2, codegen_endpc); mem_flush_write_page(block->phys_2, codegen_endpc);
#ifndef RELEASE_BUILD
if (!block->page_mask2) if (!block->page_mask2)
fatal("!page_mask2\n"); fatal("!page_mask2\n");
if (block->next_2) if (block->next_2)
@ -703,6 +732,7 @@ void codegen_block_generate_end_mask_recompile()
if (codeblock[block->next_2].pc == BLOCK_PC_INVALID) if (codeblock[block->next_2].pc == BLOCK_PC_INVALID)
fatal("block->next_2->pc=BLOCK_PC_INVALID %p\n", (void *)&codeblock[block->next_2]); fatal("block->next_2->pc=BLOCK_PC_INVALID %p\n", (void *)&codeblock[block->next_2]);
} }
#endif
} }
else else
{ {
@ -724,9 +754,10 @@ void codegen_block_generate_end_mask_mark()
uint32_t end_pc; uint32_t end_pc;
page_t *p; page_t *p;
#ifndef RELEASE_BUILD
if (block->flags & CODEBLOCK_BYTE_MASK) if (block->flags & CODEBLOCK_BYTE_MASK)
fatal("codegen_block_generate_end_mask2() - BYTE_MASK\n"); fatal("codegen_block_generate_end_mask2() - BYTE_MASK\n");
#endif
block->page_mask = 0; block->page_mask = 0;
start_pc = (block->pc & 0xfff) & ~63; start_pc = (block->pc & 0xfff) & ~63;
if ((block->pc ^ codegen_endpc) & ~0xfff) if ((block->pc ^ codegen_endpc) & ~0xfff)
@ -771,7 +802,7 @@ void codegen_block_generate_end_mask_mark()
if (!pages[block->phys_2 >> 12].block_2) if (!pages[block->phys_2 >> 12].block_2)
mem_flush_write_page(block->phys_2, codegen_endpc); mem_flush_write_page(block->phys_2, codegen_endpc);
#ifndef RELEASE_BUILD
if (!block->page_mask2) if (!block->page_mask2)
fatal("!page_mask2\n"); fatal("!page_mask2\n");
if (block->next_2) if (block->next_2)
@ -780,7 +811,7 @@ void codegen_block_generate_end_mask_mark()
if (codeblock[block->next_2].pc == BLOCK_PC_INVALID) if (codeblock[block->next_2].pc == BLOCK_PC_INVALID)
fatal("block->next_2->pc=BLOCK_PC_INVALID %p\n", (void *)&codeblock[block->next_2]); fatal("block->next_2->pc=BLOCK_PC_INVALID %p\n", (void *)&codeblock[block->next_2]);
} }
#endif
block->dirty_mask2 = &page_2->dirty_mask; block->dirty_mask2 = &page_2->dirty_mask;
} }
else else

View file

@ -156,9 +156,10 @@ void codegen_ir_compile(ir_data_t *ir, codeblock_t *block)
uop->dest_reg_a_real = codegen_reg_alloc_write_reg(block, uop->dest_reg_a); uop->dest_reg_a_real = codegen_reg_alloc_write_reg(block, uop->dest_reg_a);
} }
} }
#ifndef RELEASE_BUILD
if (!uop_handlers[uop->type & UOP_MASK]) if (!uop_handlers[uop->type & UOP_MASK])
fatal("!uop_handlers[uop->type & UOP_MASK] %08x\n", uop->type); fatal("!uop_handlers[uop->type & UOP_MASK] %08x\n", uop->type);
#endif
uop_handlers[uop->type & UOP_MASK](block, uop); uop_handlers[uop->type & UOP_MASK](block, uop);
} }

View file

@ -271,8 +271,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
switch (ireg_data[IREG_GET_REG(ir_reg.reg)].native_size) switch (ireg_data[IREG_GET_REG(ir_reg.reg)].native_size)
{ {
case REG_WORD: case REG_WORD:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER)
fatal("codegen_reg_load - REG_WORD !REG_INTEGER\n"); fatal("codegen_reg_load - REG_WORD !REG_INTEGER\n");
#endif
if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256)
codegen_direct_read_16_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); codegen_direct_read_16_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p);
else else
@ -280,8 +282,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
break; break;
case REG_DWORD: case REG_DWORD:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER)
fatal("codegen_reg_load - REG_DWORD !REG_INTEGER\n"); fatal("codegen_reg_load - REG_DWORD !REG_INTEGER\n");
#endif
if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256)
codegen_direct_read_32_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); codegen_direct_read_32_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p);
else else
@ -289,8 +293,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
break; break;
case REG_QWORD: case REG_QWORD:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP)
fatal("codegen_reg_load - REG_QWORD !REG_FP\n"); fatal("codegen_reg_load - REG_QWORD !REG_FP\n");
#endif
if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256)
codegen_direct_read_64_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); codegen_direct_read_64_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p);
else else
@ -298,8 +304,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
break; break;
case REG_POINTER: case REG_POINTER:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER)
fatal("codegen_reg_load - REG_POINTER !REG_INTEGER\n"); fatal("codegen_reg_load - REG_POINTER !REG_INTEGER\n");
#endif
if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256)
codegen_direct_read_pointer_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); codegen_direct_read_pointer_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p);
else else
@ -307,8 +315,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
break; break;
case REG_DOUBLE: case REG_DOUBLE:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP)
fatal("codegen_reg_load - REG_DOUBLE !REG_FP\n"); fatal("codegen_reg_load - REG_DOUBLE !REG_FP\n");
#endif
if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256)
codegen_direct_read_double_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); codegen_direct_read_double_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p);
else else
@ -316,8 +326,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
break; break;
case REG_FPU_ST_BYTE: case REG_FPU_ST_BYTE:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER)
fatal("codegen_reg_load - REG_FPU_ST_BYTE !REG_INTEGER\n"); fatal("codegen_reg_load - REG_FPU_ST_BYTE !REG_INTEGER\n");
#endif
if (block->flags & CODEBLOCK_STATIC_TOP) if (block->flags & CODEBLOCK_STATIC_TOP)
codegen_direct_read_8(block, reg_set->reg_list[c].reg, &cpu_state.tag[ir_reg.reg & 7]); codegen_direct_read_8(block, reg_set->reg_list[c].reg, &cpu_state.tag[ir_reg.reg & 7]);
else else
@ -325,8 +337,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
break; break;
case REG_FPU_ST_QWORD: case REG_FPU_ST_QWORD:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP)
fatal("codegen_reg_load - REG_FPU_ST_QWORD !REG_FP\n"); fatal("codegen_reg_load - REG_FPU_ST_QWORD !REG_FP\n");
#endif
if (block->flags & CODEBLOCK_STATIC_TOP) if (block->flags & CODEBLOCK_STATIC_TOP)
codegen_direct_read_64(block, reg_set->reg_list[c].reg, &cpu_state.MM[ir_reg.reg & 7]); codegen_direct_read_64(block, reg_set->reg_list[c].reg, &cpu_state.MM[ir_reg.reg & 7]);
else else
@ -334,8 +348,10 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c,
break; break;
case REG_FPU_ST_DOUBLE: case REG_FPU_ST_DOUBLE:
#ifndef RELEASE_BUILD
if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP)
fatal("codegen_reg_load - REG_FPU_ST_DOUBLE !REG_FP\n"); fatal("codegen_reg_load - REG_FPU_ST_DOUBLE !REG_FP\n");
#endif
if (block->flags & CODEBLOCK_STATIC_TOP) if (block->flags & CODEBLOCK_STATIC_TOP)
codegen_direct_read_double(block, reg_set->reg_list[c].reg, &cpu_state.ST[ir_reg.reg & 7]); codegen_direct_read_double(block, reg_set->reg_list[c].reg, &cpu_state.ST[ir_reg.reg & 7]);
else else
@ -363,24 +379,30 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i
switch (ireg_data[ir_reg].native_size) switch (ireg_data[ir_reg].native_size)
{ {
case REG_BYTE: case REG_BYTE:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_INTEGER) if (ireg_data[ir_reg].type != REG_INTEGER)
fatal("codegen_reg_writeback - REG_BYTE !REG_INTEGER\n"); fatal("codegen_reg_writeback - REG_BYTE !REG_INTEGER\n");
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
fatal("codegen_reg_writeback - REG_BYTE %p\n", p); fatal("codegen_reg_writeback - REG_BYTE %p\n", p);
#endif
codegen_direct_write_8(block, p, reg_set->reg_list[c].reg); codegen_direct_write_8(block, p, reg_set->reg_list[c].reg);
break; break;
case REG_WORD: case REG_WORD:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_INTEGER) if (ireg_data[ir_reg].type != REG_INTEGER)
fatal("codegen_reg_writeback - REG_WORD !REG_INTEGER\n"); fatal("codegen_reg_writeback - REG_WORD !REG_INTEGER\n");
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
fatal("codegen_reg_writeback - REG_WORD %p\n", p); fatal("codegen_reg_writeback - REG_WORD %p\n", p);
#endif
codegen_direct_write_16(block, p, reg_set->reg_list[c].reg); codegen_direct_write_16(block, p, reg_set->reg_list[c].reg);
break; break;
case REG_DWORD: case REG_DWORD:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_INTEGER) if (ireg_data[ir_reg].type != REG_INTEGER)
fatal("codegen_reg_writeback - REG_DWORD !REG_INTEGER\n"); fatal("codegen_reg_writeback - REG_DWORD !REG_INTEGER\n");
#endif
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
codegen_direct_write_32_stack(block, (intptr_t)p, reg_set->reg_list[c].reg); codegen_direct_write_32_stack(block, (intptr_t)p, reg_set->reg_list[c].reg);
else else
@ -388,8 +410,10 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i
break; break;
case REG_QWORD: case REG_QWORD:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_FP) if (ireg_data[ir_reg].type != REG_FP)
fatal("codegen_reg_writeback - REG_QWORD !REG_FP\n"); fatal("codegen_reg_writeback - REG_QWORD !REG_FP\n");
#endif
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
codegen_direct_write_64_stack(block, (intptr_t)p, reg_set->reg_list[c].reg); codegen_direct_write_64_stack(block, (intptr_t)p, reg_set->reg_list[c].reg);
else else
@ -397,16 +421,20 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i
break; break;
case REG_POINTER: case REG_POINTER:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_INTEGER) if (ireg_data[ir_reg].type != REG_INTEGER)
fatal("codegen_reg_writeback - REG_POINTER !REG_INTEGER\n"); fatal("codegen_reg_writeback - REG_POINTER !REG_INTEGER\n");
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
fatal("codegen_reg_writeback - REG_POINTER %p\n", p); fatal("codegen_reg_writeback - REG_POINTER %p\n", p);
#endif
codegen_direct_write_ptr(block, p, reg_set->reg_list[c].reg); codegen_direct_write_ptr(block, p, reg_set->reg_list[c].reg);
break; break;
case REG_DOUBLE: case REG_DOUBLE:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_FP) if (ireg_data[ir_reg].type != REG_FP)
fatal("codegen_reg_writeback - REG_DOUBLE !REG_FP\n"); fatal("codegen_reg_writeback - REG_DOUBLE !REG_FP\n");
#endif
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
codegen_direct_write_double_stack(block, (intptr_t)p, reg_set->reg_list[c].reg); codegen_direct_write_double_stack(block, (intptr_t)p, reg_set->reg_list[c].reg);
else else
@ -414,8 +442,10 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i
break; break;
case REG_FPU_ST_BYTE: case REG_FPU_ST_BYTE:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_INTEGER) if (ireg_data[ir_reg].type != REG_INTEGER)
fatal("codegen_reg_writeback - REG_FPU_ST_BYTE !REG_INTEGER\n"); fatal("codegen_reg_writeback - REG_FPU_ST_BYTE !REG_INTEGER\n");
#endif
if (block->flags & CODEBLOCK_STATIC_TOP) if (block->flags & CODEBLOCK_STATIC_TOP)
codegen_direct_write_8(block, &cpu_state.tag[reg_set->regs[c].reg & 7], reg_set->reg_list[c].reg); codegen_direct_write_8(block, &cpu_state.tag[reg_set->regs[c].reg & 7], reg_set->reg_list[c].reg);
else else
@ -423,8 +453,10 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i
break; break;
case REG_FPU_ST_QWORD: case REG_FPU_ST_QWORD:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_FP) if (ireg_data[ir_reg].type != REG_FP)
fatal("codegen_reg_writeback - REG_FPU_ST_QWORD !REG_FP\n"); fatal("codegen_reg_writeback - REG_FPU_ST_QWORD !REG_FP\n");
#endif
if (block->flags & CODEBLOCK_STATIC_TOP) if (block->flags & CODEBLOCK_STATIC_TOP)
codegen_direct_write_64(block, &cpu_state.MM[reg_set->regs[c].reg & 7], reg_set->reg_list[c].reg); codegen_direct_write_64(block, &cpu_state.MM[reg_set->regs[c].reg & 7], reg_set->reg_list[c].reg);
else else
@ -432,8 +464,10 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i
break; break;
case REG_FPU_ST_DOUBLE: case REG_FPU_ST_DOUBLE:
#ifndef RELEASE_BUILD
if (ireg_data[ir_reg].type != REG_FP) if (ireg_data[ir_reg].type != REG_FP)
fatal("codegen_reg_writeback - REG_FPU_ST_DOUBLE !REG_FP\n"); fatal("codegen_reg_writeback - REG_FPU_ST_DOUBLE !REG_FP\n");
#endif
if (block->flags & CODEBLOCK_STATIC_TOP) if (block->flags & CODEBLOCK_STATIC_TOP)
codegen_direct_write_double(block, &cpu_state.ST[reg_set->regs[c].reg & 7], reg_set->reg_list[c].reg); codegen_direct_write_double(block, &cpu_state.ST[reg_set->regs[c].reg & 7], reg_set->reg_list[c].reg);
else else
@ -458,14 +492,18 @@ void codegen_reg_write_imm(codeblock_t *block, ir_reg_t ir_reg, uint32_t imm_dat
switch (ireg_data[reg_idx].native_size) switch (ireg_data[reg_idx].native_size)
{ {
case REG_BYTE: case REG_BYTE:
#ifndef RELEASE_BUILD
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
fatal("codegen_reg_write_imm - REG_BYTE %p\n", p); fatal("codegen_reg_write_imm - REG_BYTE %p\n", p);
#endif
codegen_direct_write_8_imm(block, p, imm_data); codegen_direct_write_8_imm(block, p, imm_data);
break; break;
case REG_WORD: case REG_WORD:
#ifndef RELEASE_BUILD
if ((uintptr_t)p < 256) if ((uintptr_t)p < 256)
fatal("codegen_reg_write_imm - REG_WORD %p\n", p); fatal("codegen_reg_write_imm - REG_WORD %p\n", p);
#endif
codegen_direct_write_16_imm(block, p, imm_data); codegen_direct_write_16_imm(block, p, imm_data);
break; break;
@ -498,8 +536,10 @@ static void alloc_reg(ir_reg_t ir_reg)
{ {
if (IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(ir_reg.reg)) if (IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(ir_reg.reg))
{ {
#ifndef RELEASE_BUILD
if (reg_set->regs[c].version != ir_reg.version) if (reg_set->regs[c].version != ir_reg.version)
fatal("alloc_reg - host_regs[c].version != ir_reg.version %i %p %p %i %i\n", c, reg_set, &host_reg_set, reg_set->regs[c].reg, ir_reg.reg); fatal("alloc_reg - host_regs[c].version != ir_reg.version %i %p %p %i %i\n", c, reg_set, &host_reg_set, reg_set->regs[c].reg, ir_reg.reg);
#endif
reg_set->locked |= (1 << c); reg_set->locked |= (1 << c);
return; return;
} }
@ -591,9 +631,10 @@ ir_host_reg_t codegen_reg_alloc_read_reg(codeblock_t *block, ir_reg_t ir_reg, in
reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount++; reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount++;
break; break;
} }
#ifndef RELEASE_BUILD
if (!ir_reg_is_invalid(reg_set->regs[c]) && IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(ir_reg.reg) && reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount) if (!ir_reg_is_invalid(reg_set->regs[c]) && IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(ir_reg.reg) && reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount)
fatal("codegen_reg_alloc_read_reg - version mismatch!\n"); fatal("codegen_reg_alloc_read_reg - version mismatch!\n");
#endif
} }
if (c == reg_set->nr_regs) if (c == reg_set->nr_regs)
@ -612,8 +653,10 @@ ir_host_reg_t codegen_reg_alloc_read_reg(codeblock_t *block, ir_reg_t ir_reg, in
if (!(reg_set->locked & (1 << c))) if (!(reg_set->locked & (1 << c)))
break; break;
} }
#ifndef RELEASE_BUILD
if (c == reg_set->nr_regs) if (c == reg_set->nr_regs)
fatal("codegen_reg_alloc_read_reg - out of registers\n"); fatal("codegen_reg_alloc_read_reg - out of registers\n");
#endif
} }
if (reg_set->dirty[c]) if (reg_set->dirty[c])
codegen_reg_writeback(reg_set, block, c, 1); codegen_reg_writeback(reg_set, block, c, 1);
@ -628,8 +671,10 @@ ir_host_reg_t codegen_reg_alloc_read_reg(codeblock_t *block, ir_reg_t ir_reg, in
// pclog(" already loaded %i\n", c); // pclog(" already loaded %i\n", c);
reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount--; reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount--;
#ifndef RELEASE_BUILD
if (reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount == (uint8_t)-1) if (reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount == (uint8_t)-1)
fatal("codegen_reg_alloc_read_reg - refcount < 0\n"); fatal("codegen_reg_alloc_read_reg - refcount < 0\n");
#endif
if (host_reg_idx) if (host_reg_idx)
*host_reg_idx = c; *host_reg_idx = c;
@ -653,10 +698,12 @@ ir_host_reg_t codegen_reg_alloc_write_reg(codeblock_t *block, ir_reg_t ir_reg)
codegen_reg_alloc_read_reg(block, parent_reg, &c); codegen_reg_alloc_read_reg(block, parent_reg, &c);
#ifndef RELEASE_BUILD
if (IREG_GET_REG(reg_set->regs[c].reg) != IREG_GET_REG(ir_reg.reg) || reg_set->regs[c].version > ir_reg.version-1) if (IREG_GET_REG(reg_set->regs[c].reg) != IREG_GET_REG(ir_reg.reg) || reg_set->regs[c].version > ir_reg.version-1)
fatal("codegen_reg_alloc_write_reg sub_reg - doesn't match %i %02x.%i %02x.%i\n", c, fatal("codegen_reg_alloc_write_reg sub_reg - doesn't match %i %02x.%i %02x.%i\n", c,
reg_set->regs[c].reg,reg_set->regs[c].version, reg_set->regs[c].reg,reg_set->regs[c].version,
ir_reg.reg,ir_reg.version); ir_reg.reg,ir_reg.version);
#endif
reg_set->regs[c].reg = ir_reg.reg; reg_set->regs[c].reg = ir_reg.reg;
reg_set->regs[c].version = ir_reg.version; reg_set->regs[c].version = ir_reg.version;
@ -672,8 +719,10 @@ ir_host_reg_t codegen_reg_alloc_write_reg(codeblock_t *block, ir_reg_t ir_reg)
{ {
if (reg_set->regs[c].version <= ir_reg.version-1) if (reg_set->regs[c].version <= ir_reg.version-1)
{ {
#ifndef RELEASE_BUILD
if (reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount != 0) if (reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount != 0)
fatal("codegen_reg_alloc_write_reg - previous version refcount != 0\n"); fatal("codegen_reg_alloc_write_reg - previous version refcount != 0\n");
#endif
break; break;
} }
} }
@ -696,8 +745,10 @@ ir_host_reg_t codegen_reg_alloc_write_reg(codeblock_t *block, ir_reg_t ir_reg)
if (!(reg_set->locked & (1 << c))) if (!(reg_set->locked & (1 << c)))
break; break;
} }
#ifndef RELEASE_BUILD
if (c == reg_set->nr_regs) if (c == reg_set->nr_regs)
fatal("codegen_reg_alloc_write_reg - out of registers\n"); fatal("codegen_reg_alloc_write_reg - out of registers\n");
#endif
if (reg_set->dirty[c]) if (reg_set->dirty[c])
codegen_reg_writeback(reg_set, block, c, 1); codegen_reg_writeback(reg_set, block, c, 1);
} }
@ -723,8 +774,10 @@ int codegen_reg_is_loaded(ir_reg_t ir_reg)
{ {
if (reg_set->regs[c].version <= ir_reg.version-1) if (reg_set->regs[c].version <= ir_reg.version-1)
{ {
#ifndef RELEASE_BUILD
if (reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount != 0) if (reg_version[IREG_GET_REG(reg_set->regs[c].reg)][reg_set->regs[c].version].refcount != 0)
fatal("codegen_reg_alloc_write_reg - previous version refcount != 0\n"); fatal("codegen_reg_alloc_write_reg - previous version refcount != 0\n");
#endif
return 1; return 1;
} }
} }
@ -746,9 +799,10 @@ void codegen_reg_rename(codeblock_t *block, ir_reg_t src, ir_reg_t dst)
if (!ir_reg_is_invalid(reg_set->regs[c]) && IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(src.reg) && reg_set->regs[c].version == src.version) if (!ir_reg_is_invalid(reg_set->regs[c]) && IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(src.reg) && reg_set->regs[c].version == src.version)
break; break;
} }
#ifndef RELEASE_BUILD
if (c == reg_set->nr_regs) if (c == reg_set->nr_regs)
fatal("codegen_reg_rename: Can't find register to rename\n"); fatal("codegen_reg_rename: Can't find register to rename\n");
#endif
target = c; target = c;
if (reg_set->dirty[target]) if (reg_set->dirty[target])
codegen_reg_writeback(reg_set, block, target, 0); codegen_reg_writeback(reg_set, block, target, 0);

View file

@ -325,17 +325,21 @@ static inline ir_reg_t codegen_reg_read(int reg)
ir_reg_t ireg; ir_reg_t ireg;
reg_version_t *version; reg_version_t *version;
#ifndef RELEASE_BUILD
if (IREG_GET_REG(reg) == IREG_INVALID) if (IREG_GET_REG(reg) == IREG_INVALID)
fatal("codegen_reg_read - IREG_INVALID\n"); fatal("codegen_reg_read - IREG_INVALID\n");
#endif
ireg.reg = reg; ireg.reg = reg;
ireg.version = reg_last_version[IREG_GET_REG(reg)]; ireg.version = reg_last_version[IREG_GET_REG(reg)];
version = &reg_version[IREG_GET_REG(ireg.reg)][ireg.version]; version = &reg_version[IREG_GET_REG(ireg.reg)][ireg.version];
version->flags = 0; version->flags = 0;
version->refcount++; version->refcount++;
#ifndef RELEASE_BUILD
if (!version->refcount) if (!version->refcount)
fatal("codegen_reg_read - refcount overflow\n"); fatal("codegen_reg_read - refcount overflow\n");
else if (version->refcount > REG_REFCOUNT_MAX) else
#endif
if (version->refcount > REG_REFCOUNT_MAX)
CPU_BLOCK_END(); CPU_BLOCK_END();
if (version->refcount > max_version_refcount) if (version->refcount > max_version_refcount)
max_version_refcount = version->refcount; max_version_refcount = version->refcount;
@ -351,9 +355,10 @@ static inline ir_reg_t codegen_reg_write(int reg, int uop_nr)
int last_version = reg_last_version[IREG_GET_REG(reg)]; int last_version = reg_last_version[IREG_GET_REG(reg)];
reg_version_t *version; reg_version_t *version;
#ifndef RELEASE_BUILD
if (IREG_GET_REG(reg) == IREG_INVALID) if (IREG_GET_REG(reg) == IREG_INVALID)
fatal("codegen_reg_write - IREG_INVALID\n"); fatal("codegen_reg_write - IREG_INVALID\n");
#endif
ireg.reg = reg; ireg.reg = reg;
ireg.version = last_version + 1; ireg.version = last_version + 1;
@ -365,9 +370,12 @@ static inline ir_reg_t codegen_reg_write(int reg, int uop_nr)
} }
reg_last_version[IREG_GET_REG(reg)]++; reg_last_version[IREG_GET_REG(reg)]++;
#ifndef RELEASE_BUILD
if (!reg_last_version[IREG_GET_REG(reg)]) if (!reg_last_version[IREG_GET_REG(reg)])
fatal("codegen_reg_write - version overflow\n"); fatal("codegen_reg_write - version overflow\n");
else if (reg_last_version[IREG_GET_REG(reg)] > REG_VERSION_MAX) else
#endif
if (reg_last_version[IREG_GET_REG(reg)] > REG_VERSION_MAX)
CPU_BLOCK_END(); CPU_BLOCK_END();
if (reg_last_version[IREG_GET_REG(reg)] > max_version_refcount) if (reg_last_version[IREG_GET_REG(reg)] > max_version_refcount)
max_version_refcount = reg_last_version[IREG_GET_REG(reg)]; max_version_refcount = reg_last_version[IREG_GET_REG(reg)];