Diary Of An x264 Developer

03/25/2009 (9:01 pm)

An excerpt from objdump

Filed under: assembly,fail,ffmpeg,gcc ::

mov eax,esi
shr r10d,2
movsxd rax,[rax*4+0]

The tags should make this post self-explanatory.

(Yes, I’ll post something else soon.  Bug me about it on IRC or something.)

Update: the braindeadness continues.

cmp    edx,esi
cmovge edi,[esp+0xac]
cmp    edx,esi

11 Responses to “An excerpt from objdump”

  1. Reimar Says:

    If you consider that worth a complaint you’ve never seen gcc handle non-native types.
    E.g. uint16_t * uint8_t generates this code for Atmel 8-bit MCUs (but the same happens for uint64_t*uint32_t on x86):
    ldi r23, 0×00
    mul r22, r24
    movw r18, r0
    mul r22, r25
    add r19, r0
    mul r23, r24
    add r19, r0

    Yes, it does load 0 into a register just to multiply with that 0 and add the result.
    AFAICT at least _all_ 3.x and 4.x gcc versions do that.

  2. Pengvado Says:

    uint64_t foo(uint32_t x, uint64_t y) { return x*y; }

    compiled on gcc-4.3.2 x86_32:
    mov eax, [esp+0x4]
    mov ecx, [esp+0xc]
    imul ecx, eax
    mul dword[esp+0x8]
    lea edx, [ecx+edx]
    ret

    … the lea could be an add, but it looks pretty ok.

    otoh, gcc-4.2.4 is just as bad as you said:
    sub esp, 0×8
    mov edx, [esp+0x14]
    mov ecx, [esp+0xc]
    mov eax, [esp+0x10]
    mov [esp+0x4], esi
    mov esi, edx
    imul esi, ecx
    mul ecx
    mov [esp], ebx
    mov ebx, [esp]
    add esi, edx
    mov edx, esi
    mov esi, [esp+0x4]
    add esp, 0×8
    ret

  3. Jed Says:

    I was appalled when I saw what suncc does with SSE intrinsics

    mulpd xmm1,XMMWORD PTR [rsp+0x200]
    movapd XMMWORD PTR [rsp+0x230],xmm1
    movapd xmm1,XMMWORD PTR [rsp+0x230]
    addpd xmm1,xmm0
    movapd XMMWORD PTR [rsp+0x240],xmm1
    movapd xmm0,XMMWORD PTR [rsp+0x240]
    mulpd xmm2,XMMWORD PTR [rsp+0x210]
    movapd XMMWORD PTR [rsp+0x250],xmm2
    movapd xmm2,XMMWORD PTR [rsp+0x250]
    etc

    In contrast, gcc-4.4 does a remarkably good job with intrinsics.

  4. Mans Says:

    Has anyone reported these issues to gcc devs? Did they pretend to listen?

  5. Setsuna-Xero Says:

    this is why the first thing you’re supposed to do is switch CC to GGC…

  6. Setsuna-Xero Says:

    then again GCC isn’t really all to much better…

  7. pup Says:

    “gcc devs? Did they pretend to listen?”

    if the GCC devs are so bad and refuse to listen or fix these problems, why havent you people already folked the code and just made it far better yourself for everyones benefit…

  8. andrew Says:

    Technically, that’s already happened (sort of).

    See: llvm.org
    (Low Level Virtual Machine, project is a complete compiler rewrite based on GCC language frontends that is supposed to produce way better code – doesn’t support as many CPU arches currently though)

  9. Pegasus Says:

    What about Intel ICC? Any good for video encoding software?

  10. D3C0D3R Says:

    2 Pengvado

    lea instructions that are more efficient than their mov/add counterparts.

    On the 80386 and later processors, you can use the scaled indexed addressing modes to multiply by two, four, or eight as well as add registers and displacements together. Intel strongly suggests the use of the lea instruction since it is much faster than a sequence of instructions computing the same result.

    so gcc 4.32 in this case gens very smart code

  11. D3C0D3R Says:

    2 Pengvado
    hm, i was wrong
    here add is acceptible, but maybe gcc use lea for common cases when it is more preferable

Leave a Reply