caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Michael Benfield" <mike.benfield@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] What's "advantage of gcc-specific features"?
Date: Sat, 22 Apr 2006 00:09:34 -0400	[thread overview]
Message-ID: <b7be7780604212109h6bce7c69u8f687e20dad4d53e@mail.gmail.com> (raw)
In-Reply-To: <ad8cfe7e0604211846l6b43b034sa656f10b6f280041@mail.gmail.com>

In case Mr. Roewen's reply was too terse or if you don't know much
about virtual machine implementation (not that I do...), here is a
fuller explanation of why the interepreter can be faster in GCC:

In GCC, unlike standard C, you can take the address of a goto label as
described here:

http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Labels-as-Values.html#Labels-as-Values

So whereas normally in a C implementation you would do something like this:

start:
switch(*ptr) {
  case INSTRUCTION_1:
    do_stuff();
    ptr++;
    goto start;
  case INSTRUCTION_2:
    do_stuff2();
    ptr++;
    goto start;
  /* ... etc ... */
}

That is, each instruction for the virtual machine is represented as an
otherwise meaningless integer and you have to do a switch statement
for each one, and however your C compiler optimizes that, is what you
get. On the other hand, if you can take the address of a label, you
can go through the virtual machine instructions and replace each
arbitrary integer instruction with the address of a goto label
corresponding to that instruction. Then you can do this:

instruction_1:
  do_stuff();
  ptr++;
  goto *ptr;
instruction_2:
  do_stuff2();
  ptr++;
  goto *ptr;
  /* ... etc ... */

Since this provides a speedup for every VM instruction, it's quite a boost.

I think it's rather unfortunate this is not part of standard C.


  reply	other threads:[~2006-04-22  7:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-22  1:37 Yu-Hui Liu
2006-04-22  1:46 ` [Caml-list] " Jonathan Roewen
2006-04-22  4:09   ` Michael Benfield [this message]
2006-04-22  9:47 ` David MENTRE
2006-04-22 16:14   ` John Carr
2006-04-22 23:15     ` Erik de Castro Lopo
2006-04-23 12:27       ` David MENTRE
2006-04-23 16:43         ` Xavier Leroy

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=b7be7780604212109h6bce7c69u8f687e20dad4d53e@mail.gmail.com \
    --to=mike.benfield@gmail.com \
    --cc=caml-list@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).