From: Norman Ramsey <nr@eecs.harvard.edu>
To: caml-list@inria.fr
Subject: more on nativeint interface
Date: Thu, 18 Jan 2001 14:07:52 -0500 [thread overview]
Message-ID: <200101181907.OAA28875@labrador.eecs.harvard.edu> (raw)
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
next reply other threads:[~2001-01-20 15:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-18 19:07 Norman Ramsey [this message]
2001-01-21 10:45 ` Xavier Leroy
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=200101181907.OAA28875@labrador.eecs.harvard.edu \
--to=nr@eecs.harvard.edu \
--cc=caml-list@inria.fr \
/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