An excerpt from objdump
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
April 4th, 2009 at 6:09 am
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.
April 10th, 2009 at 1:14 am
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
May 11th, 2009 at 10:30 am
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.
May 14th, 2009 at 2:11 am
Has anyone reported these issues to gcc devs? Did they pretend to listen?
June 5th, 2009 at 4:45 pm
this is why the first thing you’re supposed to do is switch CC to GGC…
June 5th, 2009 at 4:51 pm
then again GCC isn’t really all to much better…
July 3rd, 2009 at 12:25 pm
“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…
July 7th, 2009 at 10:11 pm
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)
October 5th, 2009 at 7:11 am
What about Intel ICC? Any good for video encoding software?
June 18th, 2010 at 2:51 am
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
June 18th, 2010 at 5:40 am
2 Pengvado
hm, i was wrong
here add is acceptible, but maybe gcc use lea for common cases when it is more preferable