Comments on abs
Original Reporter info from Mantis: Jasper
-
Reporter name: Jasper Neumann
Original Reporter info from Mantis: Jasper
- Reporter name: Jasper Neumann
Description:
When running e.g. ppcrossx64.exe -O2, I can see code like this:
mov edx,eax
neg edx
cmovns eax,edx
This is almost optimal but cmov surely is not the fastest command and as far as I know cmov cannot always be assumed available. How comes that cmov is used?
I've seen even this:
mov rax,rdx
cmp rax,0
jnl @@less
mov rax,rdx
neg rax
jmp @@next
@@less:
mov rax,rdx
@@next:
Optimal (as used in win32) should be this (only useful for *ax and *dx):
cdq
xor eax,edx
sub eax,edx
or this (any 2 registers):
mov edx,eax
sar edx,31
xor eax,edx
sub eax,edx
or the analogous 64-bit-replacements.
Mantis conversion info:
- Mantis ID: 17275
- Build: 15908
- Platform: x86_64
- Version: 2.5.1