caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Erik de Castro Lopo <ocaml-erikd@mega-nerd.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Need for a built in round_to_int function
Date: Mon, 21 Feb 2005 22:54:32 +1100	[thread overview]
Message-ID: <20050221225432.4f15c5e5.ocaml-erikd@mega-nerd.com> (raw)
In-Reply-To: <20050221072255.29055ee4.ocaml-erikd@mega-nerd.com>

On Mon, 21 Feb 2005 07:22:55 +1100
Erik de Castro Lopo <ocaml-erikd@mega-nerd.com> wrote:

> I've looked at the code for the O'Caml compiler and I think I 
> know how to implement this, at least for x86 and PowerPC, the two
> architectures I have access to. If I was to supply a patch would
> it be accepted?

OK, I have a patch that seems to do the right thing on x86 and
PowerPC:

    http://www.mega-nerd.com/tmp/round_to_int.diff

I'm not 100% happy with the mods to byterun/floats.c. In order to
use the C99 lrintf() function in caml_round_to_int() I had to
define _ISOC9X_SOURCE etc before including <math.h>. The real
solution (when using GCC) is to add -std=c99 to the command line.

Using the following test program:

    http://www.mega-nerd.com/tmp/round_to_int.ml

with the hacked ocamlopt compiler I'm getting about a 3 times speed
improvement using round_to_int on a Pentium III. The speedup on P4
is supposed to be even more because of the P4's deeper pipeline.
On PowerPC, there is no speedup because PowerPC has two separate
instructions for float to int, one which rounds and one which 
truncates.

I'd be interested in any comments from the official ocaml maintainers.
What are the chances of this going into the official distribution?

I also have access to a machine with a MIPS CPU. I don't know
MIPS assembler but I'll see what I can do.

Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"I saw `cout' being shifted "Hello world" times to the left and
stopped right there." -- Steve Gonedes


  parent reply	other threads:[~2005-02-21 11:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-20 20:22 Erik de Castro Lopo
2005-02-21  0:00 ` [Caml-list] " Robert Roessler
2005-02-21  1:51   ` Erik de Castro Lopo
2005-02-21  4:34     ` Robert Roessler
2005-02-21  6:50       ` Erik de Castro Lopo
2005-02-21 11:54 ` Erik de Castro Lopo [this message]
2005-02-21 16:00   ` Xavier Leroy
2005-02-22  7:23     ` Erik de Castro Lopo
2005-02-21 16:01   ` Hendrik Tews

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=20050221225432.4f15c5e5.ocaml-erikd@mega-nerd.com \
    --to=ocaml-erikd@mega-nerd.com \
    --cc=caml-list@yquem.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;
as well as URLs for NNTP newsgroup(s).