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 11:00, Jakub Jelinek wrote:
> On Thu, Dec 16, 2004 at 02:32:34AM +0100, Markus F.X.J. Oberhumer wrote:
> [...]
>
> 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.

I agree - but note that in many cases the compiler is not allowed to make such 
optimizations under LP64. 

If you consider the example below, "(base[off] << shift)" must be promoted and 
computed in int/unsigned int, and the "cltq" instruction can only be omitted 
in ILP64.

Please also note that the example is already "LP64 friendly" by using long as 
parameters - naively using int here would require even more instructions 
under LP64.

And yes, you can simulate ILP64 by adding lots of casts to ptrdiff_t/size_t, 
but that's tedious, error prone, and worst of all it doesn't scale to C++ 
template code (e.g. if the "base" parameter is some iterator). With the 
-mint64 option the compiler just cares for you.

~Markus


+ set -x
+ cat test.c
char *foo(char* base, long off, long shift) {
   return base + (base[off] << shift);
}

+ 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 be 04 3e          	movsbl (%rsi,%rdi,1),%eax
   4:	48 89 d1             	mov    %rdx,%rcx
   7:	d3 e0                	shl    %cl,%eax
   9:	48 98                	cltq   
   b:	48 8d 04 07          	lea    (%rdi,%rax,1),%rax
   f:	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:	48 0f be 04 3e       	movsbq (%rsi,%rdi,1),%rax
   5:	48 89 d1             	mov    %rdx,%rcx
   8:	48 d3 e0             	shl    %cl,%rax
   b:	48 8d 04 07          	lea    (%rdi,%rax,1),%rax
   f:	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]