"cqo", "cdq" and "cwd" x86_64. Why not use only cqo?

I'm not the most experienced build programmer, and I came across the instructions "cqo", "cdq" and "cwd", which are all valid for building x86_64.

I was wondering if there are advantages to using cdq or cwd when working with lower values. Is there a difference in performance?

EDIT: Initially, I began to study this when calculating the absolute value for single-digit numbers.

For example, if we have a value of -9 in al:

cwd
xor al,dl
sub al,dl

vs. Having it as a 32-bit value and computing

cdq
xor eax,edx
sub eax,edx

or if we have a 64-bit value for -9

cqo
xor rax,rdx
sub rax,rdx

If the original value is 64 bits and consists of a value from -9 to 9, then they all look the same.

+4
1

, , 16 rax.

16- int , 16 eax , 16- . cdq edx eax, .

, 32- 32- int eax, , .

, cdq. cqo, 64 , rdx.


. http://agner.org/optimize/, asm, x86. 32- 64- , 16 64- . , I-cache ( Sandybridge, SnB uop , .)

16 , rax. , AMD64 , , 32 32 GP reg. (x86 CPU OOO, AMD64 , , ax eax).

+4

Source: https://habr.com/ru/post/1616617/


All Articles