Jerry Avins wrote:
> Hard real-time systems have
> little place for statistical inference except when the number of cases
> are similar to those in the gas laws.
In the real systems, there are many checks for the special situations
like overflow, out of range, if something wrong, if not initialized,
etc. It is very unlikely that a branch is going to be taken, however you
have to check the condition anyway. In this case, the static branch
prediction can save dozens of the CPU cycles on every check at the
average. However the hard realtime systems are designed to satisfy the
timing for the worst case, not at the average. Hence there is a little
benefit.
Also, the modern CPUs will fetch the code in the right direction if the
conditional statement is evaluated several cycles before the branch
instruction. So the compiler is trying to arrange the code like that:
r0 = fu;
r1 = bar;
cc = r0 < r1 (iu); // Check condition
p0 = [sp++]; // Do something else
r2 = r1;
r1 = r1 + r0;
r0 = blablabla;
if cc jump label; // Branch predicted because the condition is known in
advance
This minimizes the stalls of the pipeline due to the mispredictions, so
there is little or no advantage if you give hints to the compiler.
Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com