Skip to content

Commit

Permalink
VM: Tweaks to get all tests running on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumDev committed Jan 22, 2024
1 parent 7824984 commit e056d1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1129,13 +1129,22 @@ private void ExecBNot()
}
}

// The .NET optimizer seems to break on this instruction on ARM
// The bytecode format should be reduced to 32-bit to help with this
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
void UnpackSwitch(Instruction i, out uint strCount, out uint numCount)
{
strCount = (uint)i.NumVal;
numCount = i.NumValB;
}

private int ExecSwitch(int currentPtr, Instruction i, ref CallStackItem cframe)
{
//Decode
//First 3 table entries are present with bit flags
int nil = -1, ctrue = -1, cfalse = -1;
int strOff = 1;
uint strCount = (uint)i.NumVal;
UnpackSwitch(i, out var strCount, out var numCount);
if ((strCount & 0x80000000) != 0)
nil = strOff++;
if ((strCount & 0x40000000) != 0)
Expand All @@ -1146,10 +1155,14 @@ private int ExecSwitch(int currentPtr, Instruction i, ref CallStackItem cframe)
strCount &= 0x1FFFFFFF;
//get number entries
int numOff = (int) (strOff + strCount);
uint numCount = i.NumValB;
//default comes immediately after switch case
int defaultPtr = (int)(currentPtr + numOff + numCount);
int GetJump(FunctionProto p, int offset) => (int) (currentPtr + (p.code[currentPtr + offset].NumValB));
int GetJump(FunctionProto p, int offset)
{
UnpackSwitch(p.code[currentPtr + offset], out _, out var b);
return (int)(currentPtr + b);
}

var value = m_ValueStack.Pop().ToScalar();
switch (value.Type)
{
Expand All @@ -1167,11 +1180,12 @@ private int ExecSwitch(int currentPtr, Instruction i, ref CallStackItem cframe)
for (int j = 0; j < numCount; j++)
{
var ins = cframe.Function.code[currentPtr + numOff + j];
if (ins.OpCode == OpCode.SInteger && ins.NumVal == d) {
return (int) (currentPtr + ins.NumValB);
UnpackSwitch(ins, out var a, out var b);
if (ins.OpCode == OpCode.SInteger && a == d) {
return (int) (currentPtr + b);
}
if (ins.OpCode == OpCode.SNumber && d == cframe.Function.numbers[ins.NumVal]) {
return (int) (currentPtr + ins.NumValB);
if (ins.OpCode == OpCode.SNumber && d == cframe.Function.numbers[a]) {
return (int) (currentPtr + b);
}
}
return defaultPtr;
Expand All @@ -1180,8 +1194,9 @@ private int ExecSwitch(int currentPtr, Instruction i, ref CallStackItem cframe)
for (int j = 0; j < strCount; j++)
{
var ins = cframe.Function.code[currentPtr + strOff + j];
if (s == cframe.Function.strings[ins.NumVal]) {
return (int) (currentPtr + ins.NumValB);
UnpackSwitch(ins, out var a, out var b);
if (s == cframe.Function.strings[a]) {
return (int) (currentPtr + b);
}
}
return defaultPtr;
Expand Down Expand Up @@ -1277,7 +1292,7 @@ private void ExecBrShiftL()
{
m_ValueStack.Pop();
m_ValueStack.Set(0, DynValue.NewNumber((int)(
(uint)ln >> (int)rn
(uint)(int)ln >> (int)rn
)));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private double EvalArithmetic(DynValue v1, DynValue v2, bool t1Neg = false)
case Operator.BitRShiftA:
return (int) d1 >> (int) d2;
case Operator.BitRShiftL:
return (int) ((uint) d1 >> (int) d2);
return (int) ((uint)(int) d1 >> (int) d2);
case Operator.Add:
case Operator.AddConcat:
return d1 + d2;
Expand Down

0 comments on commit e056d1d

Please sign in to comment.