I am porting gcc 4.3.2 to my own micro-controller.
For below piece of code, the instruction "clr.w a15" obviously doesn't
belong to the inner loop. Compiler should be smart enough to move it
to the beginning of the function.
How I can hoist the constant out of loops?
Maybe the costs functions have to be changed, but I don't know how.
Thanks.

C code:
void memzero_aligned(uint* ptr, uint size)
{
    uint ptr_end = (uint)ptr + size;
    while ((uint)ptr < ptr_end)
    {
         *ptr++ = 0;
    }
}

Disassembly code:
00000000 <_memzero_aligned>:
   0:   bc ab 90       add.w a9 a10 a11;
   3:   f4 0e 0b        bra 0xe;  #branch unconditionally, no delay slot
   6:   bd f4            clr.w a15; #clear to zero
   8:   80 af 00        std.w a10 0x0 a15;
   b:   90 aa 04       add.w a10 a10 0x4;
   e:   b8 a9 06       cmp.w a10 a9;
  11:   f4 08 f5        brc 0x6;
  14:   f8 00            ret;

-- 
-Qifei Fan
http://freshtime.org

Reply via email to