From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: Strange loop with optimize Date: Mon, 04 Aug 1997 19:02:21 -0400 Organization: Cornell University http://www.cornell.edu Lines: 43 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <33E65F7D.4B22@cornell.edu> References: Reply-To: asu1 AT cornell DOT edu NNTP-Posting-Host: cu-dialup-0030.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Georg Kolling wrote: > /* VESA mode 640*480 already set, virtual width = 800 */ > ... > _farsetsel (LFBsel); /* sets fs */ > time = rawclock (); > for (co = 0; co < 100000000; co++) > ppix (); > time = rawclock () - time; > ... > > I can compile and run this program, i can move the pixel by moving the > mouse, i'm getting good performance (393 clockticks, about 4,6 mio. > pixel per second) on a Pentium 100...BUT... > if i compile with -O1, -O2 or -O3, the loop doesn't work! I can still > move the pixel, but the loop never gets to an end (i inserted a little > 'break' routine that stops when i press a mouse button; the result: co > (which is unsigned long) had always a value of about 400 (random), no > matter how many pixels it had actually put or how long the program was > already running) i am no expert on this so i may not be putting this exactly in the right terms. the optimizer probably realizes that you do not use the value of co in the loop, and possibly never in the function (can't tell.) hence it probably implements the loop in some other way (since it is supposed to execute a fixed number of times) eliminating the constant increment/test. did you look at the assembly output with optimization? did you actually wait for 100,000,000 iterations? at the end of the loop, co should contain the correct value 100,000,001 if the rest of the function refers to it. -- Sinan ******************************************************************* A. Sinan Unur WWWWWW |--O+O mailto:sinan DOT unur AT cornell DOT edu C ^ http://www.people.cornell.edu/pages/asu1/ \ ~/ Unsolicited e-mail is _not_ welcome, and will be billed for. *******************************************************************