aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64/ATranslatedSub.cs
diff options
context:
space:
mode:
authorAlex Barney <thealexbarney@gmail.com>2018-10-30 19:43:02 -0600
committergdkchan <gab.dark.100@gmail.com>2018-10-30 22:43:02 -0300
commit9cb57fb4bb3bbae0ae052a5af4a96a49fc5d864d (patch)
tree0c97425aeb311c142bc92a6fcc503cb2c07d4376 /ChocolArm64/ATranslatedSub.cs
parent5a87e58183578f5b84ca8d01cbb76aed11820f78 (diff)
Adjust naming conventions for Ryujinx and ChocolArm64 projects (#484)
* Change naming convention for Ryujinx project * Change naming convention for ChocolArm64 project * Fix NaN * Remove unneeded this. from Ryujinx project * Adjust naming from new PRs * Name changes based on feedback * How did this get removed? * Rebasing fix * Change FP enum case * Remove prefix from ChocolArm64 classes - Part 1 * Remove prefix from ChocolArm64 classes - Part 2 * Fix alignment from last commit's renaming * Rename namespaces * Rename stragglers * Fix alignment * Rename OpCode class * Missed a few * Adjust alignment
Diffstat (limited to 'ChocolArm64/ATranslatedSub.cs')
-rw-r--r--ChocolArm64/ATranslatedSub.cs150
1 files changed, 0 insertions, 150 deletions
diff --git a/ChocolArm64/ATranslatedSub.cs b/ChocolArm64/ATranslatedSub.cs
deleted file mode 100644
index a11da264..00000000
--- a/ChocolArm64/ATranslatedSub.cs
+++ /dev/null
@@ -1,150 +0,0 @@
-using ChocolArm64.Memory;
-using ChocolArm64.State;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Reflection;
-using System.Reflection.Emit;
-
-namespace ChocolArm64
-{
- class ATranslatedSub
- {
- private delegate long AA64Subroutine(AThreadState Register, AMemory Memory);
-
- private const int MinCallCountForReJit = 250;
-
- private AA64Subroutine ExecDelegate;
-
- public static int StateArgIdx { get; private set; }
- public static int MemoryArgIdx { get; private set; }
-
- public static Type[] FixedArgTypes { get; private set; }
-
- public DynamicMethod Method { get; private set; }
-
- public ReadOnlyCollection<ARegister> Params { get; private set; }
-
- private HashSet<long> Callers;
-
- private ATranslatedSubType Type;
-
- private int CallCount;
-
- private bool NeedsReJit;
-
- public ATranslatedSub(DynamicMethod Method, List<ARegister> Params)
- {
- if (Method == null)
- {
- throw new ArgumentNullException(nameof(Method));
- }
-
- if (Params == null)
- {
- throw new ArgumentNullException(nameof(Params));
- }
-
- this.Method = Method;
- this.Params = Params.AsReadOnly();
-
- Callers = new HashSet<long>();
-
- PrepareDelegate();
- }
-
- static ATranslatedSub()
- {
- MethodInfo MthdInfo = typeof(AA64Subroutine).GetMethod("Invoke");
-
- ParameterInfo[] Params = MthdInfo.GetParameters();
-
- FixedArgTypes = new Type[Params.Length];
-
- for (int Index = 0; Index < Params.Length; Index++)
- {
- Type ParamType = Params[Index].ParameterType;
-
- FixedArgTypes[Index] = ParamType;
-
- if (ParamType == typeof(AThreadState))
- {
- StateArgIdx = Index;
- }
- else if (ParamType == typeof(AMemory))
- {
- MemoryArgIdx = Index;
- }
- }
- }
-
- private void PrepareDelegate()
- {
- string Name = $"{Method.Name}_Dispatch";
-
- DynamicMethod Mthd = new DynamicMethod(Name, typeof(long), FixedArgTypes);
-
- ILGenerator Generator = Mthd.GetILGenerator();
-
- Generator.EmitLdargSeq(FixedArgTypes.Length);
-
- foreach (ARegister Reg in Params)
- {
- Generator.EmitLdarg(StateArgIdx);
-
- Generator.Emit(OpCodes.Ldfld, Reg.GetField());
- }
-
- Generator.Emit(OpCodes.Call, Method);
- Generator.Emit(OpCodes.Ret);
-
- ExecDelegate = (AA64Subroutine)Mthd.CreateDelegate(typeof(AA64Subroutine));
- }
-
- public bool ShouldReJit()
- {
- if (NeedsReJit && CallCount < MinCallCountForReJit)
- {
- CallCount++;
-
- return false;
- }
-
- return NeedsReJit;
- }
-
- public long Execute(AThreadState ThreadState, AMemory Memory)
- {
- return ExecDelegate(ThreadState, Memory);
- }
-
- public void AddCaller(long Position)
- {
- lock (Callers)
- {
- Callers.Add(Position);
- }
- }
-
- public long[] GetCallerPositions()
- {
- lock (Callers)
- {
- return Callers.ToArray();
- }
- }
-
- public void SetType(ATranslatedSubType Type)
- {
- this.Type = Type;
-
- if (Type == ATranslatedSubType.SubTier0)
- {
- NeedsReJit = true;
- }
- }
-
- public void MarkForReJit() => NeedsReJit = true;
- }
-} \ No newline at end of file