3 ms·
why would an error checking branch ever be mispredicted. more to the point why would error checking or exceptions ever be in an optimized inner loop.
by soup10 7y ago
why would an error checking branch ever be mispredicted. more to the point why would error checking or exceptions ever be in an optimized inner loop.
- kllrnohj 7y agoIf they're rare enough that they are ~never mispredicted then why does the cost of exceptions matter when they do happen? If they are common, then they're going to be mispredicted. The demo benchmark, for example, would produce basically always missed branches. Well, if would if the compiler didn't just strip the empty branch, invalidating the entire benchmark.
- nwallin 7y agoBecause the branch prediction cache puns an error check with a loop predicate and some other random branch. Branch predictors steadily get better, sure, but they're not infallible. Remember that reducing the total number of branches in a program helps the branch predictor predict better.