Implement CMOV.B and CMOV.W translations. Only the latter has a native

x86 equivalent however.
This commit is contained in:
gbeauche 2007-06-29 16:36:03 +00:00
parent b3f62598b7
commit 9c13d5cda9
3 changed files with 81 additions and 0 deletions

View File

@ -523,6 +523,29 @@ LOWFUNC(READ,WRITE,2,raw_setcc_m,(MEMW d, IMM cc))
}
LENDFUNC(READ,WRITE,2,raw_setcc_m,(MEMW d, IMM cc))
LOWFUNC(READ,NONE,3,raw_cmov_b_rr,(RW1 d, R1 s, IMM cc))
{
/* replacement using branch and mov */
int8 *target_p = (int8 *)x86_get_target() + 1;
JCCSii(cc^1, 0);
MOVBrr(s, d);
*target_p = (uintptr)x86_get_target() - ((uintptr)target_p + 1);
}
LENDFUNC(READ,NONE,3,raw_cmov_b_rr,(RW1 d, R1 s, IMM cc))
LOWFUNC(READ,NONE,3,raw_cmov_w_rr,(RW2 d, R2 s, IMM cc))
{
if (have_cmov)
CMOVWrr(cc, s, d);
else { /* replacement using branch and mov */
int8 *target_p = (int8 *)x86_get_target() + 1;
JCCSii(cc^1, 0);
MOVWrr(s, d);
*target_p = (uintptr)x86_get_target() - ((uintptr)target_p + 1);
}
}
LENDFUNC(READ,NONE,3,raw_cmov_w_rr,(RW2 d, R2 s, IMM cc))
LOWFUNC(READ,NONE,3,raw_cmov_l_rr,(RW4 d, R4 s, IMM cc))
{
if (have_cmov)
@ -1739,6 +1762,36 @@ LOWFUNC(READ,WRITE,2,raw_setcc_m,(MEMW d, IMM cc))
}
LENDFUNC(READ,WRITE,2,raw_setcc_m,(MEMW d, IMM cc))
LOWFUNC(READ,NONE,3,raw_cmov_b_rr,(RW1 d, R1 s, IMM cc))
{
/* replacement using branch and mov */
int uncc=(cc^1);
emit_byte(0x70+uncc);
emit_byte(3); /* skip next 2 bytes if not cc=true */
emit_byte(0x88);
emit_byte(0xc0+8*s+d);
}
LENDFUNC(READ,NONE,3,raw_cmov_b_rr,(RW1 d, R1 s, IMM cc))
LOWFUNC(READ,NONE,3,raw_cmov_w_rr,(RW2 d, R2 s, IMM cc))
{
if (have_cmov) {
emit_byte(0x66);
emit_byte(0x0f);
emit_byte(0x40+cc);
emit_byte(0xc0+8*d+s);
}
else { /* replacement using branch and mov */
int uncc=(cc^1);
emit_byte(0x70+uncc);
emit_byte(3); /* skip next 3 bytes if not cc=true */
emit_byte(0x66);
emit_byte(0x89);
emit_byte(0xc0+8*s+d);
}
}
LENDFUNC(READ,NONE,3,raw_cmov_w_rr,(RW2 d, R2 s, IMM cc))
LOWFUNC(READ,NONE,3,raw_cmov_l_rr,(RW4 d, R4 s, IMM cc))
{
if (have_cmov) {

View File

@ -339,6 +339,8 @@ DECLARE_MIDFUNC(shra_w_ri(RW2 r, IMM i));
DECLARE_MIDFUNC(shra_b_ri(RW1 r, IMM i));
DECLARE_MIDFUNC(setcc(W1 d, IMM cc));
DECLARE_MIDFUNC(setcc_m(IMM d, IMM cc));
DECLARE_MIDFUNC(cmov_b_rr(RW1 d, R1 s, IMM cc));
DECLARE_MIDFUNC(cmov_w_rr(RW2 d, R2 s, IMM cc));
DECLARE_MIDFUNC(cmov_l_rr(RW4 d, R4 s, IMM cc));
DECLARE_MIDFUNC(cmov_l_rm(RW4 d, IMM s, IMM cc));
DECLARE_MIDFUNC(bsf_l_rr(W4 d, R4 s));

View File

@ -2955,6 +2955,32 @@ MIDFUNC(2,setcc_m,(IMM d, IMM cc))
}
MENDFUNC(2,setcc_m,(IMM d, IMM cc))
MIDFUNC(3,cmov_b_rr,(RW1 d, R1 s, IMM cc))
{
if (d==s)
return;
CLOBBER_CMOV;
s=readreg(s,1);
d=rmw(d,1,1);
raw_cmov_b_rr(d,s,cc);
unlock2(s);
unlock2(d);
}
MENDFUNC(3,cmov_b_rr,(RW1 d, R1 s, IMM cc))
MIDFUNC(3,cmov_w_rr,(RW2 d, R2 s, IMM cc))
{
if (d==s)
return;
CLOBBER_CMOV;
s=readreg(s,2);
d=rmw(d,2,2);
raw_cmov_w_rr(d,s,cc);
unlock2(s);
unlock2(d);
}
MENDFUNC(3,cmov_w_rr,(RW2 d, R2 s, IMM cc))
MIDFUNC(3,cmov_l_rr,(RW4 d, R4 s, IMM cc))
{
if (d==s)