gcl-devel
[Top][All Lists]
Advanced

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

Re: [Gcl-devel] Error compiling functions w/ (declare (integer x)) pres


From: Camm Maguire
Subject: Re: [Gcl-devel] Error compiling functions w/ (declare (integer x)) present
Date: 08 Jun 2002 12:09:14 -0400

OK, I've checked in the fix for this.  avma seems to be a pari only
thing.

I the process I've located and fixed, I hope, the segfault I saw, as
well as reimplemented the declare integer to be more in line with what
Dr. Schleter was originally doing, and alluded to in doc/bignum.

1) One cannot use mpz_init, for example, without wrapping the allocated
   space in a lisp object as done in new_bignum(), lest the garbage
   collector hose the space.  this is so even though mpz_init uses
   alloc_contblock to allocate -- apparently the gc walks through
   objects to get to the contblocks.  For future reference.  again,
   this is only to the best of my understanding.

2) The bottleneck in bignum calculations appeared to be gc in
   Dr. Schelter's analysis, so he arranged to have the integer
   declaration bypass the lisp memory management and alloca sufficient
   space for the bignum temporarily on the function C stack.  I've
   followed suit, and noticed that it does reduce gc calls.  But in
   the example given in doc/bignum, gc is not eliminated, as internal
   functions in gmp_big.c and pari_big.c called after the integer
   declaration do in turn allocate lisp objects.  Maybe in the future
   we could enhance performance by using alloca here as well.

3) Right now, you must have alloca if you use gmp.  From my
   understanding, everyone does, but if this becomes a problem, we can
   code the non-alloca case as well.

4) The pi-inv example in doc/bignum works, as does the max0 function
   in R. Toy's f2cl-lib.lsp.

5) Please let me know if clx compiles

6) As the avma stuff is truly a bug, I'm going to release 2.4.3
   quickly.  If other items surface, 2.4.4 will similarly follow
   shortly if I have time -- I think it important to leave the
   official release without known bugs as quickly as possible. 

Take care,




John Jorgensen <address@hidden> writes:

> Well, CLX gets further in it's compile, but now with the example in the
> bignum docs, I get the error;
> =========================
> >(compile 'pi-inv)
> 
> Compiling gazonk0.lsp.
> End of Pass 1.  
> End of Pass 2.  
> gazonk0.c: In function `L1':
> gazonk0.c:4139: `save_avma' undeclared (first use in this function)
> gazonk0.c:4139: (Each undeclared identifier is reported only once
> gazonk0.c:4139: for each function it appears in.)
> gazonk0.c:4140: `restore_avma' undeclared (first use in this function)
> 
> Correctable error: (SYSTEM "(cd . ;gcc -pipe -fwritable-strings
> -DVOL=volatile -I/home/jjorgens/gcl/o -fsigned-char  -O -c -I. gazonk0.c
> -w)") returned a non-zero value 0.
> Signalled by UNLESS.
> If continued: Continues anyway.
> Broken at CERROR.  Type :H for Help.
> >>
> =========================
> Whatever the heck a avma is... CLX stops with the same type of error
> (save_avma undeclared).
> 
> J*
> 
> -------------------
> On 7 Jun 2002, Camm Maguire wrote:
> 
> > Greetings!  OK, I've committed a fix for this.  Please check it out.
> > And R.Toy, if you're listening, you should be able to uncomment
> > (declare (integer... too.
> > 
> > The solution I've implemented doesn't seem very optimal, but rather
> > uses the existing integer/bignum handling macros that were in place
> > for pari support and the original custom mp support.  The lisp
> > compiler spits out these C macros, and I'm far less comfortable
> > modifying the lisp compiler code.  
> > 
> > I thought declarations were supposed to help the compiler.  But all it
> > seems that they accomplish is the copying of integer data back and
> > forth needlessly.
> > 
> > Consider:
> > 
> > (defun max0 (x y &rest z)
> >   (declare (integer x y))
> >   (apply #'max x y z))
> > 
> > Here is the C code without the declaration :
> > 
> >     {object V1;
> >     object V2;
> >     object V3;
> >     V1=(base[0]);
> >     V2=(base[1]);
> >     vs_base=vs_base+2;
> >     vs_top[0]=Cnil;
> >     {object *p=vs_top;
> >      for(;p>vs_base;p--)p[-1]=MMcons(p[-1],p[0]);}
> >     V3=(base[2]);
> >     vs_top=sup;
> >     base[3]= (V1);
> >     base[4]= (V2);
> >     {object V4;
> >     V4= (V3);
> >      vs_top=base+5;
> >      while(V4!=Cnil)
> >      {vs_push((V4)->c.c_car);V4=(V4)->c.c_cdr;}
> >     vs_base=base+3;}
> >     Lmax();
> >     return;
> >     }
> > 
> > 
> > 
> > And here is the code with the declaration:
> > 
> > 
> > 
> >     {IDECL(GEN V1,V1space,V1alloc);
> >     IDECL(GEN V2,V2space,V2alloc);
> >     object V3;
> >     SETQ_IO(V1,V1alloc,(base[0]));
> >     SETQ_IO(V2,V2alloc,(base[1]));
> >     vs_base=vs_base+2;
> >     vs_top[0]=Cnil;
> >     {object *p=vs_top;
> >      for(;p>vs_base;p--)p[-1]=MMcons(p[-1],p[0]);}
> >     V3=(base[2]);
> >     vs_top=sup;
> >     base[3]= make_integer(V1);
> >     base[4]= make_integer(V2);
> >     {object V4;
> >     V4= (V3);
> >      vs_top=base+5;
> >      while(V4!=Cnil)
> >      {vs_push((V4)->c.c_car);V4=(V4)->c.c_cdr;}
> >     vs_base=base+3;}
> >     Lmax();
> >     return;
> >        }
> > 
> > 
> > What do we gain here, considering that we have to go back to objects
> > anyway when calling Lmax?
> > 
> > Take care,
> > 
> > 
> > John Jorgensen <address@hidden> writes:
> > 
> > > When I try to compile functions that declare integers, I get errors. They
> > > interpret just fine, but they don't compile. here is an example;
> > > ====================================
> > > (defun pi-inv (bits &aux (m 0))
> > >   (declare (integer bits m))
> > >   (let* ((n (+ bits (integer-length bits) 11))
> > >          (tt (truncate (ash 1 n) 882))
> > >          (d (* 4 882 882))
> > >          (s 0))
> > >     (declare (integer s d tt n))
> > >     (do ((i 2 (+ i 2))
> > >          (j 1123 (+ j 21460)))
> > >         ((zerop tt) (cons s (- (+ n 2))))
> > >       (declare (integer i j))
> > >         (setq s (+ s (* j tt))
> > >               m (- (* (- i 1) (- (* 2 i) 1) (- (* 2 i) 3)))
> > >               tt (truncate (* m tt) (* d (the integer (expt i 3))))))))
> > > ==========================
> > > 
> > > Right from the bugnum examples in the GCL documentation. running
> > > (compile 'pi-inv) produces the following errors;
> > > ==========================
> > > >(compile 'pi-inv)
> > > 
> > > Compiling gazonk1.lsp.
> > > End of Pass 1.  
> > > End of Pass 2.  
> > > gazonk1.c: In function `L1':
> > > gazonk1.c:3002: `GEN' undeclared (first use in this function)
> > > gazonk1.c:3002: (Each undeclared identifier is reported only once
> > > gazonk1.c:3002: for each function it appears in.)
> > > gazonk1.c:3002: parse error before `V1'
> > > gazonk1.c:3004: `V1' undeclared (first use in this function)
> > > gazonk1.c:3004: `V1alloc' undeclared (first use in this function)
> > > gazonk1.c:3007: parse error before `register'
> > > gazonk1.c:3008: `V2' undeclared (first use in this function)
> > > gazonk1.c:3008: `V2alloc' undeclared (first use in this function)
> > > gazonk1.c:3009: parse error before `register'
> > > gazonk1.c:3010: parse error before `register'
> > > gazonk1.c:3011: parse error before `V5'
> > > gazonk1.c:3012: parse error before `register'
> > > gazonk1.c:3023: `save_avma' undeclared (first use in this function)
> > > gazonk1.c:3024: `V3' undeclared (first use in this function)
> > > gazonk1.c:3024: `V3alloc' undeclared (first use in this function)
> > > gazonk1.c:3024: `restore_avma' undeclared (first use in this function)
> > > gazonk1.c:3036: `V4' undeclared (first use in this function)
> > > gazonk1.c:3036: `V4alloc' undeclared (first use in this function)
> > > gazonk1.c:3044: `V5' undeclared (first use in this function)
> > > gazonk1.c:3044: `V5alloc' undeclared (first use in this function)
> > > gazonk1.c:3045: `V6' undeclared (first use in this function)
> > > gazonk1.c:3045: `V6alloc' undeclared (first use in this function)
> > > gazonk1.c:3046: parse error before `register'
> > > gazonk1.c:3047: parse error before `register'
> > > gazonk1.c:3048: `V7' undeclared (first use in this function)
> > > gazonk1.c:3048: `V7alloc' undeclared (first use in this function)
> > > gazonk1.c:3049: `V8' undeclared (first use in this function)
> > > gazonk1.c:3049: `V8alloc' undeclared (first use in this function)
> > > 
> > > Correctable error: (SYSTEM "(cd . ;gcc -pipe -fwritable-strings
> > > -DVOL=volatile -I/opt/dl/gcl/o -fsigned-char  -O -c -I. gazonk1.c
> > > -w)") returned a non-zero value 0.
> > > Signalled by UNLESS.
> > > If continued: Continues anyway.
> > > Broken at CERROR.  Type :H for Help.
> > > >>
> > > ============================
> > > 
> > > If I remove the declares, it compiles just fine. It looks like this is
> > > what is keeping CLX from compiling. GEN looks like it's supposed to be a
> > > long, but I'm not sure.
> > > 
> > > J*
> > > 
> > > 
> > > _______________________________________________
> > > Gcl-devel mailing list
> > > address@hidden
> > > http://mail.gnu.org/mailman/listinfo/gcl-devel
> > > 
> > > 
> > 
> > 
> 
> 
> 

-- 
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]