caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Travis Bemann <bemann@execpc.com>
To: Nicolas Cannasse <warplayer@free.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Caml productivity.
Date: Tue, 30 Jul 2002 00:46:38 -0400	[thread overview]
Message-ID: <20020730004638.C703@execpc.com> (raw)
In-Reply-To: <008801c236d7$d285d550$0700a8c0@warp>; from warplayer@free.fr on Mon, Jul 29, 2002 at 10:13:24AM +0200

[-- Attachment #1: Type: text/plain, Size: 4015 bytes --]

On Mon, Jul 29, 2002 at 10:13:24AM +0200, Nicolas Cannasse wrote:
> > I agree that the C interface is pretty nice. However,
> > how do would you use SIMD math instructions on the
> > x86? Would you always call C-routines just to make use
> > of SIMD or multimedia-instructions? What is the
> > overhead for calling a function that is executing a
> > few assembly instructions? Is it even possible to
> > create a solid division line between "low-level" and
> > "high-level" code?
>
> Yes it is.
> Actually if you need to perform alot of SIMD instructions each frame
> (involving zounds of C calls), you can try to group them in one-C-call that
> will do the job in one time. That's matter of architecture and choices...
> not always obvious :)

Note that most C or C++ compilers won't do this either, with the
exception of some specialized vector parallelizing compilers (such as
those used to compile code on vector supercomputers).  If you really
need SIMD instructions, you'd probably need to hand-code it in
assembly, no matter what language you're using.

> > There's something to be said for premature
> > optimizations, but don't you think there's something
> > to be gained from having inline assembly in O'Caml? In
> > C++, one can create inline SIMD floating point vector
> > operations. A.I. and behaviour code constantly use 3D
> > math that would benefit from inline assembly.
>
> I don't think OCaml is the best language for that kind of things...
> If I remember my Pascal days, the compiler was so bad that i was used to
> write asm code directly in Pascal functions to perform all the 2DFx job :)
> And even if I enjoyed it because of the great perfs, it's not a good way of
> programming.
>
> If you're using OCaml as a top-level scripting langage, you have to put some
> barriers on what you can or can't do. Doing alot of "low-level" instructions
> needing SIMD optimizations is not the job of a scripting langage. So if you
> really need to do them, just move them into a C proc. OCaml code is actually
> only doing the following in my implementation :
> - moving the Camera
> - handling events ( network messages and user mouse/keyb ones )
> - setting meshes current position and animation
> - same for sprites

Well, according to some rather large sets of benches, code natively
compiled with OCaml 3.04 is often faster than C++ code compiled with
gcc 3.0 (on x86), and a number of 3D games are written in C++, such as
bzflag. And from my experience, bzflag has no speed problems
whatsoever, with 20 AI players all running on the same machine, and
I'm using gcc 2.9-sometyhing, which has far *worse* C++ compilation
(both support and performance-wise) than gcc 3.0.

Therefore, I would think that it would be safe to conclude that
anything in userspace that you can really use C++ for you can use
OCaml for (with the one exception of directly manipulating shared
memory).  And if C++ isn't fast enough, then either your machine is
too slow for the load OR the problem isn't the language, per se, but
rather your algorithms and implementation.  If you aren't doing
embedded programming (or doing something such as original PlayStation
programming), yet feel yourself needing to use hand-optimized C or
assembly for most of your code, you're probably doing something wrong,
whether it's trying to do too much in realtime or it's doing a very
algorithmically inefficient implemntation.  Try to use faster/more
scalable algorithms before you really decided that hand-coded C or
assembly is the only way.  And even still, only use hand-coded C or
assembly at points where it is critical.

(Note: I had earlier accidentally CCed this back to myself, rather
than to caml-list)

-- 
Yes, I know my enemies.
They're the teachers who tell me to fight me.
Compromise, conformity, assimilation, submission, ignorance,
hypocrisy, brutality, the elite.
All of which are American dreams.

              - Rage Against The Machine

[-- Attachment #2: Type: application/pgp-signature, Size: 3104 bytes --]

  reply	other threads:[~2002-07-30  5:46 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-15 21:22 Pal-Kristian Engstad
2002-07-20 15:16 ` William Chesters
2002-07-22 18:22   ` Pal-Kristian Engstad
2002-07-22 18:41     ` achrist
2002-07-22 19:23       ` Pal-Kristian Engstad
2002-07-22 21:13         ` [Caml-list] CamlIDL and function pointers Michael Tucker
2002-07-23  8:39           ` Xavier Leroy
2002-07-23 13:11             ` Dmitry Bely
2002-07-24 15:00             ` Michael Tucker
2002-07-25  9:36               ` Xavier Leroy
2002-07-22 21:26     ` Games (Re: [Caml-list] Caml productivity.) Oleg
2002-07-23  2:56       ` Issac Trotts
2002-07-23 11:03         ` eijiro_sumii
2002-07-23 16:17           ` Charles Martin
2002-07-29  3:36           ` Andrei de A. Formiga
2002-07-29  6:32             ` Florian Hars
2002-07-29 10:23             ` eijiro_sumii
     [not found]               ` <001901c237a7$9e685920$890bfea9@mimbi>
2002-07-30  4:52                 ` eijiro_sumii
2002-07-30 18:13                   ` Jonathan Coupe
2002-07-30  6:16                     ` eijiro_sumii
2002-08-01 15:39                     ` John Max Skaller
2002-08-01 15:59                       ` Markus Mottl
2002-08-01 16:28                       ` Jonathan Coupe
     [not found]                         ` <86vg6ta9o6.fsf@laurelin.dementia.org>
2002-08-02 12:50                           ` Jonathan Coupe
2002-08-02 14:51                         ` John Max Skaller
2002-07-25  3:19       ` Chris Hecker
2002-07-28 13:45         ` Jonathan Coupe
2002-07-29  0:57           ` Michael Vanier
2002-07-22 22:00     ` [Caml-list] Caml productivity Alexander V.Voinov
2002-07-20 15:25 ` Oleg
2002-07-22  6:41 ` Tom
2002-07-22 10:46 ` Nicolas Cannasse
2002-07-22 17:46   ` Pal-Kristian Engstad
2002-07-24  3:20     ` Travis Bemann
2002-07-24  9:45       ` Pal-Kristian Engstad
2002-07-26 21:42         ` Chris Hecker
2002-07-27  4:41           ` Issac Trotts
2002-07-27  5:49             ` Chris Hecker
2002-07-27 14:49               ` John Max Skaller
2002-07-27  9:06           ` Oleg
2002-07-27 18:18             ` Chris Hecker
2002-07-29  8:13         ` Nicolas Cannasse
2002-07-30  4:46           ` Travis Bemann [this message]
2002-07-24  8:02     ` Nicolas Cannasse
2002-07-24  8:25       ` Jérôme Marant
2002-07-24 10:00       ` Pal-Kristian Engstad
2002-07-27  9:06         ` Oleg
2002-07-23  2:08 Arturo Borquez

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=20020730004638.C703@execpc.com \
    --to=bemann@execpc.com \
    --cc=caml-list@inria.fr \
    --cc=warplayer@free.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).