Improve CPU initial translation speeds (#50)
* Add background translation to the CPU * Do not use a separate thread for translation, implement 2 tiers translation * Remove unnecessary usings * Lower MinCallCountForReJit * Remove unused variable
This commit is contained in:
parent
ee9df32e3e
commit
3edb66f389
10 changed files with 319 additions and 107 deletions
|
@ -12,14 +12,9 @@ namespace ChocolArm64.Translation
|
|||
{
|
||||
private ATranslator Translator;
|
||||
|
||||
private Dictionary<long, AILLabel> Labels;
|
||||
private HashSet<long> Callees;
|
||||
|
||||
private AILEmitter Emitter;
|
||||
|
||||
private AILBlock ILBlock;
|
||||
|
||||
private AOpCode OptOpLastCompare;
|
||||
private AOpCode OptOpLastFlagSet;
|
||||
private Dictionary<long, AILLabel> Labels;
|
||||
|
||||
private int BlkIndex;
|
||||
private int OpcIndex;
|
||||
|
@ -29,6 +24,13 @@ namespace ChocolArm64.Translation
|
|||
public ABlock CurrBlock => Graph[BlkIndex];
|
||||
public AOpCode CurrOp => Graph[BlkIndex].OpCodes[OpcIndex];
|
||||
|
||||
private AILEmitter Emitter;
|
||||
|
||||
private AILBlock ILBlock;
|
||||
|
||||
private AOpCode OptOpLastCompare;
|
||||
private AOpCode OptOpLastFlagSet;
|
||||
|
||||
//This is the index of the temporary register, used to store temporary
|
||||
//values needed by some functions, since IL doesn't have a swap instruction.
|
||||
//You can use any value here as long it doesn't conflict with the indices
|
||||
|
@ -45,10 +47,27 @@ namespace ChocolArm64.Translation
|
|||
ABlock Root,
|
||||
string SubName)
|
||||
{
|
||||
if (Translator == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Translator));
|
||||
}
|
||||
|
||||
if (Graph == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Graph));
|
||||
}
|
||||
|
||||
if (Root == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Root));
|
||||
}
|
||||
|
||||
this.Translator = Translator;
|
||||
this.Graph = Graph;
|
||||
this.Root = Root;
|
||||
|
||||
Callees = new HashSet<long>();
|
||||
|
||||
Labels = new Dictionary<long, AILLabel>();
|
||||
|
||||
Emitter = new AILEmitter(Graph, Root, SubName);
|
||||
|
@ -57,23 +76,27 @@ namespace ChocolArm64.Translation
|
|||
|
||||
OpcIndex = -1;
|
||||
|
||||
if (!AdvanceOpCode())
|
||||
if (Graph.Length == 0 || !AdvanceOpCode())
|
||||
{
|
||||
throw new ArgumentException(nameof(Graph));
|
||||
}
|
||||
}
|
||||
|
||||
public ATranslatedSub GetSubroutine() => Emitter.GetSubroutine();
|
||||
public ATranslatedSub GetSubroutine()
|
||||
{
|
||||
return Emitter.GetSubroutine(Callees);
|
||||
}
|
||||
|
||||
public bool AdvanceOpCode()
|
||||
{
|
||||
if (OpcIndex + 1 == CurrBlock.OpCodes.Count &&
|
||||
BlkIndex + 1 == Graph.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (++OpcIndex >= (CurrBlock?.OpCodes.Count ?? 0))
|
||||
{
|
||||
if (BlkIndex + 1 >= Graph.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BlkIndex++;
|
||||
OpcIndex = -1;
|
||||
|
||||
|
@ -100,6 +123,13 @@ namespace ChocolArm64.Translation
|
|||
|
||||
public bool TryOptEmitSubroutineCall()
|
||||
{
|
||||
Callees.Add(((AOpCodeBImm)CurrOp).Imm);
|
||||
|
||||
if (CurrBlock.Next == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Translator.TryGetCachedSub(CurrOp, out ATranslatedSub Sub))
|
||||
{
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue