0
0
Fork 0
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2024-12-23 03:45:46 +00:00

Optmize BFM instruction (#607)

This commit is contained in:
gdkchan 2019-02-26 06:16:50 -03:00 committed by jduncanator
parent 504f4f4abf
commit ef3f9a2abe

View file

@ -11,21 +11,56 @@ namespace ChocolArm64.Instructions
{ {
OpCodeBfm64 op = (OpCodeBfm64)context.CurrOp; OpCodeBfm64 op = (OpCodeBfm64)context.CurrOp;
EmitBfmLoadRn(context); if (op.Pos < op.Shift)
{
//BFI.
context.EmitLdintzr(op.Rn);
context.EmitLdintzr(op.Rd); int shift = op.GetBitsCount() - op.Shift;
context.EmitLdc_I(~op.WMask & op.TMask);
context.Emit(OpCodes.And); int width = op.Pos + 1;
context.Emit(OpCodes.Or);
context.EmitLdintzr(op.Rd); long mask = (long)(ulong.MaxValue >> (64 - width));
context.EmitLdc_I(~op.TMask);
context.Emit(OpCodes.And); context.EmitLdc_I(mask);
context.Emit(OpCodes.Or);
context.EmitStintzr(op.Rd); context.Emit(OpCodes.And);
context.EmitLsl(shift);
context.EmitLdintzr(op.Rd);
context.EmitLdc_I(~(mask << shift));
context.Emit(OpCodes.And);
context.Emit(OpCodes.Or);
context.EmitStintzr(op.Rd);
}
else
{
//BFXIL.
context.EmitLdintzr(op.Rn);
context.EmitLsr(op.Shift);
int width = op.Pos - op.Shift + 1;
long mask = (long)(ulong.MaxValue >> (64 - width));
context.EmitLdc_I(mask);
context.Emit(OpCodes.And);
context.EmitLdintzr(op.Rd);
context.EmitLdc_I(~mask);
context.Emit(OpCodes.And);
context.Emit(OpCodes.Or);
context.EmitStintzr(op.Rd);
}
} }
public static void Sbfm(ILEmitterCtx context) public static void Sbfm(ILEmitterCtx context)