From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id C615CBC37 for ; Sat, 22 Apr 2006 09:24:16 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k3M7OGkp026514 for ; Sat, 22 Apr 2006 09:24:16 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA17895 for ; Sat, 22 Apr 2006 09:24:15 +0200 (MET DST) Received: from pproxy.gmail.com (pproxy.gmail.com [64.233.166.176]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k3M49ZXK014063 for ; Sat, 22 Apr 2006 06:09:35 +0200 Received: by pproxy.gmail.com with SMTP id z74so624907pyg for ; Fri, 21 Apr 2006 21:09:35 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=SlhWwyPusoHRznrE0hjzmV2LagserkOjS94lkfWM5e3mc9edBrerIMXv4885B0sdaeX20S2nNP/gp1ApZC9RKs4oloDFAyE9Dsb+RBA/EZVusUrUcBF95aRgNXEK16cTSQXMu/Dry1gm1n/DqPpZadZrmkULLUZvN8nV9hGk488= Received: by 10.35.78.13 with SMTP id f13mr2689113pyl; Fri, 21 Apr 2006 21:09:35 -0700 (PDT) Received: by 10.35.62.11 with HTTP; Fri, 21 Apr 2006 21:09:34 -0700 (PDT) Message-ID: Date: Sat, 22 Apr 2006 00:09:34 -0400 From: "Michael Benfield" Subject: Re: [Caml-list] What's "advantage of gcc-specific features"? Cc: caml-list@inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <444988BF.3070905@sun.com> X-Miltered: at nez-perce with ID 4449DA20.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4449AC7F.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; gcc-specific:01 gcc:01 gcc:01 compiler:01 speedup:01 fuller:98 naci:98 caml-list:01 arbitrary:01 meaningless:01 integer:01 integer:01 ptr:02 ptr:02 represented:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 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.