VOGONS


First post, by hail-to-the-ryzen

User metadata
Rank Member
Rank
Member

Using computed gotos instead of switch...case in gcc4 is reported to increase performance, although the result depends on the gcc version:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39284

Information on the computed goto method:
http://stackoverflow.com/questions/3848343/de … -interpretation
http://eli.thegreenplace.net/2012/07/12/compu … dispatch-tables
Quote from above:

The computed goto version is faster because of two reasons:
The switch does a bit more per iteration because of bounds checking.
The effects of hardware branch prediction.

The DOSBox normal core uses switch...case statements which may be converted in this way, but instead it is possible to increase performance by removing the bounds checking of the existing cases of switch...case:
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
https://raw.githubusercontent.com/bjacob/buil … dy/master/notes
From above in the case of gcc 4.6:

    switch(x) {
case 0: break;
case 1: result = y; break;
case 2: result = y*y + y; break;
default: __builtin_unreachable(); break;
}

Tested in DOSBox with a 1 to 2% increased framerate in Quake 1 timedemo at 320x240. The disadvantage is the removal of existing error checks such as for unhandled cpu instructions. However, some blocks of code should be unaffected.