gpt4 book ai didi

assembly - 使用 bsf、blf 查找第一位、最后一位汇编

转载 作者:行者123 更新时间:2023-12-03 06:40:58 24 4
gpt4 key购买 nike

我正在查看这段代码:

http://lxr.free-electrons.com/source/arch/x86/include/asm/bitops.h

静态内联无符号长__ffs(无符号长字)
{
asm("代表; bsf %1,%0"
:“=r”(字)
:“rm”(字));
返回单词;
}

为什么bsf指令前面有一个“rep”?为什么 __fls 的情况并非如此?

最佳答案

这是一种将 bfs 在支持它的处理器上转换为 tzcnt 的技巧。不过,它肯定需要在代码中添加注释。引用指令集引用:

0F BC /r BSF r32, r/m32

F3 0F BC /r TZCNT r32, r/m32

TZCNT counts the number of trailing least significant zero bits in source operand (second operand) and returns the result in destination operand (first operand). TZCNT is an extension of the BSF instruction. The key difference between TZCNT and BSF instruction is that TZCNT provides operand size as output when source operand is zero while in the case of BSF instruction, if source operand is zero, the content of destination operand are undefined. On processors that do not support TZCNT, the instruction byte encoding is executed as BSF.

(REP 前缀当然是 F3。)

关于assembly - 使用 bsf、blf 查找第一位、最后一位汇编,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33175375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com