Branch on ?: operator?

后端 未结 5 1036
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:20

    Depends on the platform. Specifically, it depends on the size of jump prediction table of the CPU and whether the CPU allows conditional operations (like on ARM).

    CPUs with conditional operations will strongly favor the second case. CPUs with bigger jump prediction tables will favor the first case.

    The real answer (like with any other performance questions): measure and compare. Sometimes the rest of the code throws a curve ball and it's usually impossible to predict effects of some changes.

提交回复
热议问题