mirror of
https://github.com/mitch030504/Wiicompiled_VR_Frame.git
synced 2026-10-06 13:00:26 +02:00
Port the runtime and translator fixes from upstream's KartPad batch
From patchzyy/Wiicompiled 6f14bde (#244), runtime and translator parts only: - Keep KD and NCD devices available while networking is off; only IP and SSL need the network. - Run RFLiIsWorking's alarm pump in a private interrupt context so callback register writes don't clobber the caller, and release the alarm recursion guard before rescheduling. - Share one LR continuation dispatch per translated function when it has several continuation calls. The renderer half of that commit is left out: it conflicts with the stereo renderer, and upstream reverted part of it (e409d9f) for stutters. (cherry picked from part of commit 6f14bde26a4ed6390d4f18e1b3a9c1be6819d589) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011tcyLz63pXjoYEwsFjfg8F
This commit is contained in:
5 files changed
+102
-25
No files matched your search
@@ -27,7 +27,8 @@ public sealed partial class CxxLinearCodeGenerator
|
||||
IReadOnlyDictionary<uint, GuestAbiContract> stateFreeAbiContracts,
|
||||
IReadOnlyDictionary<uint, string> stateFreeCallSymbols,
|
||||
IReadOnlyDictionary<GuestStateFreeCallSiteKey, GuestStateFreeCallVariant> stateFreeCallSiteVariants,
|
||||
IReadOnlySet<uint> modOverridableCallTargets)
|
||||
IReadOnlySet<uint> modOverridableCallTargets,
|
||||
bool shareLrContinuationDispatch)
|
||||
{
|
||||
if (ins is IrPhi)
|
||||
{
|
||||
@@ -410,11 +411,18 @@ public sealed partial class CxxLinearCodeGenerator
|
||||
fallbackPad = IndentPad(indent + 1);
|
||||
}
|
||||
|
||||
EmitLocalLrContinuationDispatch(sb, fallbackPad, labelNames);
|
||||
sb.AppendLine($"{fallbackPad}if (TranslatedFunctionRegistry::FindByAddressPtr(ctx->lr) != nullptr) {{");
|
||||
sb.AppendLine($"{fallbackPad} InvokeIndirectCpu(ctx->lr, ctx);");
|
||||
sb.AppendLine($"{fallbackPad}}}");
|
||||
sb.AppendLine($"{fallbackPad}return;");
|
||||
if (shareLrContinuationDispatch)
|
||||
{
|
||||
sb.AppendLine($"{fallbackPad}goto lr_continuation_dispatch;");
|
||||
}
|
||||
else
|
||||
{
|
||||
EmitLocalLrContinuationDispatch(sb, fallbackPad, labelNames);
|
||||
sb.AppendLine($"{fallbackPad}if (TranslatedFunctionRegistry::FindByAddressPtr(ctx->lr) != nullptr) {{");
|
||||
sb.AppendLine($"{fallbackPad} InvokeIndirectCpu(ctx->lr, ctx);");
|
||||
sb.AppendLine($"{fallbackPad}}}");
|
||||
sb.AppendLine($"{fallbackPad}return;");
|
||||
}
|
||||
if (localFallthroughLr.HasValue)
|
||||
{
|
||||
sb.AppendLine($"{pad}}}");
|
||||
|
||||
@@ -241,12 +241,14 @@ public sealed partial class CxxLinearCodeGenerator
|
||||
|
||||
var labelNames = func.Blocks.ToDictionary(b => b.Label, b => SanitizeLabel(b.Label), StringComparer.OrdinalIgnoreCase);
|
||||
var instructionContinuationLabels = new Dictionary<uint, string>();
|
||||
var needsInstructionContinuationLabels = func.Blocks
|
||||
var continuationCallCount = func.Blocks
|
||||
.SelectMany(static block => block.Instructions)
|
||||
.OfType<IrCall>()
|
||||
.Any(call =>
|
||||
.Count(call =>
|
||||
TryParseAddress(call.Target, out var target) &&
|
||||
(nonReturningCallTargets.Contains(target) || lrContinuationCallTargets.Contains(target)));
|
||||
var needsInstructionContinuationLabels = continuationCallCount > 0;
|
||||
var shareLrContinuationDispatch = continuationCallCount > 1;
|
||||
if (needsInstructionContinuationLabels)
|
||||
{
|
||||
foreach (var trace in func.Blocks.SelectMany(static block => block.Instructions).OfType<IrTracePpc>())
|
||||
@@ -405,7 +407,7 @@ public sealed partial class CxxLinearCodeGenerator
|
||||
_activeGpuFifoBurstSlot = gpuFifoBurstPlan.Slot(block.Label, i);
|
||||
try
|
||||
{
|
||||
EmitInstruction(block.Label, directCallOrdinal, block.Instructions[i], body, bufferBaseLength, 1, cfg, labelNames, types, signature, localPaired, _guestAbiProvider, knownConstants, localConstants, linkedAddressRemap, nonReturningCallTargets, lrContinuationCallTargets, stackFacts, inlineGuestThunkStackBase, localFallthroughLr, guestAbiContracts, stateFreeAbiContracts, stateFreeCallSymbols, stateFreeCallSiteVariants, modOverridableCallTargets);
|
||||
EmitInstruction(block.Label, directCallOrdinal, block.Instructions[i], body, bufferBaseLength, 1, cfg, labelNames, types, signature, localPaired, _guestAbiProvider, knownConstants, localConstants, linkedAddressRemap, nonReturningCallTargets, lrContinuationCallTargets, stackFacts, inlineGuestThunkStackBase, localFallthroughLr, guestAbiContracts, stateFreeAbiContracts, stateFreeCallSymbols, stateFreeCallSiteVariants, modOverridableCallTargets, shareLrContinuationDispatch);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -423,7 +425,7 @@ public sealed partial class CxxLinearCodeGenerator
|
||||
switch (term)
|
||||
{
|
||||
case IrUndefined undef:
|
||||
EmitInstruction(block.Label, -1, undef, body, bufferBaseLength, 1, cfg, labelNames, types, signature, localPaired, _guestAbiProvider, knownConstants, localConstants, linkedAddressRemap, nonReturningCallTargets, lrContinuationCallTargets, stackFacts, inlineGuestThunkStackBase: false, localFallthroughLr: null, guestAbiContracts, stateFreeAbiContracts, stateFreeCallSymbols, stateFreeCallSiteVariants, modOverridableCallTargets);
|
||||
EmitInstruction(block.Label, -1, undef, body, bufferBaseLength, 1, cfg, labelNames, types, signature, localPaired, _guestAbiProvider, knownConstants, localConstants, linkedAddressRemap, nonReturningCallTargets, lrContinuationCallTargets, stackFacts, inlineGuestThunkStackBase: false, localFallthroughLr: null, guestAbiContracts, stateFreeAbiContracts, stateFreeCallSymbols, stateFreeCallSiteVariants, modOverridableCallTargets, shareLrContinuationDispatch);
|
||||
AppendFlush(body, " ");
|
||||
body.AppendLine(" return;");
|
||||
break;
|
||||
@@ -509,6 +511,18 @@ public sealed partial class CxxLinearCodeGenerator
|
||||
body.AppendLine();
|
||||
}
|
||||
|
||||
if (shareLrContinuationDispatch)
|
||||
{
|
||||
// Every call site has already reloaded the callee's state.
|
||||
// Keep the complete local target set, but emit it only once.
|
||||
body.AppendLine(" return;");
|
||||
body.AppendLine("[[maybe_unused]] lr_continuation_dispatch:");
|
||||
EmitLocalLrContinuationDispatch(body, " ", labelNames);
|
||||
body.AppendLine(" if (TranslatedFunctionRegistry::FindByAddressPtr(ctx->lr) != nullptr) {");
|
||||
body.AppendLine(" InvokeIndirectCpu(ctx->lr, ctx);");
|
||||
body.AppendLine(" }");
|
||||
body.AppendLine(" return;");
|
||||
}
|
||||
body.Append('}');
|
||||
// The residency discovery pass only exists for its side effects
|
||||
// on the recorder; materializing its text costs a full copy of
|
||||
|
||||
Reference in new issue
Block a user