I have a loop that is running over and over again. The logic inside that loop is dependent on the mode that the program is in. To improve performance I was thinking that an array of function pointers can be initialized, functionPtr[], so that would just call functionPtrmode that runs the right logic. The loop will stay in the same mode for many cycles (the number is unknown upfront but many thousands). The program runs on an intel x64 machine only and needs no portability.
I was hoping that the CPU would utilize branch prediction but since my branch isn't conditional (on the assembly level) but the location of the branch does depend on a variable, (functionPtr+mode). Will the CPU attempt to calculate functionPtr+mode and start pulling those instructions in while in the pipeline?
See Question&Answers more detail:os