This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bad optimization with Rn=0;

#include <AT892051.H>
#pragma OPTIMIZE (9, SPEED)

void main (void)
{ unsigned char R;
        R=0;  // this statement always produces ASM-code:
          // CLR  A
          // MOV  R7,A
          // ...!!!!.... why not MOV R7,#0   (2 bytes 1 cycle instead of 2 bytes and 2 cycles)
          //  but, if R=5;   is produced code: MOV  R7,#05H  ;;;;;;;  :o)
//....
   if(P1==0x55) R++;
//...
//...
}

Parents
  • "... things that should be done [...] by the compiler [...] are done by the optimizer"

    I have the same feeling. Another simple example: downcounting loops are not collapsed into DJNZ unless you turn optimizations ON.

    Several of the low-level generic functions on my libraries are implemented directly in assembly and prototyped to be called from C, to avoid the compiler lazy translation overhead.

Reply
  • "... things that should be done [...] by the compiler [...] are done by the optimizer"

    I have the same feeling. Another simple example: downcounting loops are not collapsed into DJNZ unless you turn optimizations ON.

    Several of the low-level generic functions on my libraries are implemented directly in assembly and prototyped to be called from C, to avoid the compiler lazy translation overhead.

Children