Excessive optimization (was Re: what was VMS/OpenVMS written in?)
csquared3 at tx.rr.com
Fri Dec 3 00:03:33 CST 2010
On 12/2/2010 2:29 PM, Eric Smith wrote:
> Ethan Dicks wrote:
>> I have used the following in embedded code to tight-loop the CPU in
>> certain circumstances, intentionally requiring a reset of the
>> processor to escape...
>> for (;;)
>> I suppose a good optimizer would know that you really meant to do that
>> and should produce something resembling the following
>> $1: JMP $1
>> ...but I certainly wouldn't want that statement optimized out entirely.
> If the compiler optimized that out entirely, the compiler is defective.
> Optimizations are not supposed to change the semantics of well-formed code.
> On the other hand, the compiler is free to optimize
> int i;
> for (i = 0; i < 100; i++)
> int i;
> i = 100;
> Since that does not change the semantics.
I'm afraid I must disagree. What if, for my own nefarious purposes, I
need the N microseconds of delay achieved via the "spurious" for loop?
I know, code loop delays are generally a poor practice, but what does
one do if a delay is absolutely required before timer interrupts can be
enabled? What if there is no hardware timer (e.g. 8254) that can be
read periodically to time the delay? What if I am writing a quick
More information about the cctalk