This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ ABI and ILP64


On Thursday 16 December 2004 02:14, Joe Buck wrote:
> On Thu, Dec 16, 2004 at 02:02:51AM +0100, Markus F.X.J. Oberhumer wrote:
> > I'm currently playing around making and testing an experimental port of
> > AMD64 for the ILP64 programming model ...
> >
> > In case you're wondering, we're working on very high speed data
> > compression libraries, and apart from being useful for portability
> > testing (e.g. for those old Cray machines) ILP64 also seems to generate a
> > little bit better code for our purposes, mainly because a number of
> > implicit unsigned char -> int -> size_t promotions within complex
> > expressions can be shortened to char -> size_t, so this is not purely
> > academic.
>
> 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.

Well, the ILP64 port is really straighforward, and the main point of my mail 
was a call to fix the C++ ABI.

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-3.4 -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   


+ 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   


+ gcc-4.0-ilp64 -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:	48 0f b6 56 01       	movzbq 0x1(%rsi),%rdx
   8:	c0 e8 02             	shr    $0x2,%al
   b:	48 c1 e2 06          	shl    $0x6,%rdx
   f:	0f b6 c0             	movzbl %al,%eax
  12:	48 01 f8             	add    %rdi,%rax
  15:	48 01 d0             	add    %rdx,%rax
  18:	c3                   	retq   

-- 
Markus F.X.J. Oberhumer
http://www.oberhumer.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]