取消设置asm中的最低设置位



下面是我提出的函数,用于取消设置数字中最低的1位。

unset_lowest_bit:
# NUM & (NUM-1)
# All binary digits to the left of the first 1 will remain unchanged, so & itself=itself
# Any zeros to the right of the first 1 will stay zero, since anything & 0 = 0
# And finally, the first 1 will go to zero, since the -1 will eventually need to borrow
# Up to the first 1 digit
lea -1(%rdi), %rax
and %rdi, %rax
ret

除了不使用函数调用之外,这是一个取消设置最低位的好实现吗?或者有没有这样的指令(这似乎是一件非常不标准的事情,所以找不到任何指令(。

有一条指令,但它不在基本指令集中,它在BMI1:blsr

BMI1由Haswell和Intel方面的更新版本(不包括Atom(实现;Piledriver和AMD方面的更新产品。

最新更新