Remove fake 3-operand instructions in x86 backend.

This commit is contained in:
SarahW 2019-01-28 21:08:01 +00:00
commit b018dc1005
4 changed files with 157 additions and 240 deletions

View file

@ -103,7 +103,7 @@ static int is_imm8(uint32_t imm_data)
return 0;
}
void host_x86_ADD32_REG_ABS(codeblock_t *block, int dst_reg, int src_reg, void *p)
void host_x86_ADD32_REG_ABS(codeblock_t *block, int dst_reg, void *p)
{
int offset = (uintptr_t)p - (((uintptr_t)&cpu_state) + 128);
@ -121,11 +121,8 @@ void host_x86_ADD32_REG_ABS(codeblock_t *block, int dst_reg, int src_reg, void *
}
}
void host_x86_ADD8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t imm_data)
void host_x86_ADD8_REG_IMM(codeblock_t *block, int dst_reg, uint8_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_ADD8_REG_IMM - dst_reg != src_reg\n");
if (dst_reg == REG_EAX)
{
codegen_alloc_bytes(block, 2);
@ -137,11 +134,8 @@ void host_x86_ADD8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t
codegen_addbyte3(block, 0x80, 0xc0 | RM_OP_ADD | dst_reg, imm_data); /*ADD dst_reg, imm_data*/
}
}
void host_x86_ADD16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16_t imm_data)
void host_x86_ADD16_REG_IMM(codeblock_t *block, int dst_reg, uint16_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_ADD16_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 4);
@ -160,11 +154,8 @@ void host_x86_ADD16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16
codegen_addword(block, imm_data);
}
}
void host_x86_ADD32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32_t imm_data)
void host_x86_ADD32_REG_IMM(codeblock_t *block, int dst_reg, uint32_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_ADD32_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 3);
@ -184,29 +175,20 @@ void host_x86_ADD32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32
}
}
void host_x86_ADD8_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_ADD8_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_ADD8_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x00, 0xc0 | dst_reg | (src_reg_b << 3)); /*ADD dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x00, 0xc0 | dst_reg | (src_reg << 3)); /*ADD dst_reg, src_reg*/
}
void host_x86_ADD16_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_ADD16_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_ADD16_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 3);
codegen_addbyte3(block, 0x66, 0x01, 0xc0 | dst_reg | (src_reg_b << 3)); /*ADD dst_reg, src_reg_b*/
codegen_addbyte3(block, 0x66, 0x01, 0xc0 | dst_reg | (src_reg << 3)); /*ADD dst_reg, src_reg*/
}
void host_x86_ADD32_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_ADD32_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_ADD32_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 3);
codegen_addbyte2(block, 0x01, 0xc0 | dst_reg | (src_reg_b << 3)); /*ADD dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x01, 0xc0 | dst_reg | (src_reg << 3)); /*ADD dst_reg, src_reg*/
}
void host_x86_ADDPS_XREG_XREG(codeblock_t *block, int dst_reg, int src_reg)
@ -220,11 +202,8 @@ void host_x86_ADDSD_XREG_XREG(codeblock_t *block, int dst_reg, int src_reg)
codegen_addbyte4(block, 0xf2, 0x0f, 0x58, 0xc0 | src_reg | (dst_reg << 3));
}
void host_x86_AND8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t imm_data)
void host_x86_AND8_REG_IMM(codeblock_t *block, int dst_reg, uint8_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_AND8_REG_IMM - dst_reg != src_reg\n");
if (dst_reg == REG_EAX)
{
codegen_alloc_bytes(block, 2);
@ -236,11 +215,8 @@ void host_x86_AND8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t
codegen_addbyte3(block, 0x80, 0xc0 | RM_OP_AND | dst_reg, imm_data); /*AND dst_reg, imm_data*/
}
}
void host_x86_AND16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16_t imm_data)
void host_x86_AND16_REG_IMM(codeblock_t *block, int dst_reg, uint16_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_AND16_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 4);
@ -259,11 +235,8 @@ void host_x86_AND16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16
codegen_addword(block, imm_data);
}
}
void host_x86_AND32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32_t imm_data)
void host_x86_AND32_REG_IMM(codeblock_t *block, int dst_reg, uint32_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_AND32_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 3);
@ -283,29 +256,20 @@ void host_x86_AND32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32
}
}
void host_x86_AND8_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_AND8_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_AND8_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x20, 0xc0 | dst_reg | (src_reg_b << 3)); /*AND dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x20, 0xc0 | dst_reg | (src_reg << 3)); /*AND dst_reg, src_reg_b*/
}
void host_x86_AND16_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_AND16_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_AND16_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 3);
codegen_addbyte3(block, 0x66, 0x21, 0xc0 | dst_reg | (src_reg_b << 3)); /*AND dst_reg, src_reg_b*/
codegen_addbyte3(block, 0x66, 0x21, 0xc0 | dst_reg | (src_reg << 3)); /*AND dst_reg, src_reg_b*/
}
void host_x86_AND32_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_AND32_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_AND32_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x21, 0xc0 | dst_reg | (src_reg_b << 3)); /*AND dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x21, 0xc0 | dst_reg | (src_reg << 3)); /*AND dst_reg, src_reg_b*/
}
void host_x86_CALL(codeblock_t *block, void *p)
@ -1263,36 +1227,24 @@ void host_x86_MULSD_XREG_XREG(codeblock_t *block, int dst_reg, int src_reg)
codegen_addbyte4(block, 0xf2, 0x0f, 0x59, 0xc0 | src_reg | (dst_reg << 3));
}
void host_x86_OR8_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_OR8_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_OR8_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x08, 0xc0 | dst_reg | (src_reg_b << 3)); /*OR dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x08, 0xc0 | dst_reg | (src_reg << 3)); /*OR dst_reg, src_reg_b*/
}
void host_x86_OR16_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_OR16_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_OR16_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 3);
codegen_addbyte3(block, 0x66, 0x09, 0xc0 | dst_reg | (src_reg_b << 3)); /*OR dst_reg, src_reg_b*/
codegen_addbyte3(block, 0x66, 0x09, 0xc0 | dst_reg | (src_reg << 3)); /*OR dst_reg, src_reg_b*/
}
void host_x86_OR32_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_OR32_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_OR32_REG_IMM - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x09, 0xc0 | dst_reg | (src_reg_b << 3)); /*OR dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x09, 0xc0 | dst_reg | (src_reg << 3)); /*OR dst_reg, src_reg_b*/
}
void host_x86_OR8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t imm_data)
void host_x86_OR8_REG_IMM(codeblock_t *block, int dst_reg, uint8_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_OR8_REG_IMM - dst_reg != src_reg\n");
if (dst_reg == REG_EAX)
{
codegen_alloc_bytes(block, 2);
@ -1304,11 +1256,8 @@ void host_x86_OR8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t
codegen_addbyte3(block, 0x80, 0xc0 | RM_OP_OR | dst_reg, imm_data); /*OR dst_reg, imm_data*/
}
}
void host_x86_OR16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16_t imm_data)
void host_x86_OR16_REG_IMM(codeblock_t *block, int dst_reg, uint16_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_OR16_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 4);
@ -1327,11 +1276,8 @@ void host_x86_OR16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16_
codegen_addword(block, imm_data);
}
}
void host_x86_OR32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32_t imm_data)
void host_x86_OR32_REG_IMM(codeblock_t *block, int dst_reg, uint32_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_OR32_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 3);
@ -1732,11 +1678,8 @@ void host_x86_SQRTSS_XREG_XREG(codeblock_t *block, int dst_reg, int src_reg)
codegen_addbyte4(block, 0xf3, 0x0f, 0x51, 0xc0 | src_reg | (dst_reg << 3)); /*SQRTSS dst_reg, src_reg*/
}
void host_x86_SUB8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t imm_data)
void host_x86_SUB8_REG_IMM(codeblock_t *block, int dst_reg, uint8_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_SUB8_REG_IMM - dst_reg != src_reg\n");
if (dst_reg == REG_EAX)
{
codegen_alloc_bytes(block, 2);
@ -1748,11 +1691,8 @@ void host_x86_SUB8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t
codegen_addbyte3(block, 0x80, 0xc0 | RM_OP_SUB | dst_reg, imm_data); /*SUB dst_reg, imm_data*/
}
}
void host_x86_SUB16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16_t imm_data)
void host_x86_SUB16_REG_IMM(codeblock_t *block, int dst_reg, uint16_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_SUB16_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 4);
@ -1771,11 +1711,8 @@ void host_x86_SUB16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16
codegen_addword(block, imm_data);
}
}
void host_x86_SUB32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32_t imm_data)
void host_x86_SUB32_REG_IMM(codeblock_t *block, int dst_reg, uint32_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_SUB32_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 3);
@ -1795,29 +1732,20 @@ void host_x86_SUB32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32
}
}
void host_x86_SUB8_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_SUB8_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_SUB8_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x28, 0xc0 | dst_reg | (src_reg_b << 3)); /*SUB dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x28, 0xc0 | dst_reg | (src_reg << 3)); /*SUB dst_reg, src_reg*/
}
void host_x86_SUB16_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_SUB16_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_SUB16_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 3);
codegen_addbyte3(block, 0x66, 0x29, 0xc0 | dst_reg | (src_reg_b << 3)); /*SUB dst_reg, src_reg_b*/
codegen_addbyte3(block, 0x66, 0x29, 0xc0 | dst_reg | (src_reg << 3)); /*SUB dst_reg, src_reg*/
}
void host_x86_SUB32_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_SUB32_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_SUB32_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x29, 0xc0 | dst_reg | (src_reg_b << 3)); /*SUB dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x29, 0xc0 | dst_reg | (src_reg << 3)); /*SUB dst_reg, src_reg*/
}
void host_x86_SUBPS_XREG_XREG(codeblock_t *block, int dst_reg, int src_reg)
@ -1868,36 +1796,24 @@ void host_x86_UNPCKLPS_XREG_XREG(codeblock_t *block, int dst_reg, int src_reg)
codegen_addbyte3(block, 0x0f, 0x14, 0xc0 | src_reg | (dst_reg << 3));
}
void host_x86_XOR8_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_XOR8_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_XOR8_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x30, 0xc0 | dst_reg | (src_reg_b << 3)); /*XOR dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x30, 0xc0 | dst_reg | (src_reg << 3)); /*XOR dst_reg, src_reg*/
}
void host_x86_XOR16_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_XOR16_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_XOR16_REG_REG - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 3);
codegen_addbyte3(block, 0x66, 0x31, 0xc0 | dst_reg | (src_reg_b << 3)); /*XOR dst_reg, src_reg_b*/
codegen_addbyte3(block, 0x66, 0x31, 0xc0 | dst_reg | (src_reg << 3)); /*XOR dst_reg, src_reg*/
}
void host_x86_XOR32_REG_REG(codeblock_t *block, int dst_reg, int src_reg_a, int src_reg_b)
void host_x86_XOR32_REG_REG(codeblock_t *block, int dst_reg, int src_reg)
{
if (dst_reg != src_reg_a)
fatal("host_x86_XOR32_REG_IMM - dst_reg != src_reg_a\n");
codegen_alloc_bytes(block, 2);
codegen_addbyte2(block, 0x31, 0xc0 | dst_reg | (src_reg_b << 3)); /*XOR dst_reg, src_reg_b*/
codegen_addbyte2(block, 0x31, 0xc0 | dst_reg | (src_reg << 3)); /*XOR dst_reg, src_reg*/
}
void host_x86_XOR8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t imm_data)
void host_x86_XOR8_REG_IMM(codeblock_t *block, int dst_reg, uint8_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_XOR8_REG_IMM - dst_reg != src_reg\n");
if (dst_reg == REG_EAX)
{
codegen_alloc_bytes(block, 2);
@ -1909,11 +1825,8 @@ void host_x86_XOR8_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint8_t
codegen_addbyte3(block, 0x80, 0xc0 | RM_OP_XOR | dst_reg, imm_data); /*XOR dst_reg, imm_data*/
}
}
void host_x86_XOR16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16_t imm_data)
void host_x86_XOR16_REG_IMM(codeblock_t *block, int dst_reg, uint16_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_XOR16_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 4);
@ -1932,11 +1845,8 @@ void host_x86_XOR16_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint16
codegen_addword(block, imm_data);
}
}
void host_x86_XOR32_REG_IMM(codeblock_t *block, int dst_reg, int src_reg, uint32_t imm_data)
void host_x86_XOR32_REG_IMM(codeblock_t *block, int dst_reg, uint32_t imm_data)
{
if (dst_reg != src_reg)
fatal("host_x86_XOR32_REG_IMM - dst_reg != src_reg\n");
if (is_imm8(imm_data))
{
codegen_alloc_bytes(block, 3);