Browse thread
Efficiency of let/and
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-09-26 (16:30) |
From: | Brian Hurt <bhurt@s...> |
Subject: | Re: [Caml-list] Re: Ant: Efficiency of let/and |
On Mon, 26 Sep 2005, Stefan Monnier wrote: >> Syntactically and semantically there is no difference. I was wondering if >> the ocamlopt compiler took advatange of the implicit paralellism at all. > > If someone tries to use such things as `and' or > unspecified-argument-evaluation-order in the hopes that the compiler will > extract some imagined parallelism is simply deluding himself. > In some cases, the freedom to execute in any order does lead to better > code, but that code rarely if ever uses any kind of parallelism. I was thinking of instruction-level parallelism- the ability of the compiler to reorder instructions to better use the available functional units, not thread-level parallelism. Sorry for not being clear there. I'm not even sure how much extra efficiency is there to be had. Obviously it'd be hard "thread" calls to complex functions, so code like: let foo lst1 lst2 = let len1 = List.length lst1 and len2 = List.length lst2 in ... wouldn't be helped- it'd be computationally infeasible for the compiler to interleave the two different calls to List.length. So you'd pretty obviously be limited to "simple" expressions, at which point the CPU's own prefetching and reordering is likely to do the work for you wether the compiler does it or not. In fact, the CPU's reordering can start executing the code to List.length lst2 speculatively before the call to List.length lst1 is complete, and in that sense the CPU's reordering is more capable then what the compiler can do (this, BTW, is the fundamental problem with the Itanium). Brian