www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/20/08:30:55

Message-ID: <3604F82B.68D16BCF@mailexcite.com>
Date: Sun, 20 Sep 1998 08:42:19 -0400
From: Doug Gale <dgale AT mailexcite DOT com>
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Optimizations
References: <Pine DOT SUN DOT 3 DOT 91 DOT 980920103551 DOT 406H-100000 AT is>
NNTP-Posting-Host: oshawappp15.idirect.com
Organization: "Usenet User"
Lines: 44
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


Eli Zaretskii wrote:

> On Fri, 18 Sep 1998, John S. Fine wrote:
>
> >   What happened?  I really did have the "-O2".  I can make tiny
> > changes in the above code and suddenly get decent output.  What
> > about the above code makes the optimizer go insane?
>
> I don't know, it's pretty tricky.  Unless you really need to understand
> how the optimizer works, you should be fine just rearranging the source so
> it emits a better code.
>
> One thing that sometimes helps in C is to explicitly tell the compiler
> that the functions called inside the loop have no side effects, by
> declaring it with __attribute__((const)).  This is described in GCC docs,
> and sometimes has a dramatic effect on code generated for loops that call
> functions.

I have also noticed a bit of strange assembler. Here is an exerpt:

   int nFront, nBack, nOnPlane;

   nFront = 0;
   nBack = 0;
   nOnPlane = 0;

the compiler generates this (strange) code:

movl $0,nFront
movl nFront,%ebx
movl %ebx,nBack
movl %ebx,nOnPlane

Why read a constant from memory after storing it? I expected something like
this:

xorl %ebx,%ebx
movl %ebx,nFront
movl %ebx,nBack
movl %ebx,nOnPlane


- Raw text -


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