gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] Re: Multiple values and gethash


From: Camm Maguire
Subject: [Gcl-devel] Re: Multiple values and gethash
Date: 23 Sep 2004 13:33:10 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings, and thanks for the feedback!

I believe the dead code in this example is removed by the C compiler in
the resulting assembler (also displayed with disassemble via
objdump).  Perhaps it could be removed at the C level as well, but
there are definitely instances in which this section is not dead,
which would mean we'd have to be smart enough at the lisp level to
tell the difference.

Consider the 'disassemblys' of the following two functions:

(defun foo (x y)
   (multiple-value-bind (ans ans-p) (or (bas) (gethash  x y))
      (cond (ans-p (bar ans))
            (t (fap x y)))))

(defun foo (x y)
   (multiple-value-bind (ans ans-p) (or (gethash  x y) (bas))
      (cond (ans-p (bar ans))
            (t (fap x y)))))

In the latter, pulling the values of the value stack is required, as
one knows nothing about (bas).  Note also that with the former
function's output assembly, gcc has eliminated the branches
corresponding to the value stack retrieval, but not in the latter's.  

So in sum, I think you are not getting the dead code in practice.  In
general, gcl tries to chew up the lisp just enough for gcc to do a
good job at the heavier lifting.  If we could convince ourselves that
at most one such value stack examination would be necessary, we could
move it right after the (bas) function call so that it would not even
appear in the C when (bas) is not present, but perhaps this only has
clarification value.

Please let me know if I am missing something.

Take care,

Robert Boyer <address@hidden> writes:

> Hi Camm,
> 
> Here is a minor comment about possible dead code being generated by
> the new inlining facility for gethash.
> 
> Consider the function
> 
> (defun foo (x y)
>    (multiple-value-bind (ans ans-p) (gethash  x y)
>       (cond (ans-p (bar ans))
>             (t (fap x y)))))
> 
> The c code generated when this is compiled in gcl-2.6.5hi includes the
> following, but it seems that the code from the first "goto T3" down to label
> "T3:" never gets executed.  Sort of looks like old value stack stuff that is
> no longer relevant since gethash is called in-line.
> 
>    #include "foo.h"
>    void init_code(){do_init(VV);}
>    /* function definition for FOO     */
> 
>    static void L1()
>    {register object *base=vs_base;
>          register object *sup=base+VM1; VC1
>          vs_check;
>          {object V1;
>          object V2;
>          V1=(base[0]);
>          V2=(base[1]);
>          vs_top=sup;
>          goto TTL;
>    TTL:;
>          {object V3;
>          object V4;
>          V3= ({struct htent *_t=gethash((V1),(V2)); _t->hte_key==OBJNULL ? ({
>          V4= Cnil;Cnil;}) : ({
>          V4= Ct;_t->hte_value;});});
>          vs_top=sup;goto T3;
>          if(vs_base>=vs_top){vs_top=sup;goto T1;}
>          V3= vs_base[0];
>          vs_base++;
>          if(vs_base>=vs_top){vs_top=sup;goto T2;}
>          V4= vs_base[0];
>          vs_top=sup;goto T3;
>          goto T1;
>    T1:;
>          V3= Cnil;
>          goto T2;
>    T2:;
>          V4= Cnil;
>          goto T3;
>    T3:;
>          if(((V4))==Cnil){
>          goto T6;}
>          base[2]= (V3);
>          vs_top=(vs_base=base+2)+1;
>          (void) (*Lnk0)();
>          return;
>          goto T6;
>    T6:;
>          base[2]= (V1);
>          base[3]= (V2);
>          vs_top=(vs_base=base+2)+2;
>          (void) (*Lnk1)();
>          return;}
>          }
>    }
> 
> Warren and Bob
> 
> 
> 

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]