Confusion about bsr and lzcnt

前端 未结 2 1132
执笔经年
执笔经年 2021-02-20 04:40

I\'m a bit confused about both instructions. First let\'s discard the special case when the scanned value is 0 and the undefined/bsr or bitsize/lzcnt result - this difference is

2条回答
  •  长发绾君心
    2021-02-20 05:32

    LZCNT gives the number of leading zero bits. BSR gives the bit index of the most significant 1 bit. So they do effectively the same thing for the non-zero case, except the result is interpreted differently. Therefore you can just subtract the BSR result from 31 to get the same behaviour as with LZCNT, i.e. LZCNT == (31 - BSR).

提交回复
热议问题