Don't ever call the Dynamic C compiler "optimizing". Here is an example:
longval = intval;
This gets compiled to:
ld hl,0x0000 add hl,sp push hl ; a pointer to longval ld hl,(sp+12) ; hl = intval ex de,hl ; de = intval ld a,d ; a = msb of intval rla ; Carry = sign of intval sbc hl,hl ; hl = sign extension of intval ld b,h ld c,l ; bc = sign extension of intval pop hl ; get that pointer to longval call slong_ ; store bc:de at (hl) with interrupts disabled
The reason they use the special 32-bit store function slong_ is that they want to make sure all such stores are atomic, so that an ISR won't find an inconsistent (partially set) value. But longval was an automatic variable allocated off the stack. There was no reason to go through so much trouble for a variable not declared as volatile. They could have simply done this:
ld hl,(sp+12) ; hl = intval ld (sp),hl ; lsb of longval is set rl h ; Carry = sign of intval sbc hl,hl ; hl = sign extension of intval ld (sp+2),hl ; msb of longval is set
I have other examples of simple local optimizations that were missed, such as failing to recognize that bit shifts of 8 and 16 bits can be accomplished by simply moving registers. Even a "non-optimizing" compiler should be expected to do these things right.
-Robert Scott Ypsilanti, Michigan (Reply through newsgroups, not by direct e-mail, as automatic reply address is fake.)