From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Optimizing Float Ref's
Date: Mon, 31 Aug 2009 18:30:53 +0100 [thread overview]
Message-ID: <200908311830.53339.jon@ffconsultancy.com> (raw)
In-Reply-To: <D27BEB0C-F919-4077-ABE6-36D20206CB34@gmail.com>
On Sunday 30 August 2009 20:43:17 Yaron Minsky wrote:
> Float refs are not unboxed automatically, because refs
> Are polymorphic containers. If you create your own pseudo-ref, i.e., a
> record with a single mutable float field, then I believe you should
> get the behaviour you expect.
I believe you are talking at cross purposes. Will wants his accumulator in a
register. You are referring to float references in data structures being
boxed because records are boxed.
Look at the compiled forms of the inner loops of these dot products, for
example:
let dot a b =
let x = ref 0.0 in
for i=0 to Array.length a - 1 do
x := !x +. a.(i) *. b.(i)
done;
!x
.L101:
.L103: movl caml_young_ptr, %eax
subl $12, %eax
movl %eax, caml_young_ptr
cmpl caml_young_limit, %eax
jb .L104
leal 4(%eax), %eax
movl $2301, -4(%eax)
fldl -4(%edi, %ecx, 4)
fmull -4(%ebx, %ecx, 4)
faddl (%esi)
fstpl (%eax)
movl %eax, %esi
movl %ecx, %eax
addl $2, %ecx
cmpl %edx, %eax
jne .L101
let dot2 a b =
let x = ref 0.0 in
for i=0 to Array.length a - 1 do
x := !x +. a.(i) *. b.(i)
done;
1.0 *. !x
.L107:
fldl -4(%eax, %ecx, 4)
fmull -4(%ebx, %ecx, 4)
faddl 0(%esp)
fstpl 0(%esp)
movl %ecx, %edx
addl $2, %ecx
cmpl %esi, %edx
jne .L107
In the latter case, "x" is unboxed into a register.
> Come to think of it, I wonder if it would be better to implement ref
> on top of a single-cell array, since then everyone would get the float
> unboxing whenever applicable. I imagine there is some runtime overhead
> to this, though.
All-float (including one-float) records are unboxed anyway.
Boxing was discussed in the book OCaml for Scientists and the OCaml Journal
articles about optimization and the SciMark2 benchmark.
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
next prev parent reply other threads:[~2009-08-31 16:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-28 20:32 Will M Farr
2009-08-30 19:43 ` [Caml-list] " Yaron Minsky
2009-08-31 14:09 ` Till Varoquaux
2009-08-31 14:51 ` Will M Farr
2009-08-31 17:30 ` Jon Harrop [this message]
2009-08-31 17:15 ` Jon Harrop
2009-09-03 9:44 ` Xavier Leroy
2009-09-03 10:15 ` Will M Farr
2010-03-31 17:21 ` Dmitry Bely
[not found] ` <p2tc7e4e9f1003311055xce0919wac2118aa3c05f1cb@mail.gmail.com>
2010-03-31 18:28 ` Dmitry Bely
2010-03-31 18:59 ` Alain Frisch
2010-03-31 19:18 ` Dmitry Bely
[not found] ` <m2lfbd71dab1003311252v5bda5d13vc2146d2d24270847@mail.gmail.com>
2010-03-31 20:00 ` Dmitry Bely
2010-04-14 18:13 ` Goswin von Brederlow
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=200908311830.53339.jon@ffconsultancy.com \
--to=jon@ffconsultancy.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