On Tue, 14 Dec 2004, Harvey J. Stein wrote:

> I've read Fateman's paper before, but I missed the Coyote Gulch
> discussion.  I just finished reading it, but was a little surprised at
> the approach taken.
> 
> For example, why were macros used to convert things like:
>    (* a b)
> to
>    (the 'double-float (* (the 'double-float a) (the 'double-float b)))?

You might want to have a look at my with-arith-defs macro. (Just google for it.)

> Added a declaration after the definition of s helps.  The following
> doesn't generate any notes:
> 
>    (defun sumn (n)
>      (declare (type (integer 0 10000) n))
>      (let ((s 0))
>        (declare (type (integer 0 200000000) s))
>        (dotimes (i n)
>          (incf s i))
>        s))

Uh, shouldn't i be declared fixnum as well?

> So far, so good.  However, before running to try this in my code, I
> wanted to see what would happen if I tried to make a double-float
> version of sumn:
> 
>    (defun sumn (n)
>      (declare (type (integer 0 10000) n)
>               (values double-float))
>      (let ((s 0d0))
>        (declare (type double-float s))
>        (dotimes (i n)
>          (incf s i))
>        s))
> 
> Surprisingly, now I get a compiler note:

>    Note: Doing float to pointer coercion (cost 13) from S to "<return value>".
>
> Why do I get no notes on the fixnum version, but get a cost 13 float
> to pointer coercion in the double-float version?

A fixnum is just an ordinary 32-bit value whose type tag in the two 
lowestmost bits is 00. A floatingpoint value cannot be represented as a 
32-bit value, hence has to be boxed - the function will return a pointer 
to a freshly consed number.

Just thinking about it, I wonder if it would work to not return a number, 
but pass it on to an extra continuation argument. I don't think the 
compiler supports tricks to do the proper optimizations in such situations 
right now, or does it?

-- 
regards,               [EMAIL PROTECTED]              (o_
 Thomas Fischbacher -  http://www.cip.physik.uni-muenchen.de/~tf  //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y)           V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1))                  (Debian GNU)

Reply via email to