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

Compiler inefficiently optimizes __swap_bytes macro

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Implemented
    • Icon: Low Low

      The attached test has this line ...

          return a | __swap_bytes(b);
      

      a and b are of type unsigned char. Build it with optimization ...

      % cl430 -vmspx -o -s try1.c
      

      ... and the resulting assembly is not very good.

      ;** 7   -----------------------    return (unsigned)a|(unsigned)b>>8|(unsigned)b<<8;
              .dwpsn  file "try1.c",line 7,column 5,is_stmt,isa 0
              MOV.B     &a+0,r15              ; [] |7|
              MOV.B     &b+0,r12              ; [] |7|
              SWPB      r12                   ; [] |7|
              MOV.B     r12,r12               ; [] |7|
              OR.W      r12,r15               ; [] |7|
              MOV.B     &b+0,r12              ; [] |7|
              RPT #8 || RLAX.W r12 ; [] |7|
              OR.W      r15,r12               ; [] |7|
      

      Build it with no optimization ...

      % cl430 -vmspx -ooff -s try1.c
      

      ... and the resulting assembly is much better ...

      ;----------------------------------------------------------------------
      ;   7 | return a | __swap_bytes(b);
      ;----------------------------------------------------------------------
              MOV.B     &a+0,r15              ; [] |7|
              MOV.B     &b+0,r12              ; [] |7|
              SWPB      r12                   ; [] |7|
              OR.W      r15,r12               ; [] |7|
      

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: