assembly - 取消设置 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 和更新版本实现。
推荐阅读
- python - 如何在帖子中进行搜索(在 django 中)
- python - 为字典列表创建过滤函数的方法
- ruby-on-rails - 主延迟作业完成后调用钩子
- python - 由类方法处理的 Cython 中的单例
- java - Minium 使用胶水和浏览器抛出错误
- azure-devops - 如何从 git repo 中引用 tfvc 在 Visual Studio Online 中触发构建
- javascript - 如何在 vanilla JS 中将参数放到 setAttribute 函数上
- docker - Nginx Plus 无法使用 Docker 嵌入式 DNS 服务器解析服务
- javascript - HTML 实体到 Unicode 转义序列
- generics - 无法将特征边界添加到结构的成员