In my code there's a regular: if a if
statement is true, it will keep true for a while, and if it changes to false, it will keep false for a while. Since the performance in this code matters, I want to make the branch predict more efficient.
Currently what I tried is to write two versions of this if
statement, one is optimized with "likely" and the other is optimized with "unlikely" and use a function pointer to save which one to use, but since function pointer breaks the pipeline either, the benchmark seems no different with normal if
statement. So I'm curious if there's any tech to let CPU "remember" the last choice of this if
statement?
Or, do I really need to care about this?