From: Brian Hurt <bhurt@spnz.org>
To: John Prevost <j.prevost@gmail.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Interesting optimization
Date: Thu, 22 Jul 2004 19:10:48 -0500 (CDT) [thread overview]
Message-ID: <Pine.LNX.4.44.0407221856200.4202-100000@localhost.localdomain> (raw)
In-Reply-To: <d849ad2a04072214407f8b4f26@mail.gmail.com>
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
next prev parent reply other threads:[~2004-07-23 0:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-22 21:07 Daniel Bünzli
2004-07-22 21:40 ` John Prevost
2004-07-23 0:10 ` Brian Hurt [this message]
2004-07-23 1:22 ` John Prevost
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=Pine.LNX.4.44.0407221856200.4202-100000@localhost.localdomain \
--to=bhurt@spnz.org \
--cc=caml-list@inria.fr \
--cc=j.prevost@gmail.com \
/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