diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2019-02-04 18:26:05 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-04 18:26:05 -0300 |
| commit | a694420d11ef74e4f0bf473be2b6f64635bc89c7 (patch) | |
| tree | 6c44e7a0633dca7b54d99ac3f01f0648fa602559 /ChocolArm64/Translator.cs | |
| parent | f5b4f6ccc4815cfac1fa3c103d8941a26d152d8a (diff) | |
Implement speculative translation on the CPU (#515)
* Implement speculative translation on the cpu, and change the way how branches to unknown or untranslated addresses works
* Port t0opt changes and other cleanups
* Change namespace from translation related classes to ChocolArm64.Translation, other minor tweaks
* Fix typo
* Translate higher quality code for indirect jumps aswell, and on some cases that were missed when lower quality (tier 0) code was available
* Remove debug print
* Remove direct argument passing optimization, and enable tail calls for BR instructions
* Call delegates directly with Callvirt rather than calling Execute, do not emit calls for tier 0 code
* Remove unused property
* Rename argument on ArmSubroutine delegate
Diffstat (limited to 'ChocolArm64/Translator.cs')
| -rw-r--r-- | ChocolArm64/Translator.cs | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/ChocolArm64/Translator.cs b/ChocolArm64/Translator.cs deleted file mode 100644 index af2586f4..00000000 --- a/ChocolArm64/Translator.cs +++ /dev/null @@ -1,120 +0,0 @@ -using ChocolArm64.Decoders; -using ChocolArm64.Events; -using ChocolArm64.Memory; -using ChocolArm64.State; -using ChocolArm64.Translation; -using System; - -namespace ChocolArm64 -{ - public class Translator - { - private TranslatorCache _cache; - - public event EventHandler<CpuTraceEventArgs> CpuTrace; - - public bool EnableCpuTrace { get; set; } - - public Translator() - { - _cache = new TranslatorCache(); - } - - internal void ExecuteSubroutine(CpuThread thread, long position) - { - ExecuteSubroutine(thread.ThreadState, thread.Memory, position); - } - - private void ExecuteSubroutine(CpuThreadState state, MemoryManager memory, long position) - { - do - { - if (EnableCpuTrace) - { - CpuTrace?.Invoke(this, new CpuTraceEventArgs(position)); - } - - if (!_cache.TryGetSubroutine(position, out TranslatedSub sub)) - { - sub = TranslateTier0(memory, position, state.GetExecutionMode()); - } - - if (sub.ShouldReJit()) - { - TranslateTier1(memory, position, state.GetExecutionMode()); - } - - position = sub.Execute(state, memory); - } - while (position != 0 && state.Running); - } - - internal bool HasCachedSub(long position) - { - return _cache.HasSubroutine(position); - } - - private TranslatedSub TranslateTier0(MemoryManager memory, long position, ExecutionMode mode) - { - Block block = Decoder.DecodeBasicBlock(memory, position, mode); - - ILEmitterCtx context = new ILEmitterCtx(_cache, block); - - string subName = GetSubroutineName(position); - - ILMethodBuilder ilMthdBuilder = new ILMethodBuilder(context.GetILBlocks(), subName); - - TranslatedSub subroutine = ilMthdBuilder.GetSubroutine(); - - subroutine.SetType(TranslatedSubType.SubTier0); - - _cache.AddOrUpdate(position, subroutine, block.OpCodes.Count); - - return subroutine; - } - - private void TranslateTier1(MemoryManager memory, long position, ExecutionMode mode) - { - Block graph = Decoder.DecodeSubroutine(_cache, memory, position, mode); - - ILEmitterCtx context = new ILEmitterCtx(_cache, graph); - - ILBlock[] ilBlocks = context.GetILBlocks(); - - string subName = GetSubroutineName(position); - - ILMethodBuilder ilMthdBuilder = new ILMethodBuilder(ilBlocks, subName); - - TranslatedSub subroutine = ilMthdBuilder.GetSubroutine(); - - subroutine.SetType(TranslatedSubType.SubTier1); - - int ilOpCount = 0; - - foreach (ILBlock ilBlock in ilBlocks) - { - ilOpCount += ilBlock.Count; - } - - _cache.AddOrUpdate(position, subroutine, ilOpCount); - - //Mark all methods that calls this method for ReJiting, - //since we can now call it directly which is faster. - if (_cache.TryGetSubroutine(position, out TranslatedSub oldSub)) - { - foreach (long callerPos in oldSub.GetCallerPositions()) - { - if (_cache.TryGetSubroutine(position, out TranslatedSub callerSub)) - { - callerSub.MarkForReJit(); - } - } - } - } - - private string GetSubroutineName(long position) - { - return $"Sub{position:x16}"; - } - } -}
\ No newline at end of file |
