Skip to content

Commit

Permalink
small switch optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Xytabich committed Nov 17, 2021
1 parent 6169f26 commit 9532b1d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Assets/Katsudon/Builder/Opcodes/SwitchOpcode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection.Emit;
using System;
using System.Reflection.Emit;
using Katsudon.Builder.Externs;

namespace Katsudon.Builder.AsmOpCodes
Expand All @@ -18,9 +19,12 @@ bool IOperationBuider.Process(IMethodDescriptor method)
IVariable condition = null;

indexVariable.Allocate();
CgeOpcode.ProcessOp(method, null, indexVariable, method.machine.GetConstVariable(0),
() => (condition = method.GetTmpVariable(typeof(bool))), out condition);
method.machine.AddBranch(condition, outLabel);
if(!NumberCodeUtils.IsUnsigned(Type.GetTypeCode(indexVariable.type)))
{
CgeOpcode.ProcessOp(method, null, indexVariable, method.machine.GetConstVariable(0),
() => (condition = method.GetTmpVariable(typeof(bool))), out condition);
method.machine.AddBranch(condition, outLabel);
}

var addressVariable = method.GetTmpVariable(typeof(uint)).Reserve();
method.machine.AddExtern(ConvertExtension.GetExternName(typeof(object), typeof(uint)), addressVariable, indexVariable.OwnType());
Expand Down

0 comments on commit 9532b1d

Please sign in to comment.