some lazy flags handling optimizations

This commit is contained in:
Stanislav Shwartsman 2014-10-22 17:49:12 +00:00
parent 25ad64f75a
commit 1c027b17d7
7 changed files with 37 additions and 35 deletions

View File

@ -342,8 +342,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POPCNT_GwEwR(bxInstruction_c *i)
{
Bit16u op_16 = popcntw(BX_READ_16BIT_REG(i->src()));
Bit32u flags = op_16 ? 0 : EFlagsZFMask;
setEFlagsOSZAPC(flags);
clearEFlagsOSZAPC();
if (! op_16) assert_ZF();
BX_WRITE_16BIT_REG(i->dst(), op_16);

View File

@ -347,8 +347,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POPCNT_GdEdR(bxInstruction_c *i)
{
Bit32u op_32 = popcntd(BX_READ_32BIT_REG(i->src()));
Bit32u flags = op_32 ? 0 : EFlagsZFMask;
setEFlagsOSZAPC(flags);
clearEFlagsOSZAPC();
if (! op_32) assert_ZF();
BX_WRITE_32BIT_REGZ(i->dst(), op_32);

View File

@ -351,8 +351,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POPCNT_GqEqR(bxInstruction_c *i)
{
Bit32u op_32 = popcntq(BX_READ_64BIT_REG(i->src()));
Bit32u flags = op_32 ? 0 : EFlagsZFMask;
setEFlagsOSZAPC(flags);
clearEFlagsOSZAPC();
if (! op_32) assert_ZF();
BX_WRITE_32BIT_REGZ(i->dst(), op_32);

View File

@ -1336,6 +1336,10 @@ public: // for now...
set_PF(1 & ((flags32) >> 2));
set_CF(1 & ((flags32) >> 0));
}
BX_SMF BX_CPP_INLINE void clearEFlagsOSZAPC(void) {
SET_FLAGS_OSZAPC_LOGIC_32(1);
}
BX_SMF BX_CPP_INLINE void SET_FLAGS_OxxxxC(Bit32u new_of, Bit32u new_cf) {
Bit32u temp_po = new_of ^ new_cf;
@ -1432,7 +1436,9 @@ public: // for now...
return ((BX_CPU_THIS_PTR oszapc.auxbits >> LF_BIT_AF) & 1);
}
BX_SMF BX_CPP_INLINE bx_bool get_AF(void) { return getB_AF(); }
BX_SMF BX_CPP_INLINE bx_bool get_AF(void) {
return (BX_CPU_THIS_PTR oszapc.auxbits & LF_MASK_AF);
}
BX_SMF BX_CPP_INLINE void set_AF(bx_bool val) {
BX_CPU_THIS_PTR oszapc.auxbits &= ~(LF_MASK_AF);

View File

@ -631,7 +631,7 @@ void BX_CPU_C::reset(unsigned source)
BX_CPU_THIS_PTR eflags = 0x2; // Bit1 is always set
// clear lazy flags state to satisfy Valgrind uninitialized variables checker
memset(&BX_CPU_THIS_PTR oszapc, 0, sizeof(BX_CPU_THIS_PTR oszapc));
setEFlagsOSZAPC(0); // update lazy flags state
clearEFlagsOSZAPC(); // update lazy flags state
if (source == BX_RESET_HARDWARE)
BX_CPU_THIS_PTR icount = 0;

View File

@ -41,15 +41,14 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDRAND_Ew(bxInstruction_c *i)
Bit16u val_16 = 0;
clearEFlagsOSZAPC();
if (HW_RANDOM_GENERATOR_READY) {
val_16 |= rand() & 0xff; // hack using std C rand() function
val_16 <<= 8;
val_16 |= rand() & 0xff;
setEFlagsOSZAPC(EFlagsCFMask);
}
else {
setEFlagsOSZAPC(0);
assert_CF();
}
BX_WRITE_16BIT_REG(i->dst(), val_16);
@ -69,6 +68,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDRAND_Ed(bxInstruction_c *i)
Bit32u val_32 = 0;
clearEFlagsOSZAPC();
if (HW_RANDOM_GENERATOR_READY) {
val_32 |= rand() & 0xff; // hack using std C rand() function
val_32 <<= 8;
@ -78,10 +79,7 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDRAND_Ed(bxInstruction_c *i)
val_32 <<= 8;
val_32 |= rand() & 0xff;
setEFlagsOSZAPC(EFlagsCFMask);
}
else {
setEFlagsOSZAPC(0);
assert_CF();
}
BX_WRITE_32BIT_REGZ(i->dst(), val_32);
@ -102,6 +100,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDRAND_Eq(bxInstruction_c *i)
Bit64u val_64 = 0;
clearEFlagsOSZAPC();
if (HW_RANDOM_GENERATOR_READY) {
val_64 |= rand() & 0xff; // hack using std C rand() function
val_64 <<= 8;
@ -119,10 +119,7 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDRAND_Eq(bxInstruction_c *i)
val_64 <<= 8;
val_64 |= rand() & 0xff;
setEFlagsOSZAPC(EFlagsCFMask);
}
else {
setEFlagsOSZAPC(0);
assert_CF();
}
BX_WRITE_64BIT_REG(i->dst(), val_64);
@ -143,15 +140,14 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDSEED_Ew(bxInstruction_c *i)
Bit16u val_16 = 0;
clearEFlagsOSZAPC();
if (HW_RANDOM_GENERATOR_READY) {
val_16 |= rand() & 0xff; // hack using std C rand() function
val_16 <<= 8;
val_16 |= rand() & 0xff;
setEFlagsOSZAPC(EFlagsCFMask);
}
else {
setEFlagsOSZAPC(0);
assert_CF();
}
BX_WRITE_16BIT_REG(i->dst(), val_16);
@ -171,6 +167,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDSEED_Ed(bxInstruction_c *i)
Bit32u val_32 = 0;
clearEFlagsOSZAPC();
if (HW_RANDOM_GENERATOR_READY) {
val_32 |= rand() & 0xff; // hack using std C rand() function
val_32 <<= 8;
@ -180,10 +178,7 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDSEED_Ed(bxInstruction_c *i)
val_32 <<= 8;
val_32 |= rand() & 0xff;
setEFlagsOSZAPC(EFlagsCFMask);
}
else {
setEFlagsOSZAPC(0);
assert_CF();
}
BX_WRITE_32BIT_REGZ(i->dst(), val_32);
@ -204,6 +199,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDSEED_Eq(bxInstruction_c *i)
Bit64u val_64 = 0;
clearEFlagsOSZAPC();
if (HW_RANDOM_GENERATOR_READY) {
val_64 |= rand() & 0xff; // hack using std C rand() function
val_64 <<= 8;
@ -221,10 +218,7 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDSEED_Eq(bxInstruction_c *i)
val_64 <<= 8;
val_64 |= rand() & 0xff;
setEFlagsOSZAPC(EFlagsCFMask);
}
else {
setEFlagsOSZAPC(0);
assert_CF();
}
BX_WRITE_64BIT_REG(i->dst(), val_64);

View File

@ -379,12 +379,14 @@ void BX_CPP_AttrRegparmN(2) BX_CPU_C::VMwrite64_Shadow(unsigned encoding, Bit64u
BX_CPP_INLINE void BX_CPU_C::VMfail(Bit32u error_code)
{
clearEFlagsOSZAPC();
if ((BX_CPU_THIS_PTR vmcsptr != BX_INVALID_VMCSPTR)) { // executed only if there is a current VMCS
setEFlagsOSZAPC(EFlagsZFMask);
assert_ZF();
VMwrite32(VMCS_32BIT_INSTRUCTION_ERROR, error_code);
}
else {
setEFlagsOSZAPC(EFlagsCFMask);
assert_CF();
}
}
@ -2390,7 +2392,7 @@ void BX_CPU_C::VMexitLoadHostState(void)
// set flags directly, avoid setEFlags side effects
BX_CPU_THIS_PTR eflags = 0x2; // Bit1 is always set
// Update lazy flags state
setEFlagsOSZAPC(0);
clearEFlagsOSZAPC();
BX_CPU_THIS_PTR activity_state = BX_ACTIVITY_STATE_ACTIVE;