Mail Archives: djgpp/2001/12/06/10:49:03
X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f
|
From: | "Marp" <marp AT 0 DOT 0 DOT 0 DOT 0>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Is it a gcc bug?
|
Date: | Thu, 6 Dec 2001 10:34:12 -0500
|
Organization: | MindSpring Enterprises
|
Lines: | 39
|
Message-ID: | <9uo3dc$i1i$1@nntp9.atl.mindspring.net>
|
NNTP-Posting-Host: | 3f.b2.e0.95
|
X-Server-Date: | 6 Dec 2001 15:38:20 GMT
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.50.4807.1700
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4807.1700
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
I think I might have run into an optimizer bug in GCC 3.0.2, but I need some
insight. I have the version dated Nov 21, 2001 on the ftp server.
Consider the following program:
#include <stdio.h>
#include <dos.h>
int main(void) {
union {
unsigned long long full;
struct {
unsigned long lo, hi;
} half;
} before, after;
asm("rdtsc" : "=a" (before.half.lo), "=d" (before.half.hi));
delay(1000); // pause for 1 second
asm("rdtsc" : "=a" (after.half.lo), "=d" (after.half.hi));
printf("CPU Speed: %llu MHz\n", (after.full - before.full) / 1000000llu);
return 0;
}
If I compile with no optimization (gcc foo.c -o foo.exe -s) the program
outputs the correct result (400). However, if I turn on the optimizer (gcc
foo.c -o foo.exe -s -O1) the program outputs an incorrect result (0). When I
inspect the assembly output of the compiler, the one difference that caught
my attention is that the second asm statement appears to be missing when the
optimizer is turned on. Now I'm not exactly an expert with assembly, but I
don't see how a correct result could be computed without that second asm
statement.
So can someone explain to me what is wrong? Is it a gcc bug, or my mistake?
Thanks in advance.
- Raw text -