Top "Branch-prediction" questions

In computer architecture, a branch predictor is a digital circuit that tries to guess which way a branch (e.g. an if-then-else structure) will go before this is known for sure.

Why is processing a sorted array faster than processing an unsorted array?

Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data …

java c++ performance optimization branch-prediction
Is "IF" expensive?

I can't, for the life of me, remember what exactly our teacher said that day and I'm hoping you would …

if-statement language-agnostic branch-prediction
What does `rep ret` mean?

I was testing some code on Visual Studio 2008 and noticed security_cookie. I can understand the point of it, but …

assembly x86 micro-optimization branch-prediction
Is there a compiler hint for GCC to force branch prediction to always go a certain way?

For the Intel architectures, is there a way to instruct the GCC compiler to generate code that always forces branch …

c++ gcc intel pragma branch-prediction
Why is (a*b != 0) faster than (a != 0 && b != 0) in Java?

I'm writing some code in Java where, at some point, the flow of the program is determined by whether two …

java performance processing-efficiency microbenchmark branch-prediction
Why is a conditional move not vulnerable for Branch Prediction Failure?

After reading this post (answer on StackOverflow) (at the optimization section), I was wondering why conditional moves are not vulnerable …

performance assembly optimization cpu-architecture branch-prediction
What is the effect of ordering if...else if statements by probability?

Specifically, if I have a series of if...else if statements, and I somehow know beforehand the relative probability that …

c++ performance if-statement optimization branch-prediction
How can I make branchless code?

Related to this answer: https://stackoverflow.com/a/11227902/4714970 In the above answer, it's mentioned how you can avoid branch prediction …

java performance branch-prediction
Portable branch prediction hints

Is there any portable way of doing branch prediction hints? Consider the following example: if (unlikely_condition) { /* ..A.. */ } else { /* ..B.. */ } …

c++ c optimization c++20 branch-prediction
Why is processing an unsorted array the same speed as processing a sorted array with modern x86-64 clang?

I discovered this popular ~9-year-old SO question and decided to double-check its outcomes. So, I have AMD Ryzen 9 5950X, clang++ 10 …

c++ performance clang cpu-architecture branch-prediction