C++ ABI and ILP64
Jakub Jelinek
jakub@redhat.com
Thu Dec 16 10:01:00 GMT 2004
On Thu, Dec 16, 2004 at 02:32:34AM +0100, Markus F.X.J. Oberhumer wrote:
> > If the code you get for I32, LP64 is really worse because of this issue
> > (inefficient conversions), that seems broken, and fixing such bugs seems
> > more worthwile than trying to make a complete ILP64 port just to work
> > around them.
>
> Still, here you can see how ILP64 can save one instruction (the "movslq"
> promotion) in a completely trivial expression:
>
>
> + set -x
> + cat test.c
> unsigned char* foo(unsigned char* base, const unsigned char* buf)
> {
> return base + (buf[0] >> 2) + (buf[1] << 6);
> }
>
> + gcc-4.0 -O2 -c test.c
> + objdump -d test.o
>
> test.o: file format elf64-x86-64
>
> Disassembly of section .text:
>
> 0000000000000000 <foo>:
> 0: 0f b6 06 movzbl (%rsi),%eax
> 3: 0f b6 56 01 movzbl 0x1(%rsi),%edx
> 7: c0 e8 02 shr $0x2,%al
> a: c1 e2 06 shl $0x6,%edx
> d: 0f b6 c0 movzbl %al,%eax
> 10: 48 63 d2 movslq %edx,%rdx
> 13: 48 01 f8 add %rdi,%rax
> 16: 48 01 d0 add %rdx,%rax
> 19: c3 retq
But what Joe says applies here perfectly. ILP64 is a wrong "solution"
for this optimization deficiency, the compiler knows or can find out
that movslq instruction is unnecessary as the sign bit is known to be
zero and the upper 32 bits of the register as well.
So any effort should be better directed that way where it will help
everybody.
Jakub
More information about the Gcc
mailing list