ANSII C, optimization, and "hardware registers"
PAD Powell
padpowell at wateng.UUCP
Fri Oct 12 23:09:22 AEST 1984
I have just run into a really fun thing with an optimizer. The problem
was in the code for a hardware level driver, which wanted to:
1. Stuff a value into a register.
2. Look at the register until a flag (bit) went high.
The code written was
struct regs{
int r1;
} *csr;
...
csr->r1 = ST_START;
while( (csr->r1 & ST_DONE) == 0 );
Well, imagine my surprise when the code generated only did:
1. loaded the ST_START value into CPU register (byte value actually)
2. placed the CPU register value into memory (word value)
3. Did not generate a test instruction, cause the ST_START and
ST_DONE value were identical.
Now here is the question:
1. Was this legal code generation?
2. Note that this compiler did "simple" optimizations as part of the code
generation. Is this legal?
I know of several ways around this, but I thought that it should be addressed
by the ANSII standard.
Patrick Powell
More information about the Comp.lang.c
mailing list