From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA08074 for caml-red; Sat, 20 Jan 2001 16:33:29 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA05012 for ; Thu, 18 Jan 2001 20:08:09 +0100 (MET) Received: from labrador.eecs.harvard.edu (labrador.eecs.harvard.edu [140.247.60.247]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f0IJ88L18769 for ; Thu, 18 Jan 2001 20:08:08 +0100 (MET) Received: (from nr@localhost) by labrador.eecs.harvard.edu (8.9.3/8.9.3) id OAA28875 for caml-list@inria.fr; Thu, 18 Jan 2001 14:07:52 -0500 Date: Thu, 18 Jan 2001 14:07:52 -0500 From: Norman Ramsey Message-Id: <200101181907.OAA28875@labrador.eecs.harvard.edu> To: caml-list@inria.fr Subject: more on nativeint interface Sender: weis@pauillac.inria.fr It would be useful to have val width : int (* number of bits in an integer of type nativeint *) so that, for example, I could do sign extension by suitable shifting. Meanwhile, I could play the following sorts of games: module N = Nativeint let width = if N.shift_right_logical N.minus_one 32 = N.zero then 32 else 64 let sx k n = N.shift_right (N.shift_left n (width-k)) (width-k) (* sign-extend the least significant k bits of integer n *) let sx13 = sx 13 Unfortunately, the code that the ocamlopt produces for this function (on x86) is pretty bad. I can get significantly better code by using this source: let width=32 let sx13b n = N.shift_right (N.shift_left n (width-13)) (width-13) But of course this code isn't portable. Is there anything I can do to get the compiler to do a better job with nativeint? Norman