1

Is it possible to force generating thumb 32 bit instructions when possible?

For example I have:

int main(void) {
 8000280:   b480        push    {r7}
 8000282:   b085        sub sp, #20
 8000284:   af00        add r7, sp, #0
    uint32_t a, b, c;

    a = 1;
 8000286:   2301        movs    r3, #1
 8000288:   60fb        str r3, [r7, #12]
    b = 1;
 800028a:   2301        movs    r3, #1
 800028c:   60bb        str r3, [r7, #8]
    c = a+b;
 800028e:   68fa        ldr r2, [r7, #12]
 8000290:   68bb        ldr r3, [r7, #8]
 8000292:   4413        add r3, r2
 8000294:   607b        str r3, [r7, #4]

    while (1) ;
 8000296:   e7fe        b.n 8000296 <main+0x16>

But they are all thumb 16 bit. For testing reason I want thumb 32 bit instructions.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
jsmith
  • 127
  • 2
  • 13
  • 1
    I thought the whole point of Thumb was that it preferred 16-bit instructions? – Cody Gray - on strike Dec 31 '16 at 07:12
  • Probably. However I'd like to generate thumb 32 instructions when possible. (Cortex M4) – jsmith Dec 31 '16 at 07:28
  • I'm not an expert here, I don't even own an ARM processor, but [the guidance I find](http://stackoverflow.com/questions/10638130/what-is-the-arm-thumb-instruction-set) seems pretty clear to me that you are pursuing an impossible task. If you want 32-bit instructions to be emitted, just compile for the standard ARM instruction set. If that isn't satisfactory, consider explaining *why* you are trying to do this, and maybe someone can give you a better workaround. – Cody Gray - on strike Dec 31 '16 at 07:32
  • 1
    If you append `.w` to an instruction it will instruct the compiler to prefer a 32-bit encoding. – EOF Dec 31 '16 at 13:24
  • @CodyGray there is a big difference between 32 bit ARM and thumb2 extensions. As mentioned this is for a cortex-m4 which doesnt support the 32 bit ARM instructions but supports the 140 or so thumb2 extensions (armv7-m). – old_timer Jan 03 '17 at 06:35
  • First you need to choose between unified syntax or not then use the right command line and/or directive. See EOFs comment above. Likewise this has been asked and answered at stack overflow (in various forms). – old_timer Jan 03 '17 at 06:37
  • If you are compiling high level code (C) and not assembly language then use the proper command line option to select armv7m and/or cortex-m4, it wont always use the larger instructions when there is a choice (this is a microcontroller that would be quite wasteful) but will use it more often than zero times for a decent sized function/project. GCC is open source so you can look at the backend and see how/when it chooses, you could build your own gcc with perhaps a flag set to lean toward thumb2, or perhaps you will find a command line option. – old_timer Jan 03 '17 at 06:39

1 Answers1

1

Well, I don't think you can do that directly, but there is a very strange way of achieving that in a very indirect way. Just a few days ago I've seen a project where the compilation process was not just a simple arm-none-eabi-gcc ... -c file.c -o file.o. The project was calling arm-none-eabi-gcc to also generate extended assembly listing, which was later assembled manually with arm-none-eabi-as into an object file. If you would do it like that, then between these two steps you could modify the assembly listing to have wide instructions only - in most (all?) cases you could just use sed to add .w suffix to the instructions (change add r3, r2 into add.w r3, r2 and so on). Whether or not such level of build complication is worth it, is up to you...

Freddie Chopin
  • 8,440
  • 2
  • 28
  • 58