Article View: gnu.gcc.help
Article #971Bad GCC code generation on Intel
From: Przemek Klosowski
Date: Wed, 30 Apr 1997 00:00
Date: Wed, 30 Apr 1997 00:00
50 lines
2041 bytes
2041 bytes
The following code accesses an exotic Pentium instruction (reads high-resolution timer
into EAX:EDX register pair):
#include <stdio.h>
main()
{
long long t1,t2;
__asm__ __volatile__("rdtsc":"=a" (((unsigned long*)&t1)[0]),"=d" (((unsigned long*)&t1)[1]));
__asm__ __volatile__("rdtsc":"=a" (((unsigned long*)&t2)[0]),"=d" (((unsigned long*)&t2)[1]));
printf("%Ld\n",t2-t1);
}
Even at -O6 it generates rather redundant code. I don't know if it could have avoided storing
data into stack local vars, but the storing and reloading of registers seems very excessive.
Is there another form of __asm__ that I should have used?
main:
pushl %ebp
movl %esp,%ebp
subl $24,%esp
#APP
rdtsc
#NO_APP
movl %eax,-8(%ebp)
movl %edx,-4(%ebp)
#APP
rdtsc
#NO_APP
movl %eax,-16(%ebp) <<<<<
movl %edx,-12(%ebp) <<<<<
movl -16(%ebp),%eax <<<<<
movl -12(%ebp),%edx <<<<<
subl -8(%ebp),%eax
sbbl -4(%ebp),%edx
movl %eax,-24(%ebp)
movl %edx,-20(%ebp)
pushl -20(%ebp)
pushl -24(%ebp)
pushl $.LC0
call printf
leave
--
przemek klosowski <przemek@nist.gov> (301) 975-6249
NIST Center for Neutron Research (bldg. 235), E111
National Institute of Standards and Technology
Gaithersburg, MD 20899, USA
Technical Details
Message-ID:
<54vi54ji53.fsf@rrdjazz.nist.gov>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,935482569d2457a9,start X-Google-Attributes: gid11318c,public X-Google-Thread: f5392,935482569d2457a9,start X-Google-Attributes: gidf5392,public X-Google-Thread: 11663c,935482569d2457a9,start X-Google-Attributes: gid11663c,public From: Przemek Klosowski <przemek@rrdjazz.nist.gov> Subject: Bad GCC code generation on Intel Date: 1997/04/30 Message-ID: <54vi54ji53.fsf@rrdjazz.nist.gov> X-Deja-AN: 238579342 Organization: U. of Maryland/NIST Newsgroups: gnu.gcc.help,comp.os.linux.development.system,dc.org.linux-users