Branch on ?: operator?

后端 未结 5 1044
Happy的楠姐
Happy的楠姐 2021-01-17 23:45

For a typical modern compiler on modern hardware, will the ? : operator result in a branch that affects the instruction pipeline?

In other words which i

5条回答
  •  醉话见心
    2021-01-18 00:26

    I can't imagine the first method would ever be faster.

    With the first method you may avoid a branch, but you replace it with a function call, which would usually involve a branch plus a lot more (unless it was inlined). Even if inlined, unless the functionality inside the purge() function was absolutely trivial it would almost certainly be slower.

提交回复
热议问题