www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/06/12:50:54

Xref: news2.mv.net comp.os.msdos.djgpp:4673
From: korpela AT islay DOT ssl DOT berkeley DOT edu (Eric J. Korpela)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Optimization question
Date: 4 Jun 1996 23:52:55 GMT
Organization: Cal Berkeley-- Space Sciences Lab
Lines: 41
Message-ID: <4p2i8n$ck6@agate.berkeley.edu>
References: <4p0mul$6ha AT sky DOT inp DOT nsk DOT su>
NNTP-Posting-Host: islay.ssl.berkeley.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <4p0mul$6ha AT sky DOT inp DOT nsk DOT su>,
Vyacheslav O. Myskin <myskin AT inp DOT nsk DOT su> wrote:
>while(!interrupt_occured) counter++;

>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		;

In intel 486 and pentium, the simple instructions like the above are
able to execute quickly, perhaps in one cycle each, without stalling
the instruction pipeline.  "incl _counter" is a compilcated instruction,
it's got to do three things (load a virtual register from memory, increment
it, and store the result.) while these things are going on no other
instructions can be decoded and the pipeline stalls.  "incl _counter"
probably takes at least 4 cycles to execute.

>	movl 	_counter,%eax		; And what is it for???

This looks to me like you compiled "while(!interrupt_occured) ++counter;"
instead of the above.  I'm guessing that because counter is declared
volatile, the return value of ++counter cannot be optimized away.  In
gcc values are returned in the %eax register.  I'm guessing that you
really didn't need to declare counter as volatile.  If you don't, I'd
guess this instruction will go away.

>	movl	 _interrupt_occured,%eax
>	testl 	%eax,%eax
>	je ...

Eric



-- 
Eric Korpela                        |  An object at rest can never be
korpela AT ssl DOT berkeley DOT edu            |  stopped.
<a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
Click here for more info.</a>

- Raw text -


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