Col*_*son 5 x86 assembly boolean-logic compilation
据我了解,在类似 C 的语言中,我可以不使用运算符执行布尔值not
:(C)
int myBool = TRUE;
myBool = !myBool;
Run Code Online (Sandbox Code Playgroud)
但我的问题是:这在幕后是如何实现的?我的猜测是使用跳转,但如果过度使用,这些可能会效率低下:(Intel x86 语法)
; assume eax holds boolean
test eax, eax
jnz short boolTrue
inc eax ; eax was 0, now 1
jmp short after
boolTrue: ; eax non-zero
xor eax, eax ; eax now 0
after:
Run Code Online (Sandbox Code Playgroud)
如图所示,它需要 5 条指令,其中至少有 1 个跳转和 1 个按位and
( test
)。必须有一种更简单的方法来做到这一点,因为我已经看到代码库if (!!fileHandle)
由于某些奇怪的原因而执行“双重不”()。
那么(如上所述):编译器如何!
在 x86 上执行 boolean 操作?
归档时间: |
|
查看次数: |
5423 次 |
最近记录: |