CUDA: Why are bitwise operators sometimes faster than logical operators?

前端 未结 3 1090
一向
一向 2021-01-11 17:46

When I am down to squeezing the last bit of performance out of a kernel, I usually find that replacing the logical operators (&& and

3条回答
  •  無奈伤痛
    2021-01-11 18:28

    Logical operators will often result in branches, particularly when the rules of short circuit evaluation need to be observed. For normal CPUs this can mean branch misprediction and for CUDA it can mean warp divergence. Bitwise operations do not require short circuit evaluation so the code flow is linear (i.e. branchless).

提交回复
热议问题