From: luke AT jet DOT msk DOT su (Oleg Yu. Polyanski) Newsgroups: comp.os.msdos.djgpp Subject: Re: Compiling with optimizations... Date: 27 May 1998 16:35:46 +0400 Organization: Jet Infosystems Lines: 37 Message-ID: References: <356c0953 DOT 171134608 AT 1 DOT 0 DOT 0 DOT 2> NNTP-Posting-Host: goliath.service.jet.msk.su Mime-Version: 1.0 (generated by tm-edit 7.108) Content-Type: text/plain; charset=US-ASCII To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk >>>>> "J" == J Schaerer writes: J> I would like to know (specifically) how to optimize a compile for J> the following criteria: 1) Speed 2) Size first of all, gcc has no special options for speed or for size optimization. in common cases it is enough to add `-O2 -fomit-frame-pointer -m486' (*) and in computation extensive code also add `-fstrength-reduce' to your command line. you may say -O3 and some of your simple functions will be "inlined" (even in C). btw, `-O3' option has nothing with pentium optimizations). if you want to get the binaries especially optimized for p5 or p6 add `-mpentium'/`-m586' or `-mpentiumpro'/`-m686' respectively. also, gcc 2.8.x optimizes for p6 in much higher degree than for p5 so you may want to try pgcc (pentium gcc), it has special pentium oriented optimization facilities. but in general, the options marked with (*) would be enough for all your code. i would like to recommend some general rules: select the optimization degree (-O2 or -O3); add cpu type qualifier (-m386/-m486/-m586/-m686) - it will tune optimizer in an architecture specific way; it is useful to say `-fomit-frame-pointer' due to on intel cpus we have very small number of general use registers and extra one will help to us great; trust in optimizer and do not add extra options (data aligning options may be one good exception in my opinion). p.s. there are, of course, other extra options to tune the optimizer more precisely: aligning data in memory (significantly speeds up access to data stored in memory), you may want to pass parameters to functions in the registers instead of stack (it is not easy though). it depends on how good quality optimization you *really* need and how good you understand code generation technique. p.p.s. also remember: bigger code does not mean slow execution speed. p.p.p.s. type `info gcc invo opti' and also `info gcc invo submodel i386' for other details. /Oleg