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

Unsetting the lowest set bit in 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 在 Intel 端(不包括 Atom)由 Haswell 和更新版本实现,在 AMD 端由 Jaguar&Piledriver 和更新版本实现。