caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: John Carr <jfc@mit.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Conditionally boxed 32 bit integers?
Date: Mon, 05 Sep 2011 11:50:11 +0200	[thread overview]
Message-ID: <1315216211.3496.220.camel@thinkpad> (raw)
In-Reply-To: <201109041522.p84FM5DA001371@outgoing.mit.edu>

Am Sonntag, den 04.09.2011, 11:22 -0400 schrieb John Carr:
> 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_?

The Netnumber module of Ocamlnet actually does this:

https://godirepo.camlcity.org/svn/lib-ocamlnet2/trunk/code/src/netstring/netnumber.mli
https://godirepo.camlcity.org/svn/lib-ocamlnet2/trunk/code/src/netstring/netnumber.mlp

Netnumber is fairly standalone, so you could just copy it to your
project if you don't want all of Ocamlnet.

Gerd


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

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
*** Searching for new projects! Need consulting for system
*** programming in Ocaml? Gerd Stolpmann can help you.
------------------------------------------------------------


      parent reply	other threads:[~2011-09-05  9:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-04 15:22 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1315216211.3496.220.camel@thinkpad \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@inria.fr \
    --cc=jfc@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).