Mail Archives: djgpp/1998/10/13/12:51:35
From: | igp AT vlc DOT servicom DOT es (Ignacio García Pérez)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | -O3 breaks my code: inline assembler & optimization
|
Date: | Tue, 13 Oct 1998 16:36:40 GMT
|
Organization: | GND
|
Lines: | 52
|
Message-ID: | <36237ef5.671209@crispin>
|
NNTP-Posting-Host: | rdsi29.vlc.servicom.es
|
Mime-Version: | 1.0
|
X-Newsreader: | Forte Agent 1.01/32.397
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hi,
I posted recently a help request about -O3 optimization (more
precisely -finline-functions) breaking my code.
I've traced down the problem to the following function:
//------------------------------
volatile dword Com::TimTicks=0;
dword Com::Ticks(void) {
dword TRef T;
asm ("pushf");
asm ("cli");
T=TimTicks;
asm ("popf");
return T;
}
//------------------------------
As you see, TimTicks is a volatile variable that is updated by a timer
interrupt function. The reason because of which the read of the
variable is enclosed between interrupt disable/enable is because
originally this code was 16 bit and then a DWORD read is split in
several instructions, which could potentially be interrupted in
between by a timer tick.
I KNOW that with DJGPP this is a single instruction and then
enabling/disabling is not needed. But what I want to discover is why
GCC is producing a code that produces a general protection fault when
this function is inlined.
These were the steps that lead me to this function:
1- Compiled with "-O2": works fine
2- Compiled with "-O3": crashes
3- Compiled with "-O2" and "-finline functions": crasesh
4- Compiled with "-O2" and defining Com::Ticks as "inline": crashes.
It seems obvious to me that somehow the compiler generates a bad jump
when inlining the function, which results in a stack misalignment due
to the push/pop pair.
If anyone wants to help in the investigation (as I said the problem is
easily solved, I just want to know WHY this happens), or has any
useful clues in tracing even downer the problem, please let me know (I
can submit the full code, because as the function is inlined, the bad
jump must happen somewhere else in the module where the function is
used).
Thanks. Nacho.
- Raw text -