aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64/Translation/AILEmitterCtx.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-03-04 14:09:59 -0300
committerGitHub <noreply@github.com>2018-03-04 14:09:59 -0300
commit3edb66f389ac279bdcde26c5682aa39b9bf5f853 (patch)
treeb3082b45648417a289ba10c2b40f6c134b93fa98 /ChocolArm64/Translation/AILEmitterCtx.cs
parentee9df32e3e13fe982c8154a6454566c8edfa13d3 (diff)
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
Diffstat (limited to 'ChocolArm64/Translation/AILEmitterCtx.cs')
-rw-r--r--ChocolArm64/Translation/AILEmitterCtx.cs58
1 files changed, 44 insertions, 14 deletions
diff --git a/ChocolArm64/Translation/AILEmitterCtx.cs b/ChocolArm64/Translation/AILEmitterCtx.cs
index ffcfa851..46659469 100644
--- a/ChocolArm64/Translation/AILEmitterCtx.cs
+++ b/ChocolArm64/Translation/AILEmitterCtx.cs
@@ -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()
{
- while (++OpcIndex >= (CurrBlock?.OpCodes.Count ?? 0))
+ if (OpcIndex + 1 == CurrBlock.OpCodes.Count &&
+ BlkIndex + 1 == Graph.Length)
{
- if (BlkIndex + 1 >= Graph.Length)
- {
- return false;
- }
+ return false;
+ }
+ while (++OpcIndex >= (CurrBlock?.OpCodes.Count ?? 0))
+ {
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;