caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Conditionally boxed 32 bit integers?
@ 2011-09-04 15:22 John Carr
  2011-09-04 17:28 ` Hezekiah M. Carty
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: John Carr @ 2011-09-04 15:22 UTC (permalink / raw)
  To: caml-list


I am working with a file format the contains 32 bit integers.
I need to use int32 on 32 bit systems.  I would like to use plain
integers, unboxed and with native machine operations, on 64 bit
systems.

Is there any way to convince ocamlopt to choose between int and
int32 representations _at compile time_?

I could use first class modules to select implementations at
runtime, which is not worth the code complexity and still
requires an indirect function call to add numbers.  I could
conditionally compile different files depending on word size,
which strikes me as an ugly and fragile solution.

I want to be able to write "int32" and have that be compiled
like an ordinary integer type if 32 bits and tag fit into a
word, and as a boxed type otherwise.  (The compiler could
mask off excess precision if desired.)  Is there a reason ocaml
can't provide this?

Another implementation would have each instance of an int32 or
int64 be boxed or not depending on whether the value fits into
a word.  I don't know whether this would be faster or slower in
practice.  There is a tradeoff between allocations and
conditional branches.

    --John Carr (jfc@mit.edu)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-09-06  7:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-04 15:22 [Caml-list] Conditionally boxed 32 bit integers? John Carr
2011-09-04 17:28 ` Hezekiah M. Carty
2011-09-04 20:58 ` Richard W.M. Jones
2011-09-05  7:25 ` rixed
2011-09-05 15:16   ` John Carr
2011-09-05 22:11     ` John Carr
2011-09-06  7:50       ` Fabrice Le Fessant
2011-09-05  9:50 ` Gerd Stolpmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).