www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/04/05:23:57

Xref: news2.mv.net comp.os.msdos.djgpp:4548
From: myskin AT inp DOT nsk DOT su (Vyacheslav O. Myskin)
Newsgroups: comp.os.msdos.djgpp
Subject: Optimization question
Date: Tue, 04 Jun 1996 07:00:37 GMT
Organization: BINP RAS
Lines: 35
Distribution: world
Message-ID: <4p0mul$6ha@sky.inp.nsk.su>
Reply-To: myskin AT inp DOT nsk DOT su
NNTP-Posting-Host: csd-bsdi.inp.nsk.su
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi all!
Yesterday I compiled a program with -O2 -S:

volatile int interrupt_occured,counter;

int main()
{
...
while(!interrupt_occured) count++;
...
}
The count was started and stopped by two consecutive timer interrupts.
Here is the assembler source:

	movl	 _counter,%eax		;
	incl 	%eax			; Why not 'incl  _counter' ?
	movl 	%eax,_counter		;
	movl 	_counter,%eax		; And what is it for???
	movl	 _interrupt_occured,%eax
	testl 	%eax,%eax
	je ...

I wondered why does the compiler generate 4 instructions (including a
really sensless one) instead of single one. But the real fun began
when I found out that this 4-instruction code loops FASTER than
'incl _counter'(I get larger values of counter)! Is this nonsense? Am
I missing something? The only thing I can assume is that it is some
kind of sophisticated optimization for 486's conveyor(???)/cache or
whatever it is called. Please tell me what's going on! Excuse my
ignorance...

Best wishes,
V. Myskin


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019