4 ms·
That's really good to know. It's still annoying though that C semantics apparently require there to be a bounds-check for every iteration of the switch(): http
by haberman 9y ago
That's really good to know. It's still annoying though that C semantics apparently require there to be a bounds-check for every iteration of the switch(): https://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e... (see "Doing less per iteration")
I've tried using "default: __builtin_unreachable()" but this doesn't seem to help.
- phkahler 9y agoIIRC GCC is capable of dropping the check if it knows the possible range of the switch variable. An example would be using a single byte and having all 256 possibilities exist in the switch. Another would be switch (x & 7) with 8 cases. I have not checked in a while, but I spent a lot of time on code with this issue. It's at the core of my ray tracer of all things.
- gpderetta 9y agoThere is no requirement for range checking in the C standard. That was a missed optimization that was only very recently fixed on GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51513 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51513