5 ms·
If it's the first time the CPU has seen this code, then the predictor has nothing to go off of, but it will learn "taken" pretty quickly when it sees the `while
by cfallin 11y ago
If it's the first time the CPU has seen this code, then the predictor has nothing to go off of, but it will learn "taken" pretty quickly when it sees the `while` loop continue to iterate.
However, branch predictors also learn based on branch-history context, and sometimes with reasonably long history lengths (see Agner Fog's guide for some numbers), so it's possible that on the second time into this snippet, the predictor might actually get the lengths right for each entry in `stringList`. It really depends on the specific chip.
(There have been some research proposals for "branch confidence predictors" that would halt fetch until the conditional branch is resolved in the backend, for efficiency reasons, but I don't think anything like this has actually been built. See e.g. [1].)
[1] http://people.engr.ncsu.edu/ericro/publications/conference_MICRO-29_jrs.pdf http://people.engr.ncsu.edu/ericro/publications/conference_M...
- fulafel 11y agoBackwards jumps are generally predicted as taken in absence of history information or compiler-provided hint.
- vardump 11y agoThose hints are generally ignored by the CPU anyways.
- fulafel 11y agoAre you referring to Intel's recent change to start ignoring the hint prefix opcodes? I thought at least ARM and PowerPC still honor them in latest chips (and have them as bit flags in branch instruction encoding, instead of verbose prefix bytes).
- deleted 11y ago[deleted]