CPU/Recompiler: Add GetValueInHostOrScratchRegister helper

This commit is contained in:
Connor McLaughlin 2020-11-21 02:05:44 +10:00
parent cdd0a5525a
commit 1128836826
3 changed files with 24 additions and 0 deletions

View File

@ -179,6 +179,7 @@ private:
void ConvertValueSizeInPlace(Value* value, RegSize size, bool sign_extend);
Value GetValueInHostRegister(const Value& value, bool allow_zero_register = true);
Value GetValueInHostOrScratchRegister(const Value& value, bool allow_zero_register = true);
void SwitchToFarCode();
void SwitchToNearCode();

View File

@ -182,6 +182,19 @@ Value CodeGenerator::GetValueInHostRegister(const Value& value, bool allow_zero_
return new_value;
}
Value CodeGenerator::GetValueInHostOrScratchRegister(const Value& value, bool allow_zero_register /* = true */)
{
if (value.IsInHostRegister())
return Value::FromHostReg(&m_register_cache, value.host_reg, value.size);
if (value.HasConstantValue(0) && allow_zero_register)
return Value::FromHostReg(&m_register_cache, static_cast<HostReg>(31), value.size);
Value new_value = Value::FromHostReg(&m_register_cache, RSCRATCH, value.size);
EmitCopyValue(new_value.host_reg, value);
return new_value;
}
void CodeGenerator::EmitBeginBlock()
{
m_emit->Sub(a64::sp, a64::sp, FUNCTION_STACK_SIZE);

View File

@ -196,6 +196,16 @@ Value CodeGenerator::GetValueInHostRegister(const Value& value, bool allow_zero_
return new_value;
}
Value CodeGenerator::GetValueInHostOrScratchRegister(const Value& value, bool allow_zero_register /* = true */)
{
if (value.IsInHostRegister())
return Value(value.regcache, value.host_reg, value.size, ValueFlags::Valid | ValueFlags::InHostRegister);
Value new_value = m_register_cache.AllocateScratch(value.size);
EmitCopyValue(new_value.host_reg, value);
return new_value;
}
void CodeGenerator::EmitBeginBlock()
{
m_register_cache.AssumeCalleeSavedRegistersAreSaved();