Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers LCC > Re: lccwin32 ge...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 1017 of 1070
Post > Topic >>

Re: lccwin32 generates MOVs instead of XCHG when swapping a pair

by jacob navia <jacob@[EMAIL PROTECTED] > Jan 16, 2008 at 07:55 PM

MatlabMonkey@[EMAIL PROTECTED]
 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
 




 2 Posts in Topic:
lccwin32 generates MOVs instead of XCHG when swapping a pair of
MatlabMonkey@[EMAIL PROTE  2008-01-16 09:37:06 
Re: lccwin32 generates MOVs instead of XCHG when swapping a pair
jacob navia <jacob@[EM  2008-01-16 19:55:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 23:24:33 CDT 2008.