Implementing expert knowledge to predict branch instructions in C # or C ++

I know that some CPUs try to predict branch instructions when deciding which code to pre-extract, I was wondering if there is a way to help or hard-code these branch predictions in C # (or C ++). An example is error checking if an operator that I know returns false 99.9999999% of the time, I would like to say that the CPU always expects the branch to never happen for prefetching purposes.

Thank.

+5
source share
1 answer

, . , # VM - , , .

C/++ , . . , gcc g++ , . gcc __builtin_expect, :

if (__builtin_expect(x == 0, 0)) { // Unlikely to occur
    /* ... */
}
+5

All Articles