0

The use of builtin_expect_with_probability gcc function is for condition check with probability like in below example __builtin_expect_with_probability(!!(x),1,1.0)

can someone tell me what is the purpose of "!!" in above function?

Naval
  • 1
  • It booleanizes, so it's telling the compiler to expect that `x != 0` is true. Without `!!`, it would be telling the compiler to expect that `x` has integer value `1` exactly, and to optimize for that special case. Note that this is not specific to the `_with_probability` version of `__builtin_expect`. – Peter Cordes Aug 16 '23 at 16:06
  • Semi-related: [How far does GCC's \_\_builtin\_expect go?](https://stackoverflow.com/q/15468042) demos use of expectations other than `0` or `1`. [What does this construct mean "\_\_builtin\_expect(!!(x), 1)"](https://stackoverflow.com/q/24999408) is basically a duplicate. (I expanded its answer with an explanation.) – Peter Cordes Aug 16 '23 at 16:16

0 Answers0