List Info

Thread: oddities in type declarations




oddities in type declarations
user name
2006-04-07 12:07:53

        Hi !

Consider the following file to be compiled:

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

(defun assign (array value)
  (declare (type (simple-array fixnum (* *)) array))
  (declare (type fixnum value))
  (let ((size (array-dimension array 0))) ; don't worry,
array is square
    (dotimes (i size)
      (declare (type fixnum i))
      (dotimes (j size)
	(setf (aref array i j) value)))))


        The declaration of i as a fixnum seems to allow
CMU-CL to inline some
operations on the loop. Otherwise, I would get a message
liike this:

; In: DEFUN ASSIGN

;   (DOTIMES (I SIZE) (DOTIMES # #))
; --> DO BLOCK LET TAGBODY UNLESS COND IF NOT IF >= IF

; ==>
;   (< I #:G0)
; Note: Forced to do GENERIC-< (cost 10).
;     Unable to do inline fixnum comparison (cost 4)
because:
;     The first argument is a UNSIGNED-BYTE, not a FIXNUM.
; 
; --> DO BLOCK LET TAGBODY PSETQ PSETF LET*
MULTIPLE-VALUE-BIND LET 1+ 
; ==>
;   (+ I 1)
; Note: Forced to do GENERIC-+ (cost 10).
;     Unable to do inline fixnum arithmetic (cost 1)
because:
;     The first argument is a UNSIGNED-BYTE, not a FIXNUM.
;     The result is a (INTEGER 1), not a FIXNUM.
;     Unable to do inline fixnum arithmetic (cost 2)
because:
;     The first argument is a UNSIGNED-BYTE, not a FIXNUM.
;     The result is a (INTEGER 1), not a FIXNUM.
;     etc.
; 


        But do I really have the right to do so ? The macro
expansion of the
function indicates that two consecutive declarations for i
are issued in that
case.

Also, I don't understand why CMU-CL gives me no note at all
about the loop on
J, which behaves exactly the same.


Thanks.

-- 
Didier Verna, didierlrde.epita.fr, http://www.lrde.epit
a.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  
didierxemacs.org


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )