MatlabMonkey@googlemail.com wrote:
> Help - are we running low on registers in the following code snippet?
> Is it generally better to choose MOVL over XCHG?
> If XCHG is faster, how would one rearrange the C code to get XCHG in
> the ASM code?
> Many thanks in advance.
>
>
>
> // --------------------- Incomplete code snippet
> ---------------------
> // Logiciels/Informatique lcc-win32 version 3.8. (Dec 18 2007
> 19:12:54)
> // Compile options -v -S -p6 -O
>
> 125 IntSwapBuf = *IntPtrL;
> 126 *IntPtrL = *IntPtrR;
> 127 *IntPtrR = IntSwapBuf
>
> .line 125
> movl -8(%ebp),%eax
> movl (,%eax),%ecx
> movl %ecx,-20(%ebp)
You tell it to assign *IntPtrL to IntSwapBuf.
It does EXACTLY that.
> .line 126
> movl -16(%ebp),%edx
> movl (,%edx),%edx
> movl %edx,(,%eax)
You tell it to assign *IntPtrR to *IntPtrL. It does
exactly that.
> .line 127
> movl -16(%ebp),%eax
> movl %ecx,(,%eax)
And then, you tell it to assign *IntSwapBuf to *IntPtrR.
It does that.
Now here is what MSVC with the HIGHEST level of optimization
generates (in 64 bit assembly)
; File d:\temp\tswap.c
; Line 6
mov rdx, QWORD PTR IntPtrL
mov eax, DWORD PTR [rdx]
mov DWORD PTR IntSwapBuf, eax
; Line 7
mov rax, QWORD PTR IntPtrR
mov ecx, DWORD PTR [rax]
mov DWORD PTR [rdx], ecx
; Line 8
mov rax, QWORD PTR IntPtrR
mov ecx, DWORD PTR IntSwapBuf
mov DWORD PTR [rax], ecx
You see?
The same code. Compilers aren't psychic to the point of realizing
that you want to swap the values
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
|