From: Didier Verna
Subject: ACL: where does this single-float box come from ?
Date: 
Message-ID: <mux4q19y1yv.fsf@uzeb.lrde.epita.fr>
        Hi !

Consider the following code:


(declaim (optimize (speed 3)
		   (compilation-speed 0)
		   (safety 0)
		   (debug 0)))

(defun assign (arr val)
  (declare (:explain :boxing))
  (declare (type (simple-array single-float (* *)) arr))
  (declare (type single-float val))
  (let ((size (* (array-dimension arr 0)
		 (array-dimension arr 0))))
    (dotimes (i size)
      (setf (row-major-aref arr i) (+ (row-major-aref arr i) val)))))


The Allegro compiler says it's generating a single-float box. Only I can't
figure out where and why. Can somebody enlighten me ?


Thanks !


-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org

From: Pascal Bourguignon
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <87r74dfkat.fsf@thalassa.informatimago.com>
Didier Verna <······@lrde.epita.fr> writes:

>         Hi !
>
> Consider the following code:
>
>
> (declaim (optimize (speed 3)
> 		   (compilation-speed 0)
> 		   (safety 0)
> 		   (debug 0)))
>
> (defun assign (arr val)
>   (declare (:explain :boxing))
>   (declare (type (simple-array single-float (* *)) arr))
>   (declare (type single-float val))
>   (let ((size (* (array-dimension arr 0)
> 		 (array-dimension arr 0))))
>     (dotimes (i size)
>       (setf (row-major-aref arr i) (+ (row-major-aref arr i) val)))))
>
>
> The Allegro compiler says it's generating a single-float box. Only I can't
> figure out where and why. Can somebody enlighten me ?

I know nothing about optimization, but I'd write:

   (let ((size (* (array-dimension arr 0)
                  (array-dimension arr 1)))) ; 1!
     (dotimes (i size)
       (setf (row-major-aref arr i) (the single-float
                                       (+ (row-major-aref arr i) val)))))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
From: Christophe Rhodes
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <sq64lpjrdr.fsf@cam.ac.uk>
Pascal Bourguignon <······@informatimago.com> writes:

> I know nothing about optimization, but I'd write:
>
>    (let ((size (* (array-dimension arr 0)
>                   (array-dimension arr 1)))) ; 1!

I think I'd prefer (array-total-size arr) ;-)

Christophe
From: Didier Verna
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <muxr74dweop.fsf@uzeb.lrde.epita.fr>
Pascal Bourguignon <······@informatimago.com> wrote:

>> (defun assign (arr val)
>>   (declare (:explain :boxing))
>>   (declare (type (simple-array single-float (* *)) arr))
>>   (declare (type single-float val))
>>   (let ((size (* (array-dimension arr 0)
>> 		 (array-dimension arr 0))))
>>     (dotimes (i size)
>>       (setf (row-major-aref arr i) (+ (row-major-aref arr i) val)))))
>>
>>
>> The Allegro compiler says it's generating a single-float box. Only I can't
>> figure out where and why. Can somebody enlighten me ?
>
> I know nothing about optimization, but I'd write:
>
>    (let ((size (* (array-dimension arr 0)
>                   (array-dimension arr 1)))) ; 1!

                    Don't worry. I have square arrays ;-)

>      (dotimes (i size)
>        (setf (row-major-aref arr i) (the single-float
>                                        (+ (row-major-aref arr i) val)))))

        Been there, done that. But I think single-float + single-float is
always a single-float (contrary to fixnums for instance). BTW, CMU-CL doesn't
complain about this "missing" declaration either, and even in the fixnum case. 
My assumption is that since setf applies to an array that is properly declared
as containing fixnums (or floats) only, the compiler has enough information to
deduce that no arithmetic overflow is expected in the addition.


-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org
From: Frank Buss
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <1gf8dqmpgkrf8$.1bh13uvpgg11j.dlg@40tude.net>
Didier Verna wrote:

>         Been there, done that. But I think single-float + single-float is
> always a single-float (contrary to fixnums for instance). 

in LispWorks:

CL-USER > (+ most-positive-single-float most-positive-single-float)
+1D++0 #| +1D++0 is double-float plus-infinity |#

(looks like single-float, long-float and double-float is the same in
LispWorks)

-- 
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Didier Verna
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <muxhd59wdjx.fsf@uzeb.lrde.epita.fr>
Frank Buss <··@frank-buss.de> wrote:

> Didier Verna wrote:
>
>>         Been there, done that. But I think single-float + single-float is
>> always a single-float (contrary to fixnums for instance).
>
> in LispWorks:
>
> CL-USER > (+ most-positive-single-float most-positive-single-float)
> +1D++0 #| +1D++0 is double-float plus-infinity |#
>
> (looks like single-float, long-float and double-float is the same in
> LispWorks)

        Hmmm. I though you always ended up with a single-float (loosing
precision) because of the way floating point calculation are done, but:

CL-USER> (+ most-positive-single-float most-positive-single-float)
; Evaluation aborted

Arithmetic error FLOATING-POINT-OVERFLOW signalled.
   [Condition of type FLOATING-POINT-OVERFLOW]

Restarts:
  0: [ABORT-REQUEST] Abort handling SLIME request.
  1: [ABORT] Return to Top-Level.

Backtrace:
  0: (X86:SIGFPE-HANDLER #<#1=unused-arg> #<#1#> #.(SYSTEM:INT-SAP #x3FFFBD70))
  1: ("call_into_lisp+#x8C [#x8054CFC] /usr/bin/lisp")
  2: ("funcall3+#x32 [#x8054B0A] /usr/bin/lisp")
  3: ("interrupt_handle_now+#xFA [#x80502C4] /usr/bin/lisp")
  4: ("interrupt_handle_now_handler+#x43 [#x80501C8] /usr/bin/lisp")
  5: (KERNEL:%SINGLE-FLOAT 1)
  6: ("DEFUN FLOAT-SIGN" 0.0)[:OPTIONAL]
  7: (LISP::OUTPUT-FLOAT 0.0 #<pretty stream {59286975}>)
  8: (PRETTY-PRINT::OUTPUT-PRETTY-OBJECT 0.0 #<String-Output Stream>)
  9: (LISP::STRINGIFY-OBJECT 0.0 T)
 10: ("DEFSLIMEFUN LISTENER-EVAL")
 --more--

-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org
From: Thomas Schilling
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <49fno0FojdtsU1@news.dfncis.de>
Didier Verna wrote:
>         Hi !
> 
> Consider the following code:
> 
> 
> (declaim (optimize (speed 3)
> 		   (compilation-speed 0)
> 		   (safety 0)
> 		   (debug 0)))
> 
> (defun assign (arr val)
>   (declare (:explain :boxing))
>   (declare (type (simple-array single-float (* *)) arr))
>   (declare (type single-float val))
>   (let ((size (* (array-dimension arr 0)
> 		 (array-dimension arr 0))))
>     (dotimes (i size)
>       (setf (row-major-aref arr i) (+ (row-major-aref arr i) val)))))
> 
> 
> The Allegro compiler says it's generating a single-float box. Only I can't
> figure out where and why. Can somebody enlighten me ?


Did you try (declare (:explain (:boxing t)) ?

http://www.franz.com/support/documentation/8.0/doc/compiling.htm#decl-help-1

Otherwise: how about putting a (values) at the end.
I guess the boxed value is the result.
From: Didier Verna
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <mux3bgtw98l.fsf@uzeb.lrde.epita.fr>
Thomas Schilling <······@yahoo.de> wrote:

> Did you try (declare (:explain (:boxing t)) ?
> http://www.franz.com/support/documentation/8.0/doc/compiling.htm#decl-help-1

It's the same as just :boxing I think. Anyway I tried that but no change.

> Otherwise: how about putting a (values) at the end.
> I guess the boxed value is the result.

        Nope. I had tried to return nil also.

Thanks.

-- 
Didier Verna, ······@lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bic�tre, France   Fax.+33 (1) 53 14 59 22   ······@xemacs.org
From: Thomas Schilling
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <49folqFo0p5bU1@news.dfncis.de>
Didier Verna wrote:
>>Did you try (declare (:explain (:boxing t)) ?
>>http://www.franz.com/support/documentation/8.0/doc/compiling.htm#decl-help-1
> 
> It's the same as just :boxing I think. Anyway I tried that but no change.

Oh, sorry, overlooked that, too.  My last try would be to look at the
assembly.

OTOH, you maybe better ask Franz directly (or post to some of their
mailing lists).
From: Thomas Schilling
Subject: Re: ACL: where does this single-float box come from ?
Date: 
Message-ID: <49fo1vFo6fuaU1@news.dfncis.de>
Thomas Schilling wrote:

> Otherwise: how about putting a (values) at the end.
> I guess the boxed value is the result.

On second thought, though, that cannot be the case.