caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Ocamlopt x86-32 and SSE2
Date: Tue, 12 May 2009 11:37:17 +0200	[thread overview]
Message-ID: <4A09434D.3020102@inria.fr> (raw)
In-Reply-To: <B1CD096B-910F-41B7-BBE8-5F2EA0DB49AF@cea.fr>

This is an interesting discussion with many relevant points being
made.  Some comments:

Matteo Frigo:
> Do you guys have any sort of empirical evidence that scalar SSE2 math is
> faster than plain old x87?
> I ask because every time I tried compiling FFTW with gcc -m32
> -mfpmath=sse, the result has been invariably slower than the vanilla x87
> compilation.  (I am talking about scalar arithmetic here.  FFTW also
> supports SSE2 2-way vector arithmetic, which is of course faster.)

gcc does rather clever tricks with the x87 float stack and the fxch
instruction, making it look almost like a flat register set and
managing to expose some instruction-level parallelism despite the
dependencies on the top of the stack.  In contrast, ocamlopt uses the
x87 stack in a pedestrian, reverse-Polish-notation way, so the
benefits of having "real" float registers is bigger.

Using the experimental x86-sse2 port that I did in 2003 on a Core2
processor, I see speedups of 10 to 15% on my few standard float
benchmarks.  However, these benchmarks were written in such a way that
the generated x87 code isn't too awful.  It is easy to construct
examples where the SSE2 code is twice as fast as x87.

More generally, the SSE2 code generator is much more forgiving towards
changes in program style, and its performance characteristics are more
predictable than the x87 code generator.  For instance, manual
elimination of common subexpressions is almost always a win with SSE2
but quite often a loss with x87 ...

Pascal Cuoq:
> According to http://en.wikipedia.org/wiki/SSE2, someone using a Via C7
> should be fine.

Richard Jones:
> AMD Geode then ...

Apparently, recent versions of the Geode support SSE2 as well.
Low-power people love vector instruction sets, because it lets them do
common tasks like audio and video decoding more efficiently, ergo with
less energy.

Sylvain Le Gall:
> If INRIA choose to switch to SSE2 there should be at least still a way
> to compile on older architecture. Doesn't mean that INRIA need to keep
> the old code generator, but should provide a simple emulation for it. In
> this case, we will have good performance on new arch for float and we
> will still be able to compile on old arch. 

The least complicated way to preserve backward compatibility with
pre-SSE2 hardware is to keep the existing x87 code generator and bolt
the SSE2 generator on top of it, Frankenstein-style.  Well, either
that, or rely on the kernel to trap unimplemented SSE2 instructions
and emulate them in software.  This is theoretically possible but I'm
pretty sure neither Linux nor Windows implement it.

David Mentre:
> Regarding option 2, I assume that byte-code would still work on i386
> pre-SSE2 machines? So OCaml programs would still work on those machines.

You're correct, provided the bytecode interpreter isn't compiled in
SSE2 mode itself (see below for one reason one might want to do this).
However, packagers would still be unhappy about this: packaged OCaml
applications like Unison or Coq are usually compiled to native-code
(the additional speed is most welcome in the case of Coq...).
Therefore, packagers would have to choose between making these
applications SSE2-only or make them slower by compiling them to bytecode.

Dmitry Bely:
> [Reproducibility of results between bytecode and native]
> I wouldn't be so sure. Bytecode runtime is C compiler-dependent (that
> does use x87 for floating-point calculations), so rounding errors can
> lead to different results.

That's right: even though it stores all intermediate float results in
64-bit format, a bytecode interpreter compiled in default x87 mode still
exhibits double rounding anomalies.  One would have to compile it with
gcc in SSE2 mode (like MacOS X does by default) to have complete
reproducibility between bytecode and native.

> Floating point is always approximate...

I used to believe strongly in this viewpoint, but after discussion
with people who do static analysis or program proof over float
programs, I'm not so sure: static analysis and program proof are
difficult enough that one doesn't want to complicate them even further
to take extended-precision intermediate results and double rounding
into account...

To finish: I'm still very interested in hearing from packagers.  Does
Debian, for example, already have some packages that are SSE2-only?
Are these packages specially tagged so that the installer will refuse
to install them on pre-SSE2 hardware?  What's the party line?

- Xavier Leroy


  reply	other threads:[~2009-05-12  9:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090511043120.976EBBC67@yquem.inria.fr>
2009-05-11  7:10 ` Pascal Cuoq
2009-05-12  9:37   ` Xavier Leroy [this message]
2009-05-12 10:04     ` Sylvain Le Gall
2009-05-25  8:23       ` Sylvain Le Gall
2009-05-12 12:40     ` [Caml-list] " Richard Jones
2009-05-13 22:30     ` Florian Weimer
     [not found] <20090509100004.353ADBC5C@yquem.inria.fr>
2009-05-09 11:38 ` CUOQ Pascal
2009-05-10  1:52   ` [Caml-list] " Goswin von Brederlow
2009-05-10  2:16     ` Seo Sanghyeon
2009-05-10  3:50       ` Jon Harrop
2009-05-11  8:05         ` Dmitry Bely
2009-05-11  9:26           ` Jon Harrop
2009-05-11  8:43             ` Dmitry Bely
2009-05-11 13:47               ` Jon Harrop
2009-05-11  9:12             ` Andrey Riabushenko
2009-05-10  8:56     ` CUOQ Pascal
2009-05-10 14:47       ` [Caml-list] " Richard Jones
2009-05-10 19:25     ` Florian Weimer
2009-04-28 19:36 Ocamlopt code generator question Dmitry Bely
2009-05-05  9:24 ` [Caml-list] " Xavier Leroy
2009-05-05  9:41   ` Dmitry Bely
2009-05-08 10:21     ` [Caml-list] Ocamlopt x86-32 and SSE2 Xavier Leroy
2009-05-10 11:04       ` David MENTRE
2009-05-11  2:43         ` Jon Harrop
2009-05-10 23:12       ` Matteo Frigo
2009-05-11  2:45         ` Jon Harrop
2009-05-11  7:55       ` Dmitry Bely

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=4A09434D.3020102@inria.fr \
    --to=xavier.leroy@inria.fr \
    --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;
as well as URLs for NNTP newsgroup(s).