mirror of
https://github.com/mitch030504/Wiicompiled_VR_Frame.git
synced 2026-10-06 07:00:30 +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
@@ -0,0 +1,52 @@
|
||||
using Translator.Core.Analysis.Ssa;
|
||||
using Translator.Core.Analysis.Representation;
|
||||
using Translator.Core.CodeGen;
|
||||
using Translator.Core.Ir;
|
||||
using Translator.Core.Representation;
|
||||
using Xunit;
|
||||
|
||||
namespace Translator.Tests;
|
||||
|
||||
public class SharedLrContinuationCodeGenTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(2)]
|
||||
[InlineData(20)]
|
||||
public void MultipleHooksShareOneCompleteDispatchAndKeepNormalFallthrough(int callCount)
|
||||
{
|
||||
var instructions = new List<IrInstruction>();
|
||||
for (var i = 0; i < callCount; i++)
|
||||
{
|
||||
instructions.Add(new IrAssign("lr", IrValue.Imm(unchecked((int)(0x80001004u + (uint)i * 4u)))));
|
||||
instructions.Add(new IrCall(string.Empty, "0x81800000", Array.Empty<IrValue>()));
|
||||
}
|
||||
instructions.Add(new IrAssign("r3", IrValue.Imm(8)));
|
||||
instructions.Add(new IrReturn(null));
|
||||
var function = new IrFunction("shared_lr_continuation", "0x80001000", new[]
|
||||
{
|
||||
new IrBasicBlock("0x80001000", instructions),
|
||||
new IrBasicBlock("0x80001100", new IrInstruction[]
|
||||
{
|
||||
new IrAssign("r3", IrValue.Imm(1)), new IrReturn(null)
|
||||
})
|
||||
});
|
||||
var types = new RepresentationEnvironment(new Dictionary<string, ValueRepresentation>
|
||||
{
|
||||
["lr"] = ValueRepresentation.UInt32, ["r3"] = ValueRepresentation.UInt32
|
||||
});
|
||||
var code = new CxxLinearCodeGenerator().Emit(0x80001000,
|
||||
new SsaTransformer().Convert(function),
|
||||
new FunctionAbiClassification("shared_lr_continuation", ValueRepresentation.Void), types,
|
||||
lrContinuationCallTargets: new HashSet<uint> { 0x81800000u });
|
||||
|
||||
Assert.Equal(1, code.Split("switch (ctx->lr)").Length - 1);
|
||||
Assert.Equal(callCount, code.Split("goto lr_continuation_dispatch;").Length - 1);
|
||||
Assert.Equal(callCount, code.Split("if (ctx->lr != ").Length - 1);
|
||||
Assert.Contains("case 0x80001100u:", code);
|
||||
Assert.Contains("goto loc_80001100;", code);
|
||||
Assert.Contains("InvokeIndirectCpu(ctx->lr, ctx);", code);
|
||||
var sharedLabel = code.IndexOf("lr_continuation_dispatch:", StringComparison.Ordinal);
|
||||
Assert.True(code.IndexOf("r3 = 8;", StringComparison.Ordinal) < sharedLabel);
|
||||
Assert.True(code.IndexOf("case 0x80001100u:", StringComparison.Ordinal) > sharedLabel);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user