aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64/Translation/TranslatedSub.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ChocolArm64/Translation/TranslatedSub.cs')
-rw-r--r--ChocolArm64/Translation/TranslatedSub.cs55
1 files changed, 47 insertions, 8 deletions
diff --git a/ChocolArm64/Translation/TranslatedSub.cs b/ChocolArm64/Translation/TranslatedSub.cs
index 65d70351..8b599b7a 100644
--- a/ChocolArm64/Translation/TranslatedSub.cs
+++ b/ChocolArm64/Translation/TranslatedSub.cs
@@ -10,21 +10,41 @@ namespace ChocolArm64.Translation
class TranslatedSub
{
+ //This is the minimum amount of calls needed for the method
+ //to be retranslated with higher quality code. It's only worth
+ //doing that for hot code.
+ private const int MinCallCountForOpt = 30;
+
public ArmSubroutine Delegate { get; private set; }
- public static int StateArgIdx { get; private set; }
- public static int MemoryArgIdx { get; private set; }
+ public static int StateArgIdx { get; }
+ public static int MemoryArgIdx { get; }
+
+ public static Type[] FixedArgTypes { get; }
+
+ public DynamicMethod Method { get; }
+
+ public TranslationTier Tier { get; }
- public static Type[] FixedArgTypes { get; private set; }
+ public long IntNiRegsMask { get; }
+ public long VecNiRegsMask { get; }
- public DynamicMethod Method { get; private set; }
+ private bool _isWorthOptimizing;
- public TranslationTier Tier { get; private set; }
+ private int _callCount;
- public TranslatedSub(DynamicMethod method, TranslationTier tier)
+ public TranslatedSub(
+ DynamicMethod method,
+ long intNiRegsMask,
+ long vecNiRegsMask,
+ TranslationTier tier,
+ bool isWorthOptimizing)
{
- Method = method ?? throw new ArgumentNullException(nameof(method));;
- Tier = tier;
+ Method = method ?? throw new ArgumentNullException(nameof(method));;
+ IntNiRegsMask = intNiRegsMask;
+ VecNiRegsMask = vecNiRegsMask;
+ _isWorthOptimizing = isWorthOptimizing;
+ Tier = tier;
}
static TranslatedSub()
@@ -61,5 +81,24 @@ namespace ChocolArm64.Translation
{
return Delegate(threadState, memory);
}
+
+ public bool IsWorthOptimizing()
+ {
+ if (!_isWorthOptimizing)
+ {
+ return false;
+ }
+
+ if (_callCount++ < MinCallCountForOpt)
+ {
+ return false;
+ }
+
+ //Only return true once, so that it is
+ //added to the queue only once.
+ _isWorthOptimizing = false;
+
+ return true;
+ }
}
} \ No newline at end of file