I have simple switch statement in code
switch( _aMap )
{
case RemapKind.Xp: _mover.MoveXPositive( ); break;
case RemapKind.Xn: _mover.MoveXNegative( ); break;
case RemapKind.Yp: _mover.MoveYPositive( ); break;
case RemapKind.Yn: _mover.MoveYNegative( ); break;
case RemapKind.Zp: _mover.MoveZPositive( ); break;
case RemapKind.Zn: _mover.MoveZNegative( ); break;
}
in IL it is simple instruction that generates jump table:
IL_0009: switch (IL_002b, IL_0041, IL_0057, IL_006d, IL_0083, IL_0099)
but IL2CPP generate sequence of ifs:
uint8_t L_0 = (uint8_t)__this->get__cMap_3();
V_0 = (uint8_t)L_0;
uint8_t L_1 = V_0;
if (L_1 == 0)
{
goto IL_002a;
}
if (L_1 == 1)
{
goto IL_0040;
}
if (L_1 == 2)
{
goto IL_0056;
}
if (L_1 == 3)
{
goto IL_006c;
}
if (L_1 == 4)
{
goto IL_0082;
}
if (L_1 == 5)
{
goto IL_0098;
}
WHY Sequence of ifs why not C++ switch statement that can be optimized to 2 jump instructions without branching at all?
What performance I will have for big switches with may be 200 cases?
200 ifs vs 2 jumps?
may be I not understand some thing and C++ compiler can convert this huge if sequence into few jumps?
Can UT explain this? Because looks like we need avoid using switch statement at all in our code.