Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-10820

Certain shift operations cause the compiler to generate redundant MOV instructions

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: Low Low

      The attached file.c includes these lines ...

      uint8_t shift_right_toU8(uint16_t val)
      {
          return val >> 8U;
      }
      

      It has 3 more functions that are similar. Build it ...

      % cl430 -k -o file.c
      

      Then inspect the resulting file.asm. The key lines for the function above are ...

      shift_right_toU8:
      ;* --------------------------------------------------------------------------*
      ;** 5   -----------------------    return (unsigned char)(val>>8u);
              SWPB      r12                   ; [] |5|
              MOV.B     r12,r12               ; [] |5|
              MOV.B     r12,r12               ; [] |5|
              RET       ; []
      

      The second MOV.B is redundant.

      The other 3 functions, while similar, sometimes have the same problem, but sometimes not.

            syncuser TI User
            syncuser TI User
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: