Re: Value types (Was: [Caml-list] ocamlopt LLVM support)

2010-12-13 Thread Alain Frisch

On 12/12/2010 08:09 PM, Benedikt Meurer wrote:

The boxing involved is relevant, but boxing in general is not the
issue. In this special case, the let nlen, n = if... code requires
heap allocation, because of the way the pattern is compiled. This could
be fixed by moving the condition out of the code and using two if's to
select n/nlen separately (doesn't speed up that much). Fixing the
pattern compiler to handle these cases might be interesting for general
benefit.


Instead of duplicating the conditional, you could also push the 
assignments to bound variables down the expression. For instance:


let (x, y) = if b then (u, v) else (v, u) in ...

can be replaced, conceptually, by:

let x = dummy in
let y = dummy in
if b then (x - u; y - v) else (x - v; y - u);
...

and similarly when the bound expression is a pattern matching.


I've played with this a few months ago and could observe important 
speedups (27%, 20%) on two micro-benchmarks.


The diff is really small:

http://caml.inria.fr/cgi-bin/viewcvs.cgi/ocaml/branches/inplace_let/bytecomp/matching.ml?rev=10475sortby=dater2=10475r1=10474


-- Alain



Micro benchmark 1:

let () =
  for k = 1 to 1 do
for i = 1 to 10 do
  let (x, y) =
if i mod 2 = 0 then (1, i * 2)
else (2, i * 3)
  in
  r := !r * x + y
done
  done



Micro benchmark 2:

let f x y z =
  let a, b =
match z with
| Some (u, v) - u, v * 2
| None - 10, 20
  in
  a * x + b * y

let () =
  let r = ref 0 in
  for k = 1 to 2000 do
for i = 1 to 10 do
  r := !r + f k i (Some (k, i));
  r := !r + f k i None
done
  done

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Re: optimize div to right shift (NOT!)

2010-12-13 Thread Török Edwin
On Mon, 13 Dec 2010 12:33:33 +
Jonathan Kimmitt jonat...@kimmitt.co.uk wrote:

 
  A C compiler would optimize this to a right shift. Changing that to
  'Int64.shift_right n 1' speeds up the code.
 
 Sorry to be a pedant, but this is not correct. The optimisation is
 only possible when the arguments are unsigned integers 

That particular program never used negative integers.

 which I don't
 think is specifiable when working in OCAML

You are right, there is no way to tell ocaml that.

 
 # Int64.shift_right (-2L) 1;;
 - : int64 = -1L (So far, so good)
 # Int64.div (-1L) 2L;;
 - : int64 = 0L (Good)
 # Int64.shift_right (-1L) 1;;
 - : int64 = -1L (Duh)

It is still possible to avoid the division, gcc generates this:
movq%rdi, %rax
shrq$63, %rax
addq%rdi, %rax
sarq%rax

Or a better example with division by 8:
leaq7(%rdi), %rax
testq   %rdi, %rdi
cmovns  %rdi, %rax
sarq$3, %rax

And division by non-power of two integers can optimized by replacing it
with multiplication with its inverse (which gcc and llvm don't do for
signed divisions, only for unsigned ones):
http://www.hackersdelight.org/HDcode/magic.c.txt
http://www.hackersdelight.org/HDcode/magicu.c.txt

Best regards,
--Edwin

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] [ANN] Js_of_ocaml version 1.0

2010-12-13 Thread Jerome Vouillon
Hi,

I'm happy to announce the first official release of Js_of_ocaml,
a compiler from OCaml bytecode to Javascript.

This tool let you write OCaml programs that run on Web browsers.

Js_of_ocaml is easy to install, and use thereafter, as it works with
an existing installation of OCaml, with no need to recompile any
library.  It comes with bindings for a large part of the browser APIs.

The project page is:   http://ocsigen.org/js_of_ocaml/

EXAMPLES

The compiler has been used to implement some noteworthy examples,
such as:
- an interactive 3D view of the Earth
http://ocsigen.org/js_of_ocaml/planet
- a graph viewer
http://ocsigen.org/js_of_ocaml/graph

PERFORMANCES

According to our benchmarks, with state of the art Javascript engines,
the generated programs runs typically faster than with the OCaml
bytecode interpreter ( http://ocsigen.org/js_of_ocaml/performances ).

Js_of_ocaml performs dead code elimination in order to generate
compact code: the Javascript file produced is usually smaller than
the input bytecode file, and often much smaller.

LINKS

Project home page  http://ocsigen.org/js_of_ocaml/
Download   http://ocsigen.org/download/js_of_ocaml-1.0.tar.gz
Get source codedarcs get http://ocsigen.org/darcs/js_of_ocaml/
Documentation  https://ocsigen.org/js_of_ocaml/lib/overview

FURTHER TECHNICAL DETAILS

Js_of_ocaml performs a fairly faithful translation.  The order of
evaluation is preserved.  Modular arithmetic is used for integers (but
with 32 bit integer).  It does not support tail calls (function calls
in tail position), as this would be too expansive.  However tail
recursion (self call in tail position) is properly optimized.

Explicit coercion functions can be used to convert Ocaml values to
Javascript values, and conversely (for instance, to map OCaml mutable
strings to Javascript immutable UTF-16 strings, or to map OCaml
booleans to Javascript booleans).  A Camlp4 syntax extension makes it
possible to invoke Javascript methods in a type safe way.

COMPARISON TO OCAMLJS

Ocamljs is a compiler from OCaml source code to Javascript.  Jake
Donham has written a fair comparison of the two tools:

  http://ambassadortothecomputers.blogspot.com/2010/08/ocamljs-03.html

Ocamljs is a back-end to the existing OCaml compiler.  Thus, contrary
to Js_of_ocaml, you need to perform a distinct installation of OCaml
to use Ocamljs, and you have to recompile all the libraries you may
need.

Ocamljs follows a different philosophy: it attempts to merge OCaml
datatypes with the corresponding Javascript datatypes.  For instance,
OCaml objects are implemented as Javascript objects.  Conversely,
Javascript objects are given an OCaml object type.  A mixed
representation of strings is used: mutable OCaml-style strings and
immutable Javascript strings both have the same type.  All this is
good for interoperability, but can be a source of incompatibilities
and can result in runtime errors not caught by the type checker.

Ocamljs optimizes tail recursion, but this comes at a large
performance cost.

--
Jerome Vouillon

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] [ANN] Js_of_ocaml version 1.0

2010-12-13 Thread Yitzhak Mandelbaum
Jerome,

Thank you, this sounds fantastic!  

One small question: could you expand on your last comment:

On Dec 13, 2010, at 8:06 AM, Jerome Vouillon wrote:

 snip
 
 Ocamljs optimizes tail recursion, but this comes at a large
 performance cost.

Do you mean all tail-calls come a large cost, or only those outside of plain 
tail-recursion?  Either way, could you give us some more intuition as to why 
this happens, and why js_of_ocaml doesn't suffer from the same problem 
(assuming it applies to tail-recursion)?

Thanks,
Yitzhak

-
Yitzhak Mandelbaum



___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] [ANN] Lwt 2.2.0 released

2010-12-13 Thread Jérémie Dimino
Hello,

The Lwt team is pleased to announce the release of Lwt 2.2.0. You can
download it at:

  http://ocsigen.org/lwt/install

Here is a list of changes from the previous version (2.1.1):

  * Bugfixes:
** Fix a bug with cancellable threads causing {{{Canceled}}}
   exceptions to be raised randomly
** Fix a fd-leak in Lwt_io.open_connection
  * {{{Lwt_unix}}} now use libev instead of select
  * Add thread local storage support to {{{Lwt}}}
  * Add backtrace support to {{{Lwt}}}. Now {{{Lwt}}} exceptions can
be recored by using the syntax extension with the {{{-lwt-debug}}}
command line switch.
  * Allow blocking system calls to be executed in parallels
  * Change the type of many functions of {{{Lwt_unix}}}, which now
return a {{{Lwt}}} thread
  * Add functions {{{Lwt_unix.readable}}} and {{{Lwt_unix.writable}}}
  * Add function {{{Lwt_io.is_busy}}}
  * Add functions {{{Lwt_event.delay}}} and {{{Lwt_signal.delay}}}
  * Add function {{{Lwt_term.render_update}}}
  * Add function {{{Lwt_ssl.embed_socket}}}
  * Add module {{{Lwt_bytes}}} defining operations on bigarrays
instead of strings
  * Use bigarrays in Lwt_io instead of strings for the internal buffer.
Lwt_io.make now takes a function that uses a bigarray.
  * Add module {{{Lwt_switch}}}

Enjoy!

-- 
Jérémie Dimino, on behalf of the Lwt team

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] [ANN] Js_of_ocaml version 1.0

2010-12-13 Thread Jerome Vouillon
On Mon, Dec 13, 2010 at 09:58:27AM -0500, Yitzhak Mandelbaum wrote:
 One small question: could you expand on your last comment:
 
 On Dec 13, 2010, at 8:06 AM, Jerome Vouillon wrote:
 
  snip
  
  Ocamljs optimizes tail recursion, but this comes at a large
  performance cost.
 
 Do you mean all tail-calls come a large cost, or only those outside
 of plain tail-recursion?  Either way, could you give us some more
 intuition as to why this happens, and why js_of_ocaml doesn't suffer
 from the same problem (assuming it applies to tail-recursion)?

I meant tail calls, indeed.  Tail recursion (when a function calls
itself recursively in tail position) can be optimized efficiently by
wrapping the function body inside a loop.  This is what Js_of_ocaml
does.

For optimizing tail calls in general, you need to use trampolines.
Instead of calling a function in tail position, you return this
function and its arguments.  Then, a piece of code called a trampoline
takes care of invoking repeately the functions it receives this way
until a final result is returned.  This is expansive.  You have to
make sure that this piece of code is there whenever a function is
invoked in tail position.  Also, the JIT compilers cannot optimize the
trampoline, as the functions it will have to call, and their number of
arguments, are unknown.

-- Jerome

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] [ANN] OBus 1.1

2010-12-13 Thread Jérémie Dimino
Hi,

I'm happy to announce the release 1.1 of OBus, a pure OCaml
implementation of the D-Bus protocol.

OBus aims to make it easy to use and provide D-Bus services in OCaml. It
can generate interfaces to D-Bus services from introspection files, it
provides integration of D-Bus methods, signals and properties to native
ocaml functions, mapping between D-Bus types and OCaml types, ... But it
is also possible to write low-level D-Bus application using OBus.

OBus is distributed with predefined OCaml interfaces to the following
services: Hal, NetworkManager, Popup notifications, PolicyKit, UDisks
and UPower.

Links:

Archive:
https://forge.ocamlcore.org/frs/download.php/539/obus-1.1.tar.gz
Project page:   https://forge.ocamlcore.org/projects/obus/
Manual: 
https://forge.ocamlcore.org/docman/view.php/26/127/manual.pdf
Api documentation:  http://obus.forge.ocamlcore.org/api/

Enjoy!

-- 
Jérémie

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


RE: [Caml-list] Re: optimize div to right shift (NOT!)

2010-12-13 Thread Jon Harrop
Edwin wrote:
 http://www.hackersdelight.org/HDcode/magic.c.txt
 http://www.hackersdelight.org/HDcode/magicu.c.txt

Nice! :-)

Cheers,
Jon.


___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs