Created attachment 15526
brainfuck interpreter and example data
Delaring cases in a switch statement like below as unreachable may reduce
performance:
switch x {
case 0: // ...
break;
case 1: // ...
break;
// ....
case 7: // ...
break;
default:
__builtin_unreachable();
}
Removing the __builtin_unreachable() improves the performance. On my PC the
attached example needs about 25 with it and 17 without.
The attached code is a simple brainfuck interpreter that can be tested by
calling "brainfuck-optimized mandel.brainfuck".
It was test with options -O3 and -O2 as 64 bit build on a haswell processor.
The problem is reproducible in Rust.
Profiling shows a suspiciously high number of branch mispredictions. From what
I have seen of the assembler code, I think that nested conditional branches
like a binary search are faster than a branch table by causing fewer
mispredictions.
unreachable-example.tar.gz
(20480 bytes, application/x-gzip)