Q_UNLIKELY and compiler optimization
-
Hello,
If I put a function call insideQ_UNLIKELY
can I be sure that it won't be optimized out? Am I gaining the cache branching reduction one'd expect this way, or it's better to use a variable? E.g.if (Q_UNLIKELY(myfunction() != SUCCESS)) ; // Do stuff
or should I use:
register int result = myfunction(); if (Q_UNLIKELY(result != SUCCESS)) ; // Do stuff
Kind regards.
-
Hi,
What is the value of success ? Depending on it you can use
Q_LIKELY
but in any case AFAIK, it won't be optimized out. -
@SGaist
Success
is equal to zero. I'm not expectingMPI_Iprobe
(the function in question) to ever return an error, unless something is very wrong with a node. However the constant is external to my application and while it's value probably won't change I can't be certain of it. -
That's the kind of constant that shouldn't change. Usually success = 0 and anything else (usually below 0) is an error code. Sometimes a positive number can be an information like the size of something.
I'd go for the first version of your if in case you have doubts that SUCCESS might change