Pack decoded ModR/M data into a single word - minor recompiler speedup.

This commit is contained in:
SarahW 2016-08-14 16:29:54 +01:00
commit 535604b760
34 changed files with 1263 additions and 1270 deletions

View file

@ -608,7 +608,7 @@ void codegen_debug()
static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc)
{
if (!mod && rm == 6)
if (!cpu_mod && cpu_rm == 6)
{
addbyte(0xC7); /*MOVL $0,(ssegs)*/
addbyte(0x04);
@ -621,7 +621,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat,
{
int base_reg, index_reg;
switch (rm)
switch (cpu_rm)
{
case 0: case 1: case 7:
base_reg = LOAD_REG_W(REG_BX);
@ -636,9 +636,9 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat,
base_reg = LOAD_REG_W(REG_DI);
break;
}
if (!(rm & 4))
if (!(cpu_rm & 4))
{
if (rm & 1)
if (cpu_rm & 1)
index_reg = LOAD_REG_W(REG_DI);
else
index_reg = LOAD_REG_W(REG_SI);
@ -646,10 +646,10 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat,
base_reg &= 7;
index_reg &= 7;
switch (mod)
switch (cpu_mod)
{
case 0:
if (rm & 4)
if (cpu_rm & 4)
{
addbyte(0x41); /*MOVZX EAX, base_reg*/
addbyte(0x0f);
@ -675,7 +675,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat,
}
break;
case 1:
if (rm & 4)
if (cpu_rm & 4)
{
addbyte(0x67); /*LEA EAX, base_reg+imm8*/
addbyte(0x41);
@ -695,7 +695,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat,
(*op_pc)++;
break;
case 2:
if (rm & 4)
if (cpu_rm & 4)
{
addbyte(0x67); /*LEA EAX, base_reg+imm8*/
addbyte(0x41);
@ -716,7 +716,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat,
break;
}
if (mod || !(rm & 4))
if (cpu_mod || !(cpu_rm & 4))
{
addbyte(0x25); /*ANDL $0xffff, %eax*/
addlong(0xffff);
@ -726,7 +726,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat,
addbyte(0x25);
addlong((uint32_t)&eaaddr);
if (mod1seg[rm] == &ss && !op_ssegs)
if (mod1seg[cpu_rm] == &ss && !op_ssegs)
op_ea_seg = &_ss;
}
return op_ea_seg;
@ -736,14 +736,14 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat,
{
uint32_t new_eaaddr;
if (rm == 4)
if (cpu_rm == 4)
{
uint8_t sib = fetchdat >> 8;
int base_reg = -1, index_reg = -1;
(*op_pc)++;
if (mod || (sib & 7) != 5)
if (cpu_mod || (sib & 7) != 5)
base_reg = LOAD_REG_L(sib & 7) & 7;
if (((sib >> 3) & 7) != 4)
@ -751,7 +751,7 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat,
if (index_reg == -1)
{
switch (mod)
switch (cpu_mod)
{
case 0:
if ((sib & 7) == 5)
@ -805,7 +805,7 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat,
}
else
{
switch (mod)
switch (cpu_mod)
{
case 0:
if ((sib & 7) == 5)
@ -869,12 +869,12 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat,
break;
}
}
if (stack_offset && (sib & 7) == 4 && (mod || (sib & 7) != 5)) /*ESP*/
if (stack_offset && (sib & 7) == 4 && (cpu_mod || (sib & 7) != 5)) /*ESP*/
{
addbyte(0x05);
addlong(stack_offset);
}
if (((sib & 7) == 4 || (mod && (sib & 7) == 5)) && !op_ssegs)
if (((sib & 7) == 4 || (cpu_mod && (sib & 7) == 5)) && !op_ssegs)
op_ea_seg = &_ss;
addbyte(0x89); /*MOV eaaddr, EAX*/
@ -886,7 +886,7 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat,
{
int base_reg;
if (!mod && rm == 5)
if (!cpu_mod && cpu_rm == 5)
{
new_eaaddr = fastreadl(cs + (*op_pc) + 1);
addbyte(0xC7); /*MOVL $new_eaaddr,(eaaddr)*/
@ -897,12 +897,12 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat,
(*op_pc) += 4;
return op_ea_seg;
}
base_reg = LOAD_REG_L(rm) & 7;
if (mod)
base_reg = LOAD_REG_L(cpu_rm) & 7;
if (cpu_mod)
{
if (rm == 5 && !op_ssegs)
if (cpu_rm == 5 && !op_ssegs)
op_ea_seg = &_ss;
if (mod == 1)
if (cpu_mod == 1)
{
addbyte(0x67); /*LEA EAX, base_reg+imm8*/
addbyte(0x41);
@ -1167,30 +1167,19 @@ generate_call:
if (op_table == x86_dynarec_opcodes && opcode == 0x8f) /*POP*/
stack_offset = (op_32 & 0x100) ? 4 : 2;
mod = (fetchdat >> 6) & 3;
reg = (fetchdat >> 3) & 7;
rm = fetchdat & 7;
cpu_mod = (fetchdat >> 6) & 3;
cpu_reg = (fetchdat >> 3) & 7;
cpu_rm = fetchdat & 7;
addbyte(0xC7); /*MOVL $mod,(mod)*/
addbyte(0x04);
addbyte(0x25);
addlong((uint32_t)&mod);
addlong(mod);
addbyte(0xC7); /*MOVL $reg,(reg)*/
addbyte(0x04);
addbyte(0x25);
addlong((uint32_t)&reg);
addlong(reg);
addbyte(0xC7); /*MOVL $rm,(rm)*/
addbyte(0x04);
addbyte(0x25);
addlong((uint32_t)&rm);
addlong(rm);
addbyte(0xC7); /*MOVL $rm | mod | reg,(rm_mod_reg_data)*/
addbyte(0x45);
addbyte((uintptr_t)&cpu_state.rm_data.rm_mod_reg_data - (uintptr_t)&cpu_state);
addlong(cpu_rm | (cpu_mod << 8) | (cpu_reg << 16));
op_pc += pc_off;
if (mod != 3 && !(op_32 & 0x200))
if (cpu_mod != 3 && !(op_32 & 0x200))
op_ea_seg = codegen_generate_ea_16_long(op_ea_seg, fetchdat, op_ssegs, &op_pc);
if (mod != 3 && (op_32 & 0x200))
if (cpu_mod != 3 && (op_32 & 0x200))
op_ea_seg = codegen_generate_ea_32_long(op_ea_seg, fetchdat, op_ssegs, &op_pc, stack_offset);
op_pc -= pc_off;
}