seclan のほえほえルーム

| |

x86: 高速な abs 計算

・
2001/08/22 []

 整数の絶対値を取る abs という関数がありますが、x86 asm では次のような方法を考えた人がいます。

入力:eax, 出力:abs(eax)
movecx, eax
sareax, 31
xorecx, eax
subecx, eax

 P6 だとこんな方法が使えます。
入力:eax, 出力:abs(eax)
movecx, eax
negeax
cmovseax, ecx



by seclan

関連


| |

 

配信

9.54 msec