Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ncar!stout!thor From: thor@stout.ucar.edu (Rich Neitzel) Newsgroups: comp.lang.c Subject: Re: C optimizer Keywords: C Ultrix Message-ID: <1420@ncar.ucar.edu> Date: 15 Feb 89 20:46:41 GMT References: <515@larry.UUCP> <3684@arcturus> Sender: news@ncar.ucar.edu Reply-To: thor@thor.UCAR.EDU (Rich Neitzel) Organization: Field Observing Facility, NCAR, Boulder, CO Lines: 55 In article <3684@arcturus> evil@arcturus.UUCP (Wade Guthrie) writes: >While we're talking about optimizers (and, since all the furor about >optimizing one's code has died down :->), what do most optimizers on >most C compilers do? Where is TFM that I should be 'R'ing (and in which >FM should I look?)... > >What else should I expect? From what compilers? On what machines? >In short, what should I do myself and what should I let the *general* >optimizer/compiler do? > In addition, should one let the compiler do optimization? This may not be important in most cases, but for others it can destroy the functioning of the code. For example, many external devices have control/status registers that are cleared only when read. An optimizer might see code: junk = *csr; and since junk is never used again, remove that line. Or how about this: while (i < length) { while (!(*csr & 0x80)); *storage++ = *data_reg; } This loop polls on a done bit and then reads the new data in the data register. An optimizer might decide that since data_reg does not SEEM to change, the value it points to can be put into a register and copied from there on each pass. Optimizing is an uncertain tool unless one knows what the optimizer is doing. Since RISC cpus use heavily optimizing compilers and have assemblers that are nearly impossible to follow, how does one make certain that the optimizer hasn't shafted you? (On my 68020 I can peek at the assembler output.) Even on CISC machines, perhaps compiler vendors should supply a OPT_ON and OPT_OFF set of directives. ------------------------------------------------------------------------------- Richard Neitzel National Center For Atmospheric Research Box 3000 Boulder, CO 80307-3000 303-497-2057 thor@thor.ucar.edu Torren med sitt skjegg Thor with the beard lokkar borni under sole-vegg calls the children to the sunny wall Gjo'i med sitt shinn Gjo with the pelts jagar borni inn. chases the children in. -------------------------------------------------------------------------------