aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2019-02-26 09:50:36 -0300
committerjduncanator <1518948+jduncanator@users.noreply.github.com>2019-02-26 23:50:36 +1100
commit81aa50feb0899e73ee62e5113b786efe0ff6b7a9 (patch)
treea2f947918fe588255dd80225ad3ff1176541255a
parentef3f9a2abe85cfd572ab6bec73481e3526762dcc (diff)
Optimize MOVI/MVNI instructions using intrinsics (#606)
-rw-r--r--ChocolArm64/Instructions/InstEmitSimdMove.cs50
1 files changed, 48 insertions, 2 deletions
diff --git a/ChocolArm64/Instructions/InstEmitSimdMove.cs b/ChocolArm64/Instructions/InstEmitSimdMove.cs
index 7145263d..20647ce0 100644
--- a/ChocolArm64/Instructions/InstEmitSimdMove.cs
+++ b/ChocolArm64/Instructions/InstEmitSimdMove.cs
@@ -318,12 +318,26 @@ namespace ChocolArm64.Instructions
public static void Movi_V(ILEmitterCtx context)
{
- EmitVectorImmUnaryOp(context, () => { });
+ if (Optimizations.UseSse2)
+ {
+ EmitMoviMvni(context, not: false);
+ }
+ else
+ {
+ EmitVectorImmUnaryOp(context, () => { });
+ }
}
public static void Mvni_V(ILEmitterCtx context)
{
- EmitVectorImmUnaryOp(context, () => context.Emit(OpCodes.Not));
+ if (Optimizations.UseSse2)
+ {
+ EmitMoviMvni(context, not: true);
+ }
+ else
+ {
+ EmitVectorImmUnaryOp(context, () => context.Emit(OpCodes.Not));
+ }
}
public static void Smov_S(ILEmitterCtx context)
@@ -480,6 +494,38 @@ namespace ChocolArm64.Instructions
}
}
+ private static void EmitMoviMvni(ILEmitterCtx context, bool not)
+ {
+ OpCodeSimdImm64 op = (OpCodeSimdImm64)context.CurrOp;
+
+ Type[] typesSav = new Type[] { UIntTypesPerSizeLog2[op.Size] };
+
+ long imm = op.Imm;
+
+ if (not)
+ {
+ imm = ~imm;
+ }
+
+ if (op.Size < 3)
+ {
+ context.EmitLdc_I4((int)imm);
+ }
+ else
+ {
+ context.EmitLdc_I8(imm);
+ }
+
+ context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
+
+ context.EmitStvec(op.Rd);
+
+ if (op.RegisterSize == RegisterSize.Simd64)
+ {
+ EmitVectorZeroUpper(context, op.Rd);
+ }
+ }
+
private static void EmitVectorTranspose(ILEmitterCtx context, int part)
{
OpCodeSimdReg64 op = (OpCodeSimdReg64)context.CurrOp;