2 ms·
To add, to avoid any misunderstanding: the cost is probably within 1-10% in likely scenarios on most real world code. Pathological case would be code with a lo
by vardump 11y ago
To add, to avoid any misunderstanding: the cost is probably within 1-10% in likely scenarios on most real world code.
Pathological case would be code with a lot of taken branches mixed with range/overflow checks.
For range checks, any sane compiler would generate code that doesn't branch if the value is in range. If no branch predictor entry is present, branches are assumed [1] to be not taken. These branches can still thrash BTB (kind of cache trashing) and cause taken branches that fell out of BTB to become always mispredicted, thus very expensive.
[1]: Some architectures do support branch hints, even x86 did so in the past. Modern x86 CPUs simply ignore these hints.
- pcwalton 11y agoNot only that, you lose the ability to pattern match simple arithmetic to LEA and bloat your code size.