diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2019-04-26 01:55:12 -0300 |
|---|---|---|
| committer | jduncanator <1518948+jduncanator@users.noreply.github.com> | 2019-04-26 14:55:12 +1000 |
| commit | 8a7d99cdeae2355511d4eb43aefb76d0d886bcf8 (patch) | |
| tree | 655d33f4db5dc3eb21c9c4ff5867b1179913585a /ChocolArm64/Instructions | |
| parent | 2b8eac1bcec6d4870776b4f302d9dd7794223642 (diff) | |
Refactoring and optimization on CPU translation (#661)
* Refactoring and optimization on CPU translation
* Remove now unused property
* Rename ilBlock -> block (local)
* Change equality comparison on RegisterMask for consistency
Co-Authored-By: gdkchan <gab.dark.100@gmail.com>
* Add back the aggressive inlining attribute to the Synchronize method
* Implement IEquatable on the Register struct
* Fix identation
Diffstat (limited to 'ChocolArm64/Instructions')
| -rw-r--r-- | ChocolArm64/Instructions/InstEmit32Helper.cs | 29 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitAlu.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitAlu32.cs | 3 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitCcmp.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitCsel.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitException.cs | 9 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitFlow.cs | 17 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitFlow32.cs | 4 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitFlowHelper.cs | 11 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitMemory32.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitMemoryEx.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitMemoryHelper.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitSimdArithmetic.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitSimdCmp.cs | 1 | ||||
| -rw-r--r-- | ChocolArm64/Instructions/InstEmitSimdMove.cs | 1 |
15 files changed, 48 insertions, 34 deletions
diff --git a/ChocolArm64/Instructions/InstEmit32Helper.cs b/ChocolArm64/Instructions/InstEmit32Helper.cs index 792e96f5..49377981 100644 --- a/ChocolArm64/Instructions/InstEmit32Helper.cs +++ b/ChocolArm64/Instructions/InstEmit32Helper.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System; @@ -31,7 +32,7 @@ namespace ChocolArm64.Instructions { if (register == RegisterAlias.Aarch32Pc) { - context.EmitStoreState(); + context.EmitStoreContext(); EmitBxWritePc(context); } @@ -112,13 +113,13 @@ namespace ChocolArm64.Instructions switch (mode) { case Aarch32Mode.User: - case Aarch32Mode.System: return RegisterAlias.SpUsr; - case Aarch32Mode.Fiq: return RegisterAlias.SpFiq; - case Aarch32Mode.Irq: return RegisterAlias.SpIrq; - case Aarch32Mode.Supervisor: return RegisterAlias.SpSvc; - case Aarch32Mode.Abort: return RegisterAlias.SpAbt; - case Aarch32Mode.Hypervisor: return RegisterAlias.SpHyp; - case Aarch32Mode.Undefined: return RegisterAlias.SpUnd; + case Aarch32Mode.System: return RegisterAlias.SpUsr; + case Aarch32Mode.Fiq: return RegisterAlias.SpFiq; + case Aarch32Mode.Irq: return RegisterAlias.SpIrq; + case Aarch32Mode.Supervisor: return RegisterAlias.SpSvc; + case Aarch32Mode.Abort: return RegisterAlias.SpAbt; + case Aarch32Mode.Hypervisor: return RegisterAlias.SpHyp; + case Aarch32Mode.Undefined: return RegisterAlias.SpUnd; default: throw new ArgumentException(nameof(mode)); } @@ -128,12 +129,12 @@ namespace ChocolArm64.Instructions { case Aarch32Mode.User: case Aarch32Mode.Hypervisor: - case Aarch32Mode.System: return RegisterAlias.LrUsr; - case Aarch32Mode.Fiq: return RegisterAlias.LrFiq; - case Aarch32Mode.Irq: return RegisterAlias.LrIrq; - case Aarch32Mode.Supervisor: return RegisterAlias.LrSvc; - case Aarch32Mode.Abort: return RegisterAlias.LrAbt; - case Aarch32Mode.Undefined: return RegisterAlias.LrUnd; + case Aarch32Mode.System: return RegisterAlias.LrUsr; + case Aarch32Mode.Fiq: return RegisterAlias.LrFiq; + case Aarch32Mode.Irq: return RegisterAlias.LrIrq; + case Aarch32Mode.Supervisor: return RegisterAlias.LrSvc; + case Aarch32Mode.Abort: return RegisterAlias.LrAbt; + case Aarch32Mode.Undefined: return RegisterAlias.LrUnd; default: throw new ArgumentException(nameof(mode)); } diff --git a/ChocolArm64/Instructions/InstEmitAlu.cs b/ChocolArm64/Instructions/InstEmitAlu.cs index bd49124e..36ce8c7f 100644 --- a/ChocolArm64/Instructions/InstEmitAlu.cs +++ b/ChocolArm64/Instructions/InstEmitAlu.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System; diff --git a/ChocolArm64/Instructions/InstEmitAlu32.cs b/ChocolArm64/Instructions/InstEmitAlu32.cs index 539e7c43..0b4bac2f 100644 --- a/ChocolArm64/Instructions/InstEmitAlu32.cs +++ b/ChocolArm64/Instructions/InstEmitAlu32.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System.Reflection.Emit; @@ -122,7 +123,7 @@ namespace ChocolArm64.Instructions private static void EmitAluWritePc(ILEmitterCtx context) { - context.EmitStoreState(); + context.EmitStoreContext(); if (IsThumb(context.CurrOp)) { diff --git a/ChocolArm64/Instructions/InstEmitCcmp.cs b/ChocolArm64/Instructions/InstEmitCcmp.cs index 714ae06a..e21dc696 100644 --- a/ChocolArm64/Instructions/InstEmitCcmp.cs +++ b/ChocolArm64/Instructions/InstEmitCcmp.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System; diff --git a/ChocolArm64/Instructions/InstEmitCsel.cs b/ChocolArm64/Instructions/InstEmitCsel.cs index 19b073ce..7008a8c7 100644 --- a/ChocolArm64/Instructions/InstEmitCsel.cs +++ b/ChocolArm64/Instructions/InstEmitCsel.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.Translation; using System.Reflection.Emit; diff --git a/ChocolArm64/Instructions/InstEmitException.cs b/ChocolArm64/Instructions/InstEmitException.cs index 9444397a..7922c62b 100644 --- a/ChocolArm64/Instructions/InstEmitException.cs +++ b/ChocolArm64/Instructions/InstEmitException.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System.Reflection.Emit; @@ -21,7 +22,7 @@ namespace ChocolArm64.Instructions { OpCodeException64 op = (OpCodeException64)context.CurrOp; - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdarg(TranslatedSub.StateArgIdx); @@ -48,7 +49,7 @@ namespace ChocolArm64.Instructions if (context.CurrBlock.Next != null) { - context.EmitLoadState(); + context.EmitLoadContext(); } else { @@ -62,7 +63,7 @@ namespace ChocolArm64.Instructions { OpCode64 op = context.CurrOp; - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdarg(TranslatedSub.StateArgIdx); @@ -73,7 +74,7 @@ namespace ChocolArm64.Instructions if (context.CurrBlock.Next != null) { - context.EmitLoadState(); + context.EmitLoadContext(); } else { diff --git a/ChocolArm64/Instructions/InstEmitFlow.cs b/ChocolArm64/Instructions/InstEmitFlow.cs index 5eae89cc..6355b8b4 100644 --- a/ChocolArm64/Instructions/InstEmitFlow.cs +++ b/ChocolArm64/Instructions/InstEmitFlow.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System.Reflection.Emit; @@ -19,7 +20,7 @@ namespace ChocolArm64.Instructions } else { - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdc_I8(op.Imm); context.Emit(OpCodes.Ret); @@ -50,7 +51,7 @@ namespace ChocolArm64.Instructions context.EmitLdintzr(op.Rn); context.EmitLdc_I(op.Position + 4); context.EmitStint(RegisterAlias.Lr); - context.EmitStoreState(); + context.EmitStoreContext(); EmitVirtualCall(context); } @@ -61,7 +62,7 @@ namespace ChocolArm64.Instructions context.HasIndirectJump = true; - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdintzr(op.Rn); EmitVirtualJump(context); @@ -82,7 +83,7 @@ namespace ChocolArm64.Instructions public static void Ret(ILEmitterCtx context) { - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdint(RegisterAlias.Lr); context.Emit(OpCodes.Ret); @@ -115,7 +116,7 @@ namespace ChocolArm64.Instructions if (context.CurrBlock.Next == null) { - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdc_I8(op.Position + 4); context.Emit(OpCodes.Ret); @@ -123,7 +124,7 @@ namespace ChocolArm64.Instructions } else { - context.EmitStoreState(); + context.EmitStoreContext(); ILLabel lblTaken = new ILLabel(); @@ -151,7 +152,7 @@ namespace ChocolArm64.Instructions if (context.CurrBlock.Next == null) { - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdc_I8(op.Position + 4); context.Emit(OpCodes.Ret); @@ -159,7 +160,7 @@ namespace ChocolArm64.Instructions } else { - context.EmitStoreState(); + context.EmitStoreContext(); ILLabel lblTaken = new ILLabel(); diff --git a/ChocolArm64/Instructions/InstEmitFlow32.cs b/ChocolArm64/Instructions/InstEmitFlow32.cs index dea490c7..b0b9754f 100644 --- a/ChocolArm64/Instructions/InstEmitFlow32.cs +++ b/ChocolArm64/Instructions/InstEmitFlow32.cs @@ -19,7 +19,7 @@ namespace ChocolArm64.Instructions } else { - context.EmitStoreState(); + context.EmitStoreContext(); context.EmitLdc_I8(op.Imm); context.Emit(OpCodes.Ret); @@ -40,7 +40,7 @@ namespace ChocolArm64.Instructions { IOpCode32BReg op = (IOpCode32BReg)context.CurrOp; - context.EmitStoreState(); + context.EmitStoreContext(); EmitLoadFromRegister(context, op.Rm); diff --git a/ChocolArm64/Instructions/InstEmitFlowHelper.cs b/ChocolArm64/Instructions/InstEmitFlowHelper.cs index a6091a57..e7a6bf38 100644 --- a/ChocolArm64/Instructions/InstEmitFlowHelper.cs +++ b/ChocolArm64/Instructions/InstEmitFlowHelper.cs @@ -1,3 +1,4 @@ +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System.Reflection; @@ -11,7 +12,7 @@ namespace ChocolArm64.Instructions { if (context.Tier == TranslationTier.Tier0) { - context.EmitStoreState(); + context.EmitStoreContext(); context.TranslateAhead(imm); @@ -26,13 +27,13 @@ namespace ChocolArm64.Instructions { context.HasSlowCall = true; - context.EmitStoreState(); + context.EmitStoreContext(); context.TranslateAhead(imm); context.EmitLdarg(TranslatedSub.StateArgIdx); - context.EmitFieldLoad(typeof(CpuThreadState).GetField(nameof(CpuThreadState.CurrentTranslator), + context.EmitLdfld(typeof(CpuThreadState).GetField(nameof(CpuThreadState.CurrentTranslator), BindingFlags.Instance | BindingFlags.NonPublic)); @@ -72,7 +73,7 @@ namespace ChocolArm64.Instructions context.EmitSttmp(); context.EmitLdarg(TranslatedSub.StateArgIdx); - context.EmitFieldLoad(typeof(CpuThreadState).GetField(nameof(CpuThreadState.CurrentTranslator), + context.EmitLdfld(typeof(CpuThreadState).GetField(nameof(CpuThreadState.CurrentTranslator), BindingFlags.Instance | BindingFlags.NonPublic)); @@ -132,7 +133,7 @@ namespace ChocolArm64.Instructions context.Emit(OpCodes.Pop); - context.EmitLoadState(); + context.EmitLoadContext(); } else { diff --git a/ChocolArm64/Instructions/InstEmitMemory32.cs b/ChocolArm64/Instructions/InstEmitMemory32.cs index 1e1419e6..647d5755 100644 --- a/ChocolArm64/Instructions/InstEmitMemory32.cs +++ b/ChocolArm64/Instructions/InstEmitMemory32.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System; diff --git a/ChocolArm64/Instructions/InstEmitMemoryEx.cs b/ChocolArm64/Instructions/InstEmitMemoryEx.cs index 920c695f..329fba7e 100644 --- a/ChocolArm64/Instructions/InstEmitMemoryEx.cs +++ b/ChocolArm64/Instructions/InstEmitMemoryEx.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.Memory; using ChocolArm64.State; using ChocolArm64.Translation; diff --git a/ChocolArm64/Instructions/InstEmitMemoryHelper.cs b/ChocolArm64/Instructions/InstEmitMemoryHelper.cs index c225cdd8..4dc40b1a 100644 --- a/ChocolArm64/Instructions/InstEmitMemoryHelper.cs +++ b/ChocolArm64/Instructions/InstEmitMemoryHelper.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.Memory; using ChocolArm64.State; using ChocolArm64.Translation; diff --git a/ChocolArm64/Instructions/InstEmitSimdArithmetic.cs b/ChocolArm64/Instructions/InstEmitSimdArithmetic.cs index 357d88b5..0e610bbb 100644 --- a/ChocolArm64/Instructions/InstEmitSimdArithmetic.cs +++ b/ChocolArm64/Instructions/InstEmitSimdArithmetic.cs @@ -2,6 +2,7 @@ // https://www.agner.org/optimize/#vectorclass @ vectori128.h using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System; diff --git a/ChocolArm64/Instructions/InstEmitSimdCmp.cs b/ChocolArm64/Instructions/InstEmitSimdCmp.cs index d54edb7e..b2925006 100644 --- a/ChocolArm64/Instructions/InstEmitSimdCmp.cs +++ b/ChocolArm64/Instructions/InstEmitSimdCmp.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System; diff --git a/ChocolArm64/Instructions/InstEmitSimdMove.cs b/ChocolArm64/Instructions/InstEmitSimdMove.cs index 131ddec6..841dcfe7 100644 --- a/ChocolArm64/Instructions/InstEmitSimdMove.cs +++ b/ChocolArm64/Instructions/InstEmitSimdMove.cs @@ -1,4 +1,5 @@ using ChocolArm64.Decoders; +using ChocolArm64.IntermediateRepresentation; using ChocolArm64.State; using ChocolArm64.Translation; using System; |
