Hi all,

I am using the gcc ARM cross-compiler (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)). Compiling the test.c code (in attachement) with:

'arm-linux-gnueabi-gcc -S test.c'

I obtain the test.s assembly code (in attachement). At lines 56 and 57 of the test.s there is two identical strd instructions:

56      strd    r2, [r7]
57      strd    r2, [r7]

I have checked the semantic of the ARM strd instruction and I have not seen any side effect of this instruction that could explain why gcc need to put this instruction two times in a row. For me, one is sufficient to store the 8-bytes variable into memory.

Is there an explanation?

Thanks.

Nathanaël Prémillieu
#include <stdlib.h>
#include <stdio.h>

int main()
{
  int a = rand();
  long long int b = rand();
  if(a % 2)
    {
      b *= 999;
    }
  printf("%lld\n", b);
}
        .syntax unified
        .arch armv7-a
        .eabi_attribute 27, 3
        .fpu vfpv3-d16
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 6
        .eabi_attribute 34, 1
        .eabi_attribute 18, 4
        .thumb
        .file   "test.c"
        .section        .rodata
        .align  2
.LC0:
        .ascii  "%lld\012\000"
        .text
        .align  2
        .global main
        .thumb
        .thumb_func
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        push    {r7, lr}
        sub     sp, sp, #16
        add     r7, sp, #0
        bl      rand
        str     r0, [r7, #12]
        bl      rand
        mov     r1, r0
        mov     r2, r1
        asr     r3, r2, #31
        strd    r2, [r7]
        ldr     r3, [r7, #12]
        and     r3, r3, #1
        uxtb    r3, r3
        cmp     r3, #0
        beq     .L2
        ldr     r3, [r7, #4]
        movw    r2, #999
        mul     r2, r2, r3
        ldr     r3, [r7, #0]
        mov     r1, #0
        mul     r3, r1, r3
        adds    r1, r2, r3
        ldr     r2, [r7, #0]
        movw    r3, #999
        umull   r2, r3, r2, r3
        adds    r1, r1, r3
        mov     r3, r1
        strd    r2, [r7]
        strd    r2, [r7]
.L2:
        movw    r3, #:lower16:.LC0
        movt    r3, #:upper16:.LC0
        mov     r0, r3
        ldrd    r2, [r7]
        bl      printf
        mov     r0, r3
        add     r7, r7, #16
        mov     sp, r7
        pop     {r7, pc}
        .size   main, .-main
        .ident  "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
        .section        .note.GNU-stack,"",%progbits

Reply via email to