Page 1 of 1

Pointless "movt r#, 0x0" instruction?

PostPosted: Thu Dec 31, 2015 3:44 pm
by jar
I noticed GCC seems to emit the instruction pair for loading a 32-bit constant into a register (16 bits at a time). The instruction pair generally looks something like this:

Code: Select all
unsigned int foo = 0xdeadbeef;

compiles to:
Code: Select all
mov r0,0xbeef
movt r0,0xdead


If there is a compile-time constant that is 16-bits or less (just 0xbeef in the above code), GCC shouldn't need the second movt instruction for setting the upper 16-bits. It's my understanding that the single mov (immediate) instruction should be sufficient for this case because it sets all 32-bits (I'm assuming the high bits are zeroed?). GCC will still emit "movt r0, 0x0" which seems rather pointless. In some of my routines, 40% of the instructions are these instruction pairs, so the binary ends up 25% larger than needed with all the "movt r#,0x0" instructions. Compiler options like "-Os" don't seem to have any effect. Is there any way to emit tighter code short of hacking GCC? Is there some side effect of the movt instruction I don't fully understand?

Re: Pointless "movt r#, 0x0" instruction?

PostPosted: Thu Dec 31, 2015 4:53 pm
by aolofsson
I recall this being a compiler performance issue that did not get resolved. Can you file an issue on the epiphany-sdk github repo? Hopefully it is an easy fix.
Andreas

Re: Pointless "movt r#, 0x0" instruction?

PostPosted: Thu Dec 31, 2015 6:40 pm
by jar
Thank you, Andreas.

I submitted the issue here:
https://github.com/adapteva/epiphany-sdk/issues/61