Move the MakeOp to OpCodeTable class, for reduce the use of ConcurrentDictionary (#996)
This commit is contained in:
parent
8e64984158
commit
31b94f4641
2 changed files with 35 additions and 47 deletions
|
@ -2,11 +2,14 @@ using ARMeilleure.Instructions;
|
|||
using ARMeilleure.State;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
|
||||
namespace ARMeilleure.Decoders
|
||||
{
|
||||
static class OpCodeTable
|
||||
{
|
||||
public delegate object MakeOp(InstDescriptor inst, ulong address, int opCode);
|
||||
|
||||
private const int FastLookupSize = 0x1000;
|
||||
|
||||
private struct InstInfo
|
||||
|
@ -18,12 +21,32 @@ namespace ARMeilleure.Decoders
|
|||
|
||||
public Type Type { get; }
|
||||
|
||||
public MakeOp MakeOp { get; }
|
||||
|
||||
public InstInfo(int mask, int value, InstDescriptor inst, Type type)
|
||||
{
|
||||
Mask = mask;
|
||||
Value = value;
|
||||
Inst = inst;
|
||||
Type = type;
|
||||
MakeOp = CacheOpActivator(type);
|
||||
}
|
||||
|
||||
private static MakeOp CacheOpActivator(Type type)
|
||||
{
|
||||
Type[] argTypes = new Type[] { typeof(InstDescriptor), typeof(ulong), typeof(int) };
|
||||
|
||||
DynamicMethod mthd = new DynamicMethod($"Make{type.Name}", type, argTypes);
|
||||
|
||||
ILGenerator generator = mthd.GetILGenerator();
|
||||
|
||||
generator.Emit(OpCodes.Ldarg_0);
|
||||
generator.Emit(OpCodes.Ldarg_1);
|
||||
generator.Emit(OpCodes.Ldarg_2);
|
||||
generator.Emit(OpCodes.Newobj, type.GetConstructor(argTypes));
|
||||
generator.Emit(OpCodes.Ret);
|
||||
|
||||
return (MakeOp)mthd.CreateDelegate(typeof(MakeOp));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1034,32 +1057,32 @@ namespace ARMeilleure.Decoders
|
|||
}
|
||||
}
|
||||
|
||||
public static (InstDescriptor inst, Type type) GetInstA32(int opCode)
|
||||
public static (InstDescriptor inst, MakeOp makeOp) GetInstA32(int opCode)
|
||||
{
|
||||
return GetInstFromList(_instA32FastLookup[ToFastLookupIndex(opCode)], opCode);
|
||||
}
|
||||
|
||||
public static (InstDescriptor inst, Type type) GetInstT32(int opCode)
|
||||
public static (InstDescriptor inst, MakeOp makeOp) GetInstT32(int opCode)
|
||||
{
|
||||
return GetInstFromList(_instT32FastLookup[ToFastLookupIndex(opCode)], opCode);
|
||||
}
|
||||
|
||||
public static (InstDescriptor inst, Type type) GetInstA64(int opCode)
|
||||
public static (InstDescriptor inst, MakeOp makeOp) GetInstA64(int opCode)
|
||||
{
|
||||
return GetInstFromList(_instA64FastLookup[ToFastLookupIndex(opCode)], opCode);
|
||||
}
|
||||
|
||||
private static (InstDescriptor inst, Type type) GetInstFromList(InstInfo[] insts, int opCode)
|
||||
private static (InstDescriptor inst, MakeOp makeOp) GetInstFromList(InstInfo[] insts, int opCode)
|
||||
{
|
||||
foreach (InstInfo info in insts)
|
||||
{
|
||||
if ((opCode & info.Mask) == info.Value)
|
||||
{
|
||||
return (info.Inst, info.Type);
|
||||
return (info.Inst, info.MakeOp);
|
||||
}
|
||||
}
|
||||
|
||||
return (new InstDescriptor(InstName.Und, InstEmit.Und), typeof(OpCode));
|
||||
return (new InstDescriptor(InstName.Und, InstEmit.Und), null);
|
||||
}
|
||||
|
||||
private static int ToFastLookupIndex(int value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue