In x86 assembly, is it better to use two separate registers for imul?

I'm curious, mainly out of curiosity, if using the same register for an operation is better than using two. What would be better considering the performance and / or other issues?

mov %rbx, %rcx
imul %rcx, %rcx

or

mov %rbx, %rcx
imul %rbx, %rcx

Any advice on how to evaluate this, or resources where I could read about it, would be appreciated since I'm new to the assembly.

+2
source share
2 answers

resources where I could read about this type

. Agar Fog microarch pdf . tag wiki ( , Intel).


, :

mov   %rbx, %rcx
imul  %rbx, %rbx     # doesn'y have to wait for mov to execute
# old value of %rbx is still available in %rcx

imul , mov (, AMD Intel IvyBridge), . imul , mov.

, , , - , , mov .

, , , , . , , , . , , asm .


Intel P6- (PPro/PII-Nehalem) , , . %rbx , , mov imul (RAT).

4, %rbx . Core2/Nehalem 3 , (, Agner Fog ), , ( 3 2 Core2 ).

. Agar Fog microarch pdf 8.8. Core2 PPro. PPro 3- , Agner , .


mov imul , %rbx. 3 4 , Core2/Nehalem.

, , ( ) Intel P6-. , AFAIK, .

mov   %rbx, %rcx
imul  %rcx, %rcx     # uses only the recently-written rcx; can't contribute to register-read stalls

:

mov   %rbx, %rcx
imul  %rbx, %rcx     # can't execute until after the mov, but still reads a potentially-old register

, .


Intel Sandybridge (, AMD Bulldozer) .

Ivybridge (2- Sandybridge), mov reg,reg , . , , imul rbx rcx .

, AMD Bulldozer xmm ; - 1 .

, mov , .


, , Core2 imul %rbx, %rcx, imul %rcx, %rcx. , , mov imul , , , - , . (, lea (%rsi, %rdi, 1), %eax add (%rsi, %rdi, 1), %eax ( , - core2/nehalem, 1 (It - SnB)).

+4

, . , , , , , ( , , , ). - , , , , .

, , , () .

+5

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


All Articles