From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p859oJ8Y030685 for ; Mon, 5 Sep 2011 11:50:19 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvoAAKiaZE7U4367kGdsb2JhbABCDoQ/o3sUAQEBAQkJDQcUAyOBRgEBBAEjVhALDgwCJgICVwYTCRKHWAICpyuQZ4EshC2BEQSMFYwoi0Y6 X-IronPort-AV: E=Sophos;i="4.68,332,1312149600"; d="scan'208";a="107735180" Received: from moutng.kundenserver.de ([212.227.126.187]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Sep 2011 11:50:14 +0200 Received: from office1.lan.sumadev.de (dslb-094-219-217-072.pools.arcor-ip.net [94.219.217.72]) by mrelayeu.kundenserver.de (node=mrbap4) with ESMTP (Nemesis) id 0MdLEp-1Qjnsd1z1P-00IBAY; Mon, 05 Sep 2011 11:50:12 +0200 Received: from [192.168.0.29] (dslb-084-058-040-030.pools.arcor-ip.net [84.58.40.30]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id 1167AC00C7; Mon, 5 Sep 2011 11:50:12 +0200 (CEST) From: Gerd Stolpmann To: John Carr Cc: caml-list@inria.fr In-Reply-To: <201109041522.p84FM5DA001371@outgoing.mit.edu> References: <201109041522.p84FM5DA001371@outgoing.mit.edu> Content-Type: text/plain; charset="UTF-8" Date: Mon, 05 Sep 2011 11:50:11 +0200 Message-ID: <1315216211.3496.220.camel@thinkpad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:hpJ3cMVQ3am0oRLYfeFY4wKAmbgJBccud77SR9Sl9ej +gE7KVnve1izOFQ4uu/04szpyhIQwx3cx9wyH3KlJCHluHlVR3 7dP/sWOwc1tGoS73iy4TUixcBrh1JB/JvE5CthyvpwmhX/sJ59 6kf1H5ht3KjFSgXInStDEqUs4A5YDytlv7lXyyD6WCFVD1Ms/D Wjkw8/8kfoU1d+B0l1rYcDlKBdAwbvFAk7Q/g+dHiH5f4lVPkz 5vRJZsuzcFl+4K6CIm0aLfGF5e/bHNhyQDcdq70Gw8l6luCtB9 /e7EqoKgaj9J+4s6HiTu+0dO9r4yQ4VqF6K65Py2h8e3Qy2kGT 5aoR0NDnopIa/Cvgm0vrshQhpOkD8c1Rzuu9wjWEJ Subject: Re: [Caml-list] Conditionally boxed 32 bit integers? 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. ------------------------------------------------------------