Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
32 bit integers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: 32 bit integers
> I found this implementation to be terribly slow (even slower than the
> bignum stuff in many cases.)  Any idea why this is?  Is it just
> because of the extra dereference, or is it because the compiler uses
> better code for "primitive" type operations like int addition than it
> does for other types?

Both, actually.  Boxing is always expensive, not so much because of
the extra dereference, but mostly because of the extra heap allocations.
(There are good reasons why the "int" type is tagged instead of boxed
in OCaml...)  On top of that, all operations on Int32.t are
implemented by C functions, and calling a C function from Caml is
expensive -- more expensive than calling a Caml function, and much
more expensive than open-coding the operations.

> (This second was my guess.)  Is there any way
> to make this kind of extension work better?

There is a way, but it involves modifying the compiler itself
to add special code generation rules for the primitive operations on
the new integer type.

- Xavier Leroy