OpcodeDispatcher: Add a dirty flag for tracking NZCV status

Cached NZCV reads don't need to be written back at the end of the block.
This will remove one instruction from the end of some blocks.
This commit is contained in:
Ryan Houdek committed 2023-09-15 10:09:37 -07:00
1 parent 9152fb030e
commit 759cc0025a
2 files changed
+11 -4

No files matched your search

@@ -869,8 +869,9 @@ private:
}
}
OrderedNode* CachedNZCV = {};
uint32_t PossiblySetNZCVBits = 0;
OrderedNode* CachedNZCV{};
bool NZCVDirty{};
uint32_t PossiblySetNZCVBits{};
fextl::map<uint64_t, JumpTargetInfo> JumpTargets;
bool HandledLock{false};
@@ -1115,11 +1116,13 @@ private:
void SetNZCV(OrderedNode *Value) {
CachedNZCV = Value;
NZCVDirty = true;
}
void ZeroNZCV() {
CachedNZCV = _Constant(0);
PossiblySetNZCVBits = 0;
NZCVDirty = true;
}
void ZeroCV() {
@@ -1152,6 +1155,7 @@ private:
// Mask off just the N bit, which now equals the sign bit
CachedNZCV = _And(OpSize::i32Bit, Shifted, _Constant(1u << NBit));
PossiblySetNZCVBits = (1u << NBit);
NZCVDirty = true;
}
void SetNZ_ZeroCV(unsigned SrcSize, OrderedNode *Res) {
@@ -1160,6 +1164,7 @@ private:
if (SrcSize >= 4) {
CachedNZCV = _TestNZ(SrcSize, Res);
PossiblySetNZCVBits = (1u << 31) | (1u << 30);
NZCVDirty = true;
} else {
// N
SetN_ZeroZCV(SrcSize, Res);
@@ -272,10 +272,11 @@ void OpDispatchBuilder::CalculateAF(OpSize OpSize, OrderedNode *Res, OrderedNode
void OpDispatchBuilder::CalculateDeferredFlags(uint32_t FlagsToCalculateMask) {
if (CurrentDeferredFlags.Type == FlagsGenerationType::TYPE_NONE) {
// Nothing to do
if (CachedNZCV)
if (NZCVDirty && CachedNZCV)
_StoreFlag(CachedNZCV, FEXCore::X86State::RFLAG_NZCV_LOC);
CachedNZCV = nullptr;
NZCVDirty = false;
return;
}
@@ -459,10 +460,11 @@ void OpDispatchBuilder::CalculateDeferredFlags(uint32_t FlagsToCalculateMask) {
// Done calculating
CurrentDeferredFlags.Type = FlagsGenerationType::TYPE_NONE;
if (CachedNZCV)
if (NZCVDirty && CachedNZCV)
_StoreFlag(CachedNZCV, FEXCore::X86State::RFLAG_NZCV_LOC);
CachedNZCV = nullptr;
NZCVDirty = false;
}
void OpDispatchBuilder::CalculateFlags_ADC(uint8_t SrcSize, OrderedNode *Res, OrderedNode *Src1, OrderedNode *Src2, OrderedNode *CF) {