Branch Prediction?

Erik Österlund erik.osterlund at lnu.se
Sat Nov 8 09:43:32 UTC 2014


Hi,

Just out of curiosity, is there some good reason why we don't have a branch prediction macro?
For every tight load a; cmpxchg(expect: a, addr: &x, new_val: b); loop, I feel a bit uneasy not telling the compiler that this is pretty likely to succeed, and relying on its guessing.

Has it been excluded because it's considered not nice or perhaps it was simply never introduced because nobody found it useful?

Could have some define like this for GCC, which for other compilers reduces to nothing:

#define VM_EXPECT_TRUE(A) __builtin_expect((A), true)
#define VM_EXPECT_FALSE(A) __builtin_expect((A), false)

It might not lead to drastic performance improvements, but it feels weird not to tell the compiler what we know and keep secrets from it. And I think it's also nice for documentation purposes that people reading it also understand that this expression is gonna be true most of the time, and deal with it accordingly.

/Erik


More information about the hotspot-dev mailing list