In article , snipped-for-privacy@green.rahul.net (Ken Smith) writes: |> |> Yes, there are lots of other examples, but I think the Booth's case is the |> simplest real case to see the problem with.
It does, however, give the impression that the problem applies only to very esoteric codes. It doesn't.
|> BTW: I disagree with the suggestion that jumps in OO programs are by |> there nature harder to predict. Virtual method dispatching is a hard type |> of branch to predict but in non-OO code, the virtual method call would be |> replaced with a long switch statement. In good compilers, long switches |> are implemented with jump tables. "goto table[i]" is very hard to |> predict.
Neither is hard to predict, if you do it right. Few, if any, modern systems do.
What is needed is a compiler-generated instruction that sets up a datum to be used for branch prediction, which is then quoted in the branch, and used by the hardware. The instruction history alone is useless for such codes, but the object address is (obviously) excellent. This has the advantage that information from a previous branch in the same function could be used.
For example, consider the following instructions:
Set predictor. It takes up to 2 registers, and sets one of a few (4-16) predictors based on their contents (in an unspecified fashion).
Predict branch. It takes a predictor and also specifies a preferred direction, a resulting direction or none. It must immediately precede a branch.
This would allow a compiler to take the following:
IF a > b THEN ... FI; . . . IF b < a THEN ... FI;
and issue:
Set_predictor 1 a b . . . Predict_branch 1 +1 [ indicating a resulting direction ] . . . Predict_branch 1 -2 [ indicating a preferred direction ]
I have little idea how effective this would be, but my gut feeling is that it would be better than correct approaches for such codes. As far as I know, I have rendered this unpatentable by posting :-)
Regards, Nick Maclaren.