Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site wateng.UUCP Path: utzoo!watmath!wateng!padpowell From: padpowell@wateng.UUCP (PAD Powell) Newsgroups: net.lang.c Subject: ANSII C, optimization, and "hardware registers" Message-ID: <1538@wateng.UUCP> Date: Fri, 12-Oct-84 09:09:22 EDT Article-I.D.: wateng.1538 Posted: Fri Oct 12 09:09:22 1984 Date-Received: Sat, 13-Oct-84 05:15:15 EDT Organization: U of Waterloo, Ontario Lines: 28 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