From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA07652; Fri, 23 Jul 2004 02:03:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 CAA07593 for ; Fri, 23 Jul 2004 02:03:15 +0200 (MET DST) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6N03DEV020843 for ; Fri, 23 Jul 2004 02:03:14 +0200 Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.11.6/8.10.1) with ESMTP id i6N03Ao21155; Thu, 22 Jul 2004 19:03:10 -0500 (CDT) Date: Thu, 22 Jul 2004 19:10:48 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: John Prevost cc: Ocaml Mailing List Subject: Re: [Caml-list] Interesting optimization In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 410055C1.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 prevost:01 movl:01 cmpl:01 addl:01 $2,:01 cmpl:01 ocaml:01 align:98 int:01 rec:01 rec:01 wrote:03 ebx:03 ebx:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 22 Jul 2004, John Prevost wrote: > let update'' c = > let rec loop c' a = > if a >= 0 > then loop (c' land 0xff) (succ a) > else c' > in > c := (loop !c 0) let update''' c = let rec loop c i = let c = c land 0xff in if (i < max_int) then loop c (i+1) else c in loop c 0 ;; Haven't tried timing it. But the core code on the x86 becomes: Temp__loop_59: .L101: andl $511, %eax movl $2147483647, %ecx cmpl %ecx, %ebx jge .L100 addl $2, %ebx jmp .L101 .align 16 I'm slightly disappointed that Ocaml didn't just cmpl $2147483647, %ebx and not use ecx at all. Not that this is that big a problem. The only other possible optimizations would be to recognize that the entire loop is pointless, and the function can be replaced by: let update c = c land 0xff;; I feel comfortable leaving that particular optimization in the hands of the programmer, however. -- "Usenet is like a herd of performing elephants with diarrhea -- massive, difficult to redirect, awe-inspiring, entertaining, and a source of mind-boggling amounts of excrement when you least expect it." - Gene Spafford Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners