@@ -1129,13 +1129,22 @@ private void ExecBNot()
1129
1129
}
1130
1130
}
1131
1131
1132
+ // The .NET optimizer seems to break on this instruction on ARM
1133
+ // The bytecode format should be reduced to 32-bit to help with this
1134
+ [ MethodImpl ( MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
1135
+ void UnpackSwitch ( Instruction i , out uint strCount , out uint numCount )
1136
+ {
1137
+ strCount = ( uint ) i . NumVal ;
1138
+ numCount = i . NumValB ;
1139
+ }
1140
+
1132
1141
private int ExecSwitch ( int currentPtr , Instruction i , ref CallStackItem cframe )
1133
1142
{
1134
1143
//Decode
1135
1144
//First 3 table entries are present with bit flags
1136
1145
int nil = - 1 , ctrue = - 1 , cfalse = - 1 ;
1137
1146
int strOff = 1 ;
1138
- uint strCount = ( uint ) i . NumVal ;
1147
+ UnpackSwitch ( i , out var strCount , out var numCount ) ;
1139
1148
if ( ( strCount & 0x80000000 ) != 0 )
1140
1149
nil = strOff ++ ;
1141
1150
if ( ( strCount & 0x40000000 ) != 0 )
@@ -1146,10 +1155,14 @@ private int ExecSwitch(int currentPtr, Instruction i, ref CallStackItem cframe)
1146
1155
strCount &= 0x1FFFFFFF ;
1147
1156
//get number entries
1148
1157
int numOff = ( int ) ( strOff + strCount ) ;
1149
- uint numCount = i . NumValB ;
1150
1158
//default comes immediately after switch case
1151
1159
int defaultPtr = ( int ) ( currentPtr + numOff + numCount ) ;
1152
- int GetJump ( FunctionProto p , int offset ) => ( int ) ( currentPtr + ( p . code [ currentPtr + offset ] . NumValB ) ) ;
1160
+ int GetJump ( FunctionProto p , int offset )
1161
+ {
1162
+ UnpackSwitch ( p . code [ currentPtr + offset ] , out _ , out var b ) ;
1163
+ return ( int ) ( currentPtr + b ) ;
1164
+ }
1165
+
1153
1166
var value = m_ValueStack . Pop ( ) . ToScalar ( ) ;
1154
1167
switch ( value . Type )
1155
1168
{
@@ -1167,11 +1180,12 @@ private int ExecSwitch(int currentPtr, Instruction i, ref CallStackItem cframe)
1167
1180
for ( int j = 0 ; j < numCount ; j ++ )
1168
1181
{
1169
1182
var ins = cframe . Function . code [ currentPtr + numOff + j ] ;
1170
- if ( ins . OpCode == OpCode . SInteger && ins . NumVal == d ) {
1171
- return ( int ) ( currentPtr + ins . NumValB ) ;
1183
+ UnpackSwitch ( ins , out var a , out var b ) ;
1184
+ if ( ins . OpCode == OpCode . SInteger && a == d ) {
1185
+ return ( int ) ( currentPtr + b ) ;
1172
1186
}
1173
- if ( ins . OpCode == OpCode . SNumber && d == cframe . Function . numbers [ ins . NumVal ] ) {
1174
- return ( int ) ( currentPtr + ins . NumValB ) ;
1187
+ if ( ins . OpCode == OpCode . SNumber && d == cframe . Function . numbers [ a ] ) {
1188
+ return ( int ) ( currentPtr + b ) ;
1175
1189
}
1176
1190
}
1177
1191
return defaultPtr ;
@@ -1180,8 +1194,9 @@ private int ExecSwitch(int currentPtr, Instruction i, ref CallStackItem cframe)
1180
1194
for ( int j = 0 ; j < strCount ; j ++ )
1181
1195
{
1182
1196
var ins = cframe . Function . code [ currentPtr + strOff + j ] ;
1183
- if ( s == cframe . Function . strings [ ins . NumVal ] ) {
1184
- return ( int ) ( currentPtr + ins . NumValB ) ;
1197
+ UnpackSwitch ( ins , out var a , out var b ) ;
1198
+ if ( s == cframe . Function . strings [ a ] ) {
1199
+ return ( int ) ( currentPtr + b ) ;
1185
1200
}
1186
1201
}
1187
1202
return defaultPtr ;
@@ -1277,7 +1292,7 @@ private void ExecBrShiftL()
1277
1292
{
1278
1293
m_ValueStack . Pop ( ) ;
1279
1294
m_ValueStack . Set ( 0 , DynValue . NewNumber ( ( int ) (
1280
- ( uint ) ln >> ( int ) rn
1295
+ ( uint ) ( int ) ln >> ( int ) rn
1281
1296
) ) ) ;
1282
1297
}
1283
1298
else
0 commit comments