Compiler level branch prediction

I read about branch prediction, but the only implementation that I find is mainly related to the hardware of the computer. processors seem to take care of most of the forecast. My question is, can the compiler do branch prediction? The only thing I found was 2 methods, an inline function and a loop reversal. Is this considered correct? Are they still in use?

+3
source share
1 answer

Of course. The compiler can get predictive information if it knows:

  • Statistical branch probabilities collected using instrumentation
  • , - ; , ,
  • -
  • ( "10", :)
  • , ( ""

​​, , , "" .

, , , . , , .

, . OO ( JITted) , . , . , / ( ) , . , .

: , ! :

  if (exp1 relop exp2)
      X = Y
  endif

"" , "MOV_if_relop A to B", , , .. , , :

  <compute exp1 and exp2>
  CMP  exp1,exp2 ; sets condition code
  MOVif_relop  X,Y
+7

All Articles