From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id D036ABC75 for ; Mon, 21 Feb 2005 12:54:38 +0100 (CET) Received: from smtp.syd.swiftdsl.com.au (smtp.syd.swiftdsl.com.au [218.214.224.138]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j1LBsZkS006283 for ; Mon, 21 Feb 2005 12:54:37 +0100 Received: (qmail 7662 invoked from network); 21 Feb 2005 11:54:52 -0000 Received: from unknown (HELO coltrane.mega-nerd.net) (218.214.64.136) by smtp.syd.swiftdsl.com.au with SMTP; 21 Feb 2005 11:54:52 -0000 Received: from coltrane (localhost [127.0.0.1]) by coltrane.mega-nerd.net (Postfix) with SMTP id 6ECD27B90 for ; Mon, 21 Feb 2005 22:54:33 +1100 (EST) Date: Mon, 21 Feb 2005 22:54:32 +1100 From: Erik de Castro Lopo To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Need for a built in round_to_int function Message-Id: <20050221225432.4f15c5e5.ocaml-erikd@mega-nerd.com> In-Reply-To: <20050221072255.29055ee4.ocaml-erikd@mega-nerd.com> References: <20050221072255.29055ee4.ocaml-erikd@mega-nerd.com> Organization: Erik Conspiracy Secret Labs X-Mailer: Sylpheed version 1.0.0 (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4219CBFB.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 o'caml:01 compiler:01 powerpc:01 powerpc:01 byterun:01 gcc:01 hacked:01 ocamlopt:01 compiler:01 speedup:01 speedup:01 ocaml:01 mips:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: On Mon, 21 Feb 2005 07:22:55 +1100 Erik de Castro Lopo 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 . 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