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

Extra (useless) instructions involving r7 and accumulator

Why would the following line in C:

XRAM00 |= 0x01;

compile into this:

mov dptr, #XRAM00
movx a, @dptr
mov r7, a
mov a, r7
orl a, #1
mov r7, a
mov dptr, #XRAM00
mov a, r7
movx @dptr, a

I would have expected this:

mov dptr, #XRAM00
movx a, @dptr
orl a, #1
movx @dptr, a

Parents
  • And it turns out it's a lot easier to generate code that's correct, if inefficient, and then optimize away inefficiency than it is to try to write a code generator that is smarter in the first place. It's a form of modularity; the code generator is responsible for semantics, the optimizer for getting rid of the silliness that occurs when you don't pay global attention to that sort of thing

    as to my post above and this

    that "it's a lot easier ..." does not, in any way, hinder that what I described could be done by the compiler, maybe do compile - do optimize, instead of "compile to optimal", but that would not make any difference to the user.

    Then, of course an optimizer would be needed to optimize after linking (e.g. combine identical execution strings in different modules for those that do not care about debugging).

    Erik

Reply
  • And it turns out it's a lot easier to generate code that's correct, if inefficient, and then optimize away inefficiency than it is to try to write a code generator that is smarter in the first place. It's a form of modularity; the code generator is responsible for semantics, the optimizer for getting rid of the silliness that occurs when you don't pay global attention to that sort of thing

    as to my post above and this

    that "it's a lot easier ..." does not, in any way, hinder that what I described could be done by the compiler, maybe do compile - do optimize, instead of "compile to optimal", but that would not make any difference to the user.

    Then, of course an optimizer would be needed to optimize after linking (e.g. combine identical execution strings in different modules for those that do not care about debugging).

    Erik

Children
No data