aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64/Instructions/InstEmitFlow.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/Instructions/InstEmitFlow.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/Instructions/InstEmitFlow.cs')
-rw-r--r--ChocolArm64/Instructions/InstEmitFlow.cs189
1 files changed, 189 insertions, 0 deletions
diff --git a/ChocolArm64/Instructions/InstEmitFlow.cs b/ChocolArm64/Instructions/InstEmitFlow.cs
new file mode 100644
index 00000000..7d0897cd
--- /dev/null
+++ b/ChocolArm64/Instructions/InstEmitFlow.cs
@@ -0,0 +1,189 @@
+using ChocolArm64.Decoders;
+using ChocolArm64.State;
+using ChocolArm64.Translation;
+using System.Reflection.Emit;
+
+namespace ChocolArm64.Instructions
+{
+ static partial class InstEmit
+ {
+ public static void B(ILEmitterCtx context)
+ {
+ OpCodeBImmAl64 op = (OpCodeBImmAl64)context.CurrOp;
+
+ if (context.CurrBlock.Branch != null)
+ {
+ context.Emit(OpCodes.Br, context.GetLabel(op.Imm));
+ }
+ else
+ {
+ context.EmitStoreState();
+ context.EmitLdc_I8(op.Imm);
+
+ context.Emit(OpCodes.Ret);
+ }
+ }
+
+ public static void B_Cond(ILEmitterCtx context)
+ {
+ OpCodeBImmCond64 op = (OpCodeBImmCond64)context.CurrOp;
+
+ EmitBranch(context, op.Cond);
+ }
+
+ public static void Bl(ILEmitterCtx context)
+ {
+ OpCodeBImmAl64 op = (OpCodeBImmAl64)context.CurrOp;
+
+ context.EmitLdc_I(op.Position + 4);
+ context.EmitStint(CpuThreadState.LrIndex);
+ context.EmitStoreState();
+
+ if (context.TryOptEmitSubroutineCall())
+ {
+ //Note: the return value of the called method will be placed
+ //at the Stack, the return value is always a Int64 with the
+ //return address of the function. We check if the address is
+ //correct, if it isn't we keep returning until we reach the dispatcher.
+ context.Emit(OpCodes.Dup);
+
+ context.EmitLdc_I8(op.Position + 4);
+
+ ILLabel lblContinue = new ILLabel();
+
+ context.Emit(OpCodes.Beq_S, lblContinue);
+ context.Emit(OpCodes.Ret);
+
+ context.MarkLabel(lblContinue);
+
+ context.Emit(OpCodes.Pop);
+
+ context.EmitLoadState(context.CurrBlock.Next);
+ }
+ else
+ {
+ context.EmitLdc_I8(op.Imm);
+
+ context.Emit(OpCodes.Ret);
+ }
+ }
+
+ public static void Blr(ILEmitterCtx context)
+ {
+ OpCodeBReg64 op = (OpCodeBReg64)context.CurrOp;
+
+ context.EmitLdc_I(op.Position + 4);
+ context.EmitStint(CpuThreadState.LrIndex);
+ context.EmitStoreState();
+ context.EmitLdintzr(op.Rn);
+
+ context.Emit(OpCodes.Ret);
+ }
+
+ public static void Br(ILEmitterCtx context)
+ {
+ OpCodeBReg64 op = (OpCodeBReg64)context.CurrOp;
+
+ context.EmitStoreState();
+ context.EmitLdintzr(op.Rn);
+
+ context.Emit(OpCodes.Ret);
+ }
+
+ public static void Cbnz(ILEmitterCtx context) => EmitCb(context, OpCodes.Bne_Un);
+ public static void Cbz(ILEmitterCtx context) => EmitCb(context, OpCodes.Beq);
+
+ private static void EmitCb(ILEmitterCtx context, OpCode ilOp)
+ {
+ OpCodeBImmCmp64 op = (OpCodeBImmCmp64)context.CurrOp;
+
+ context.EmitLdintzr(op.Rt);
+ context.EmitLdc_I(0);
+
+ EmitBranch(context, ilOp);
+ }
+
+ public static void Ret(ILEmitterCtx context)
+ {
+ context.EmitStoreState();
+ context.EmitLdint(CpuThreadState.LrIndex);
+
+ context.Emit(OpCodes.Ret);
+ }
+
+ public static void Tbnz(ILEmitterCtx context) => EmitTb(context, OpCodes.Bne_Un);
+ public static void Tbz(ILEmitterCtx context) => EmitTb(context, OpCodes.Beq);
+
+ private static void EmitTb(ILEmitterCtx context, OpCode ilOp)
+ {
+ OpCodeBImmTest64 op = (OpCodeBImmTest64)context.CurrOp;
+
+ context.EmitLdintzr(op.Rt);
+ context.EmitLdc_I(1L << op.Pos);
+
+ context.Emit(OpCodes.And);
+
+ context.EmitLdc_I(0);
+
+ EmitBranch(context, ilOp);
+ }
+
+ private static void EmitBranch(ILEmitterCtx context, Cond cond)
+ {
+ OpCodeBImm64 op = (OpCodeBImm64)context.CurrOp;
+
+ if (context.CurrBlock.Next != null &&
+ context.CurrBlock.Branch != null)
+ {
+ context.EmitCondBranch(context.GetLabel(op.Imm), cond);
+ }
+ else
+ {
+ context.EmitStoreState();
+
+ ILLabel lblTaken = new ILLabel();
+
+ context.EmitCondBranch(lblTaken, cond);
+
+ context.EmitLdc_I8(op.Position + 4);
+
+ context.Emit(OpCodes.Ret);
+
+ context.MarkLabel(lblTaken);
+
+ context.EmitLdc_I8(op.Imm);
+
+ context.Emit(OpCodes.Ret);
+ }
+ }
+
+ private static void EmitBranch(ILEmitterCtx context, OpCode ilOp)
+ {
+ OpCodeBImm64 op = (OpCodeBImm64)context.CurrOp;
+
+ if (context.CurrBlock.Next != null &&
+ context.CurrBlock.Branch != null)
+ {
+ context.Emit(ilOp, context.GetLabel(op.Imm));
+ }
+ else
+ {
+ context.EmitStoreState();
+
+ ILLabel lblTaken = new ILLabel();
+
+ context.Emit(ilOp, lblTaken);
+
+ context.EmitLdc_I8(op.Position + 4);
+
+ context.Emit(OpCodes.Ret);
+
+ context.MarkLabel(lblTaken);
+
+ context.EmitLdc_I8(op.Imm);
+
+ context.Emit(OpCodes.Ret);
+ }
+ }
+ }
+} \ No newline at end of file