[prev in list] [next in list] [prev in thread] [next in thread]
List: mingw-users
Subject: [Mingw-users] Optimizer produces suboptimal code for e.g. x = x ^
From: Jasper Neumann <jasper.neumann () web ! de>
Date: 2011-02-25 19:27:51
Message-ID: 4D6802B7.406 () web ! de
[Download RAW message or body]
Hello folks!
When I compile the following OPT.CPP with gcc 4.5.2...
===
int test(int x)
{
x = x ^ (x >> 1);
int x1=x;
x = x >> 2;
x = x ^ x1;
return x;
}
===
...a call to
gpp -O3 -S OPT.CPP
produces this OPT.s:
===
.file "OPT.CPP"
.text
.p2align 2,,3
.globl __Z4testi
.def __Z4testi; .scl 2; .type 32; .endef
__Z4testi:
LFB0:
pushl %ebp
LCFI0:
movl %esp, %ebp
LCFI1:
movl 8(%ebp), %eax
movl %eax, %edx
sarl %edx
xorl %eax, %edx
movl %edx, %eax
sarl $2, %eax
xorl %edx, %eax
leave
LCFI2:
ret
LFE0:
===
The problem I see is that in
movl %eax, %edx
sarl %edx
xorl %eax, %edx
movl %edx, %eax
sarl $2, %eax
xorl %edx, %eax
gcc produces code which presumably costs 6 cycles
(edx end then eax is modified 3 times in a row)
whereas the equivalent statements
movl %eax, %edx
sarl %eax
xorl %eax, %edx
movl %edx, %eax
sarl $2, %edx
xorl %edx, %eax
cost only 4 cycles since the mov and the shift can go in parallel.
I would have expected this at least for explicit form in
int x1=x;
x = x >> 2;
x = x ^ x1;
I found no way to get gcc to output my version.
Have I missed something?
By the way: If I produce an output in Intel syntax
the statement "sar eax" should be "sar eax,1".
Otherwise some assemblers will complain.
Jasper
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
MinGW-users mailing list
MinGW-users@lists.sourceforge.net
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same. Disregard for the list etiquette may \
cause your account to be moderated.
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@lists.sourceforge.net?subject=unsubscribe
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic