clang format in codegen & codegen_new
This commit is contained in:
@@ -30,34 +30,33 @@
|
||||
same page).
|
||||
*/
|
||||
|
||||
typedef struct codeblock_t
|
||||
{
|
||||
uint32_t pc;
|
||||
uint32_t _cs;
|
||||
uint32_t phys, phys_2;
|
||||
uint16_t status;
|
||||
uint16_t flags;
|
||||
uint8_t ins;
|
||||
uint8_t TOP;
|
||||
typedef struct codeblock_t {
|
||||
uint32_t pc;
|
||||
uint32_t _cs;
|
||||
uint32_t phys, phys_2;
|
||||
uint16_t status;
|
||||
uint16_t flags;
|
||||
uint8_t ins;
|
||||
uint8_t TOP;
|
||||
|
||||
/*Pointers for codeblock tree, used to search for blocks when hash lookup
|
||||
fails.*/
|
||||
uint16_t parent, left, right;
|
||||
/*Pointers for codeblock tree, used to search for blocks when hash lookup
|
||||
fails.*/
|
||||
uint16_t parent, left, right;
|
||||
|
||||
uint8_t *data;
|
||||
uint8_t *data;
|
||||
|
||||
uint64_t page_mask, page_mask2;
|
||||
uint64_t *dirty_mask, *dirty_mask2;
|
||||
uint64_t page_mask, page_mask2;
|
||||
uint64_t *dirty_mask, *dirty_mask2;
|
||||
|
||||
/*Previous and next pointers, for the codeblock list associated with
|
||||
each physical page. Two sets of pointers, as a codeblock can be
|
||||
present in two pages.*/
|
||||
uint16_t prev, next;
|
||||
uint16_t prev_2, next_2;
|
||||
/*Previous and next pointers, for the codeblock list associated with
|
||||
each physical page. Two sets of pointers, as a codeblock can be
|
||||
present in two pages.*/
|
||||
uint16_t prev, next;
|
||||
uint16_t prev_2, next_2;
|
||||
|
||||
/*First mem_block_t used by this block. Any subsequent mem_block_ts
|
||||
will be in the list starting at head_mem_block->next.*/
|
||||
struct mem_block_t *head_mem_block;
|
||||
/*First mem_block_t used by this block. Any subsequent mem_block_ts
|
||||
will be in the list starting at head_mem_block->next.*/
|
||||
struct mem_block_t *head_mem_block;
|
||||
} codeblock_t;
|
||||
|
||||
extern codeblock_t *codeblock;
|
||||
@@ -83,235 +82,206 @@ extern uint8_t *block_write_data;
|
||||
/*Code block is not inlining immediate parameters, parameters must be fetched from memory*/
|
||||
#define CODEBLOCK_NO_IMMEDIATES 0x80
|
||||
|
||||
#define BLOCK_PC_INVALID 0xffffffff
|
||||
#define BLOCK_PC_INVALID 0xffffffff
|
||||
|
||||
#define BLOCK_INVALID 0
|
||||
#define BLOCK_INVALID 0
|
||||
|
||||
static inline int get_block_nr(codeblock_t *block)
|
||||
static inline int
|
||||
get_block_nr(codeblock_t *block)
|
||||
{
|
||||
return ((uintptr_t)block - (uintptr_t)codeblock) / sizeof(codeblock_t);
|
||||
return ((uintptr_t) block - (uintptr_t) codeblock) / sizeof(codeblock_t);
|
||||
}
|
||||
|
||||
static inline codeblock_t *codeblock_tree_find(uint32_t phys, uint32_t _cs)
|
||||
static inline codeblock_t *
|
||||
codeblock_tree_find(uint32_t phys, uint32_t _cs)
|
||||
{
|
||||
codeblock_t *block;
|
||||
uint64_t a = _cs | ((uint64_t)phys << 32);
|
||||
codeblock_t *block;
|
||||
uint64_t a = _cs | ((uint64_t) phys << 32);
|
||||
|
||||
if (!pages[phys >> 12].head)
|
||||
return NULL;
|
||||
if (!pages[phys >> 12].head)
|
||||
return NULL;
|
||||
|
||||
block = &codeblock[pages[phys >> 12].head];
|
||||
while (block)
|
||||
{
|
||||
uint64_t block_cmp = block->_cs | ((uint64_t)block->phys << 32);
|
||||
if (a == block_cmp)
|
||||
{
|
||||
if (!((block->status ^ cpu_cur_status) & CPU_STATUS_FLAGS) &&
|
||||
((block->status & cpu_cur_status & CPU_STATUS_MASK) == (cpu_cur_status & CPU_STATUS_MASK)))
|
||||
break;
|
||||
}
|
||||
if (a < block_cmp)
|
||||
block = block->left ? &codeblock[block->left] : NULL;
|
||||
else
|
||||
block = block->right ? &codeblock[block->right] : NULL;
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
static inline void codeblock_tree_add(codeblock_t *new_block)
|
||||
{
|
||||
codeblock_t *block = &codeblock[pages[new_block->phys >> 12].head];
|
||||
uint64_t a = new_block->_cs | ((uint64_t)new_block->phys << 32);
|
||||
|
||||
if (!pages[new_block->phys >> 12].head)
|
||||
{
|
||||
pages[new_block->phys >> 12].head = get_block_nr(new_block);
|
||||
new_block->parent = new_block->left = new_block->right = BLOCK_INVALID;
|
||||
block = &codeblock[pages[phys >> 12].head];
|
||||
while (block) {
|
||||
uint64_t block_cmp = block->_cs | ((uint64_t) block->phys << 32);
|
||||
if (a == block_cmp) {
|
||||
if (!((block->status ^ cpu_cur_status) & CPU_STATUS_FLAGS) && ((block->status & cpu_cur_status & CPU_STATUS_MASK) == (cpu_cur_status & CPU_STATUS_MASK)))
|
||||
break;
|
||||
}
|
||||
if (a < block_cmp)
|
||||
block = block->left ? &codeblock[block->left] : NULL;
|
||||
else
|
||||
{
|
||||
codeblock_t *old_block = NULL;
|
||||
uint64_t old_block_cmp = 0;
|
||||
block = block->right ? &codeblock[block->right] : NULL;
|
||||
}
|
||||
|
||||
while (block)
|
||||
{
|
||||
old_block = block;
|
||||
old_block_cmp = old_block->_cs | ((uint64_t)old_block->phys << 32);
|
||||
|
||||
if (a < old_block_cmp)
|
||||
block = block->left ? &codeblock[block->left] : NULL;
|
||||
else
|
||||
block = block->right ? &codeblock[block->right] : NULL;
|
||||
}
|
||||
|
||||
if (a < old_block_cmp)
|
||||
old_block->left = get_block_nr(new_block);
|
||||
else
|
||||
old_block->right = get_block_nr(new_block);
|
||||
|
||||
new_block->parent = get_block_nr(old_block);
|
||||
new_block->left = new_block->right = BLOCK_INVALID;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
static inline void codeblock_tree_delete(codeblock_t *block)
|
||||
static inline void
|
||||
codeblock_tree_add(codeblock_t *new_block)
|
||||
{
|
||||
uint16_t parent_nr = block->parent;
|
||||
codeblock_t *parent;
|
||||
codeblock_t *block = &codeblock[pages[new_block->phys >> 12].head];
|
||||
uint64_t a = new_block->_cs | ((uint64_t) new_block->phys << 32);
|
||||
|
||||
if (block->parent)
|
||||
parent = &codeblock[block->parent];
|
||||
if (!pages[new_block->phys >> 12].head) {
|
||||
pages[new_block->phys >> 12].head = get_block_nr(new_block);
|
||||
new_block->parent = new_block->left = new_block->right = BLOCK_INVALID;
|
||||
} else {
|
||||
codeblock_t *old_block = NULL;
|
||||
uint64_t old_block_cmp = 0;
|
||||
|
||||
while (block) {
|
||||
old_block = block;
|
||||
old_block_cmp = old_block->_cs | ((uint64_t) old_block->phys << 32);
|
||||
|
||||
if (a < old_block_cmp)
|
||||
block = block->left ? &codeblock[block->left] : NULL;
|
||||
else
|
||||
block = block->right ? &codeblock[block->right] : NULL;
|
||||
}
|
||||
|
||||
if (a < old_block_cmp)
|
||||
old_block->left = get_block_nr(new_block);
|
||||
else
|
||||
parent = NULL;
|
||||
old_block->right = get_block_nr(new_block);
|
||||
|
||||
if (!block->left && !block->right)
|
||||
{
|
||||
/*Easy case - remove from parent*/
|
||||
if (!parent)
|
||||
pages[block->phys >> 12].head = BLOCK_INVALID;
|
||||
else
|
||||
{
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr)
|
||||
parent->left = BLOCK_INVALID;
|
||||
if (parent->right == block_nr)
|
||||
parent->right = BLOCK_INVALID;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (!block->left)
|
||||
{
|
||||
/*Only right node*/
|
||||
if (!parent_nr)
|
||||
{
|
||||
pages[block->phys >> 12].head = block->right;
|
||||
codeblock[pages[block->phys >> 12].head].parent = BLOCK_INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr)
|
||||
{
|
||||
parent->left = block->right;
|
||||
codeblock[parent->left].parent = parent_nr;
|
||||
}
|
||||
if (parent->right == block_nr)
|
||||
{
|
||||
parent->right = block->right;
|
||||
codeblock[parent->right].parent = parent_nr;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (!block->right)
|
||||
{
|
||||
/*Only left node*/
|
||||
if (!parent_nr)
|
||||
{
|
||||
pages[block->phys >> 12].head = block->left;
|
||||
codeblock[pages[block->phys >> 12].head].parent = BLOCK_INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr)
|
||||
{
|
||||
parent->left = block->left;
|
||||
codeblock[parent->left].parent = parent_nr;
|
||||
}
|
||||
if (parent->right == block_nr)
|
||||
{
|
||||
parent->right = block->left;
|
||||
codeblock[parent->right].parent = parent_nr;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*Difficult case - node has two children. Walk right child to find lowest node*/
|
||||
codeblock_t *lowest = &codeblock[block->right], *highest;
|
||||
codeblock_t *old_parent;
|
||||
uint16_t lowest_nr;
|
||||
|
||||
while (lowest->left)
|
||||
lowest = &codeblock[lowest->left];
|
||||
lowest_nr = get_block_nr(lowest);
|
||||
|
||||
old_parent = &codeblock[lowest->parent];
|
||||
|
||||
/*Replace deleted node with lowest node*/
|
||||
if (!parent_nr)
|
||||
pages[block->phys >> 12].head = lowest_nr;
|
||||
else
|
||||
{
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr)
|
||||
parent->left = lowest_nr;
|
||||
if (parent->right == block_nr)
|
||||
parent->right = lowest_nr;
|
||||
}
|
||||
|
||||
lowest->parent = parent_nr;
|
||||
lowest->left = block->left;
|
||||
if (lowest->left)
|
||||
codeblock[lowest->left].parent = lowest_nr;
|
||||
|
||||
old_parent->left = BLOCK_INVALID;
|
||||
|
||||
highest = &codeblock[lowest->right];
|
||||
if (!lowest->right)
|
||||
{
|
||||
if (lowest_nr != block->right)
|
||||
{
|
||||
lowest->right = block->right;
|
||||
codeblock[block->right].parent = lowest_nr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
while (highest->right)
|
||||
highest = &codeblock[highest->right];
|
||||
|
||||
if (block->right && block->right != lowest_nr)
|
||||
{
|
||||
highest->right = block->right;
|
||||
codeblock[block->right].parent = get_block_nr(highest);
|
||||
}
|
||||
}
|
||||
new_block->parent = get_block_nr(old_block);
|
||||
new_block->left = new_block->right = BLOCK_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
#define PAGE_MASK_MASK 63
|
||||
static inline void
|
||||
codeblock_tree_delete(codeblock_t *block)
|
||||
{
|
||||
uint16_t parent_nr = block->parent;
|
||||
codeblock_t *parent;
|
||||
|
||||
if (block->parent)
|
||||
parent = &codeblock[block->parent];
|
||||
else
|
||||
parent = NULL;
|
||||
|
||||
if (!block->left && !block->right) {
|
||||
/*Easy case - remove from parent*/
|
||||
if (!parent)
|
||||
pages[block->phys >> 12].head = BLOCK_INVALID;
|
||||
else {
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr)
|
||||
parent->left = BLOCK_INVALID;
|
||||
if (parent->right == block_nr)
|
||||
parent->right = BLOCK_INVALID;
|
||||
}
|
||||
return;
|
||||
} else if (!block->left) {
|
||||
/*Only right node*/
|
||||
if (!parent_nr) {
|
||||
pages[block->phys >> 12].head = block->right;
|
||||
codeblock[pages[block->phys >> 12].head].parent = BLOCK_INVALID;
|
||||
} else {
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr) {
|
||||
parent->left = block->right;
|
||||
codeblock[parent->left].parent = parent_nr;
|
||||
}
|
||||
if (parent->right == block_nr) {
|
||||
parent->right = block->right;
|
||||
codeblock[parent->right].parent = parent_nr;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (!block->right) {
|
||||
/*Only left node*/
|
||||
if (!parent_nr) {
|
||||
pages[block->phys >> 12].head = block->left;
|
||||
codeblock[pages[block->phys >> 12].head].parent = BLOCK_INVALID;
|
||||
} else {
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr) {
|
||||
parent->left = block->left;
|
||||
codeblock[parent->left].parent = parent_nr;
|
||||
}
|
||||
if (parent->right == block_nr) {
|
||||
parent->right = block->left;
|
||||
codeblock[parent->right].parent = parent_nr;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
/*Difficult case - node has two children. Walk right child to find lowest node*/
|
||||
codeblock_t *lowest = &codeblock[block->right], *highest;
|
||||
codeblock_t *old_parent;
|
||||
uint16_t lowest_nr;
|
||||
|
||||
while (lowest->left)
|
||||
lowest = &codeblock[lowest->left];
|
||||
lowest_nr = get_block_nr(lowest);
|
||||
|
||||
old_parent = &codeblock[lowest->parent];
|
||||
|
||||
/*Replace deleted node with lowest node*/
|
||||
if (!parent_nr)
|
||||
pages[block->phys >> 12].head = lowest_nr;
|
||||
else {
|
||||
uint16_t block_nr = get_block_nr(block);
|
||||
|
||||
if (parent->left == block_nr)
|
||||
parent->left = lowest_nr;
|
||||
if (parent->right == block_nr)
|
||||
parent->right = lowest_nr;
|
||||
}
|
||||
|
||||
lowest->parent = parent_nr;
|
||||
lowest->left = block->left;
|
||||
if (lowest->left)
|
||||
codeblock[lowest->left].parent = lowest_nr;
|
||||
|
||||
old_parent->left = BLOCK_INVALID;
|
||||
|
||||
highest = &codeblock[lowest->right];
|
||||
if (!lowest->right) {
|
||||
if (lowest_nr != block->right) {
|
||||
lowest->right = block->right;
|
||||
codeblock[block->right].parent = lowest_nr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
while (highest->right)
|
||||
highest = &codeblock[highest->right];
|
||||
|
||||
if (block->right && block->right != lowest_nr) {
|
||||
highest->right = block->right;
|
||||
codeblock[block->right].parent = get_block_nr(highest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define PAGE_MASK_MASK 63
|
||||
#define PAGE_MASK_SHIFT 6
|
||||
|
||||
void codegen_mark_code_present_multibyte(codeblock_t *block, uint32_t start_pc, int len);
|
||||
|
||||
static inline void codegen_mark_code_present(codeblock_t *block, uint32_t start_pc, int len)
|
||||
static inline void
|
||||
codegen_mark_code_present(codeblock_t *block, uint32_t start_pc, int len)
|
||||
{
|
||||
if (len == 1)
|
||||
{
|
||||
if (block->flags & CODEBLOCK_BYTE_MASK)
|
||||
{
|
||||
if (!((start_pc ^ block->pc) & ~0x3f)) /*Starts in second page*/
|
||||
block->page_mask |= ((uint64_t)1 << (start_pc & PAGE_MASK_MASK));
|
||||
else
|
||||
block->page_mask2 |= ((uint64_t)1 << (start_pc & PAGE_MASK_MASK));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!((start_pc ^ block->pc) & ~0xfff)) /*Starts in second page*/
|
||||
block->page_mask |= ((uint64_t)1 << ((start_pc >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK));
|
||||
else
|
||||
block->page_mask2 |= ((uint64_t)1 << ((start_pc >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK));
|
||||
}
|
||||
if (len == 1) {
|
||||
if (block->flags & CODEBLOCK_BYTE_MASK) {
|
||||
if (!((start_pc ^ block->pc) & ~0x3f)) /*Starts in second page*/
|
||||
block->page_mask |= ((uint64_t) 1 << (start_pc & PAGE_MASK_MASK));
|
||||
else
|
||||
block->page_mask2 |= ((uint64_t) 1 << (start_pc & PAGE_MASK_MASK));
|
||||
} else {
|
||||
if (!((start_pc ^ block->pc) & ~0xfff)) /*Starts in second page*/
|
||||
block->page_mask |= ((uint64_t) 1 << ((start_pc >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK));
|
||||
else
|
||||
block->page_mask2 |= ((uint64_t) 1 << ((start_pc >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK));
|
||||
}
|
||||
else
|
||||
codegen_mark_code_present_multibyte(block, start_pc, len);
|
||||
} else
|
||||
codegen_mark_code_present_multibyte(block, start_pc, len);
|
||||
}
|
||||
|
||||
extern void codegen_init(void);
|
||||
@@ -329,7 +299,7 @@ extern void codegen_set_op32(void);
|
||||
extern void codegen_flush(void);
|
||||
extern void codegen_check_flush(struct page_t *page, uint64_t mask, uint32_t phys_addr);
|
||||
struct ir_data_t;
|
||||
x86seg *codegen_generate_ea(struct ir_data_t *ir, x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t op_32, int stack_offset);
|
||||
x86seg *codegen_generate_ea(struct ir_data_t *ir, x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t op_32, int stack_offset);
|
||||
extern void codegen_check_seg_read(codeblock_t *block, struct ir_data_t *ir, x86seg *seg);
|
||||
extern void codegen_check_seg_write(codeblock_t *block, struct ir_data_t *ir, x86seg *seg);
|
||||
|
||||
@@ -338,7 +308,7 @@ extern int codegen_purge_purgable_list(void);
|
||||
will only be called when the allocator is out of memory*/
|
||||
extern void codegen_delete_random_block(int required_mem_block);
|
||||
|
||||
extern int cpu_block_end;
|
||||
extern int cpu_block_end;
|
||||
extern uint32_t codegen_endpc;
|
||||
|
||||
extern int cpu_reps;
|
||||
@@ -353,14 +323,13 @@ extern void (*codegen_timing_block_start)(void);
|
||||
extern void (*codegen_timing_block_end)(void);
|
||||
extern int (*codegen_timing_jump_cycles)(void);
|
||||
|
||||
typedef struct codegen_timing_t
|
||||
{
|
||||
void (*start)(void);
|
||||
void (*prefix)(uint8_t prefix, uint32_t fetchdat);
|
||||
void (*opcode)(uint8_t opcode, uint32_t fetchdat, int op_32, uint32_t op_pc);
|
||||
void (*block_start)(void);
|
||||
void (*block_end)(void);
|
||||
int (*jump_cycles)(void);
|
||||
typedef struct codegen_timing_t {
|
||||
void (*start)(void);
|
||||
void (*prefix)(uint8_t prefix, uint32_t fetchdat);
|
||||
void (*opcode)(uint8_t opcode, uint32_t fetchdat, int op_32, uint32_t op_pc);
|
||||
void (*block_start)(void);
|
||||
void (*block_end)(void);
|
||||
int (*jump_cycles)(void);
|
||||
} codegen_timing_t;
|
||||
|
||||
extern codegen_timing_t codegen_timing_pentium;
|
||||
@@ -371,7 +340,6 @@ extern codegen_timing_t codegen_timing_winchip2;
|
||||
extern codegen_timing_t codegen_timing_k6;
|
||||
extern codegen_timing_t codegen_timing_p6;
|
||||
|
||||
|
||||
void codegen_timing_set(codegen_timing_t *timing);
|
||||
|
||||
extern int block_current;
|
||||
@@ -382,8 +350,8 @@ extern int block_pos;
|
||||
/*Current physical page of block being recompiled. -1 if no recompilation taking place */
|
||||
extern uint32_t recomp_page;
|
||||
|
||||
extern x86seg *op_ea_seg;
|
||||
extern int op_ssegs;
|
||||
extern x86seg *op_ea_seg;
|
||||
extern int op_ssegs;
|
||||
extern uint32_t op_old_pc;
|
||||
|
||||
/*Set to 1 if flags have been changed in the block being recompiled, and hence
|
||||
@@ -400,11 +368,11 @@ extern int codegen_in_recompile;
|
||||
|
||||
void codegen_generate_reset(void);
|
||||
|
||||
int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_instruction, int *TOP);
|
||||
int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_instruction, int *TOP);
|
||||
void codegen_set_loop_start(struct ir_data_t *ir, int first_instruction);
|
||||
|
||||
#ifdef DEBUG_EXTRA
|
||||
extern uint32_t instr_counts[256*256];
|
||||
extern uint32_t instr_counts[256 * 256];
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user