# HG changeset patch # User TomW # Date 1412275976 -3600 # Node ID 1dda97300a324e698baaa23c3d0e004d50e10ba7 # Parent 096e27a8c67b7553293854b2ed54d194ea9a9ea8 Further fixes to IMUL flags. diff -r 096e27a8c67b -r 1dda97300a32 src/x86_ops_misc.h --- a/src/x86_ops_misc.h Sun Sep 28 11:48:52 2014 +0100 +++ b/src/x86_ops_misc.h Thu Oct 02 19:52:56 2014 +0100 @@ -75,8 +75,8 @@ tempws = (int)((int8_t)AL) * (int)((int8_t)dst); AX = tempws & 0xffff; flags_rebuild(); - if (AH && AH != 0xff) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int16_t)AX >> 7) != 0 && ((int16_t)AX >> 7) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 14; break; case 0x30: /*DIV AL,b*/ @@ -163,8 +163,8 @@ tempws = (int)((int8_t)AL) * (int)((int8_t)dst); AX = tempws & 0xffff; flags_rebuild(); - if (AH && AH != 0xff) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int16_t)AX >> 7) != 0 && ((int16_t)AX >> 7) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 14; break; case 0x30: /*DIV AL,b*/ @@ -257,8 +257,8 @@ AX = templ & 0xFFFF; DX = templ >> 16; flags_rebuild(); - if (DX && DX != 0xFFFF) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int32_t)templ >> 15) != 0 && ((int32_t)templ >> 15) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 22; break; case 0x30: /*DIV AX,w*/ @@ -341,8 +341,8 @@ AX = templ & 0xFFFF; DX = templ >> 16; flags_rebuild(); - if (DX && DX != 0xFFFF) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int32_t)templ >> 15) != 0 && ((int32_t)templ >> 15) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 22; break; case 0x30: /*DIV AX,w*/ @@ -425,8 +425,8 @@ EAX = temp64 & 0xffffffff; EDX = temp64 >> 32; flags_rebuild(); - if (EDX && EDX != 0xffffffff) flags |= (C_FLAG|V_FLAG); - else flags &= ~(C_FLAG|V_FLAG); + if (((int64_t)temp64 >> 31) != 0 && ((int64_t)temp64 >> 31) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 38; break; case 0x30: /*DIV EAX,l*/ @@ -485,8 +485,8 @@ EAX = temp64 & 0xffffffff; EDX = temp64 >> 32; flags_rebuild(); - if (EDX && EDX != 0xffffffff) flags |= (C_FLAG|V_FLAG); - else flags &= ~(C_FLAG|V_FLAG); + if (((int64_t)temp64 >> 31) != 0 && ((int64_t)temp64 >> 31) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 38; break; case 0x30: /*DIV EAX,l*/ diff -r 096e27a8c67b -r 1dda97300a32 src/x86_ops_mul.h --- a/src/x86_ops_mul.h Sun Sep 28 11:48:52 2014 +0100 +++ b/src/x86_ops_mul.h Thu Oct 02 19:52:56 2014 +0100 @@ -1,6 +1,6 @@ static int opIMUL_w_iw_a16(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_16(fetchdat); @@ -10,8 +10,8 @@ templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && (templ >> 16) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -19,7 +19,7 @@ } static int opIMUL_w_iw_a32(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_32(fetchdat); @@ -29,8 +29,8 @@ templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && (templ >> 16) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -49,8 +49,8 @@ temp64 = ((int64_t)templ) * ((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles-=25; @@ -68,8 +68,8 @@ temp64 = ((int64_t)templ) * ((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles-=25; @@ -78,7 +78,7 @@ static int opIMUL_w_ib_a16(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_16(fetchdat); @@ -89,8 +89,8 @@ templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && ((templ >> 16) & 0xffff) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -98,7 +98,7 @@ } static int opIMUL_w_ib_a32(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_32(fetchdat); @@ -109,8 +109,8 @@ templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && ((templ >> 16) & 0xffff) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -119,7 +119,7 @@ static int opIMUL_l_ib_a16(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; int32_t templ, templ2; fetch_ea_16(fetchdat); @@ -129,8 +129,8 @@ temp64 = ((int64_t)templ)*((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles -= 20; @@ -138,7 +138,7 @@ } static int opIMUL_l_ib_a32(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; int32_t templ, templ2; fetch_ea_32(fetchdat); @@ -148,8 +148,8 @@ temp64 = ((int64_t)templ)*((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles -= 20; @@ -160,30 +160,30 @@ static int opIMUL_w_w_a16(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; fetch_ea_16(fetchdat); templ = (int32_t)(int16_t)regs[reg].w * (int32_t)(int16_t)geteaw(); if (abrt) return 0; regs[reg].w = templ & 0xFFFF; flags_rebuild(); - if ((templ >> 16) && (templ >> 16) != 0xFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 18; return 0; } static int opIMUL_w_w_a32(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; fetch_ea_32(fetchdat); templ = (int32_t)(int16_t)regs[reg].w * (int32_t)(int16_t)geteaw(); if (abrt) return 0; regs[reg].w = templ & 0xFFFF; flags_rebuild(); - if ((templ >> 16) && (templ >> 16) != 0xFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 18; return 0; @@ -191,30 +191,30 @@ static int opIMUL_l_l_a16(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; fetch_ea_16(fetchdat); temp64 = (int64_t)(int32_t)regs[reg].l * (int64_t)(int32_t)geteal(); if (abrt) return 0; regs[reg].l = temp64 & 0xFFFFFFFF; flags_rebuild(); - if ((temp64 >> 32) && (temp64 >> 32) != 0xFFFFFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 30; return 0; } static int opIMUL_l_l_a32(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; fetch_ea_32(fetchdat); temp64 = (int64_t)(int32_t)regs[reg].l * (int64_t)(int32_t)geteal(); if (abrt) return 0; regs[reg].l = temp64 & 0xFFFFFFFF; flags_rebuild(); - if ((temp64 >> 32) && (temp64 >> 32) != 0xFFFFFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 30; return 0;