Version française
Home     About     Download     Resources     Contact us    
Browse thread
Estimating the size of the ocaml community
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] The boon of static type checking
Brian Hurt <bhurt@spnz.org> writes:

> Hint: I've yet to meet a compiler that couldn't turn x/32 into 
> x >> 5.

Actually this is incorrect when x is a signed type (and might be
negative).

Strictly speaking, the sign of the quotient when either argument
is negative is implementation-defined in C++, but GCC prefers to be
consistent (it's the sign of the dividend when idiv is used, but
shifting would yield the sign of the divisor).

This means that when I care about performance and perform division
of a number that I know is non-negative by a number which might
be a constant power of 2, I cast the divisor to an unsigned type.
The same applies to remainder.

> Actually, g++ does do tail call optimization (in the 3.x tree).  It's 
> actually not that hard to do, just not that beneficial (for C++).

It is hard:

- With the default C/C++ calling convention it's impossible if
  parameters of the callee take more space than parameters of the
  caller.

- On x86 in PIC it would make calls from extern functions to some
  static functions slower. Because the callee assumes that %ebx allows
  to find data of our module, yet *our* caller in general assumes that
  we will restore %ebx. Instead of making these functions slower for
  all calls (by setting up and restoring %ebx in the callee too), GCC
  doesn't perform tail call optimization in this case.

- It requires from the compiler to infer that addresses of our local
  variables don't leak to code which might use them while the
  tail-called function is running.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/