none
branch hints

    Question

  • Hello,

    In gcc I can send the compiler a hint about the expected flow of a branch

    #define NOT_LIKELY(expr)    __builtin_expect((expr),(1==0))
    #define LIKELY(expr)        __builtin_expect((expr),(1==1))

    I know the intel compilers do this, too. Is there a way to do this with the Visual Studio 2005 compiler?
    Thanks.
    Tuesday, March 28, 2006 6:50 PM

Answers

  • Hi!

    No, there is no hints like you mentioned in VC++.

    Still, if I remember correct, Intel CPU always thinks that "then" section will be executed first and try to preexecute it. I think compilers with branch hints simply reverse then-else sections depending on hint while emitting code. So, if you want to help CPU a little - put most probable code in "then" section.

    Tuesday, March 28, 2006 7:05 PM
  • This could be note related at all, but have you looked at the perf gains you might get by using the Profile Guided Optimizations. It optimizes based on user scenarios and hence could do the branch prediction for you.

    Thanks,
    Ayman Shoukry
    VC++ Team
    Tuesday, March 28, 2006 7:28 PM

All replies

  • Hi!

    No, there is no hints like you mentioned in VC++.

    Still, if I remember correct, Intel CPU always thinks that "then" section will be executed first and try to preexecute it. I think compilers with branch hints simply reverse then-else sections depending on hint while emitting code. So, if you want to help CPU a little - put most probable code in "then" section.

    Tuesday, March 28, 2006 7:05 PM
  • Thanks for the prompt reply.

    That's too bad... hints can make a difference in insanely deep pipelines like the p4. As far as I understood, the higher-end Intel processors include a set of small 2bit finite state automata meant for the branch prediction which is supposed to yield a *much* better performance than just assuming a branch taken/branch not taken approach.

    Do you know if there are any plans to support this on future VC compilers
    ?

    Thanks again.
    Tuesday, March 28, 2006 7:15 PM
  • This could be note related at all, but have you looked at the perf gains you might get by using the Profile Guided Optimizations. It optimizes based on user scenarios and hence could do the branch prediction for you.

    Thanks,
    Ayman Shoukry
    VC++ Team
    Tuesday, March 28, 2006 7:28 PM
  • I was just looking at that right now. I think that may be very useful to me. Thanks!
    Tuesday, March 28, 2006 7:45 PM