From: Shyamal Prasad
Subject: Need help understanding a SBCL compilation note
Date: 
Message-ID: <873betlzgb.fsf@turtle.local>
Hi,

I need a little help understanding a SBCL 0.9.12 (Debian unstable,
i386/Pentium) note. Here is the function I'm compiling

(defun test5 (n)
    (declare (fixnum n)
	     (optimize (speed 3) (compilation-speed 0)
		       (safety 0) (debug 0)))
    
    (format t "~,9f	Cookson Hills~%"
	  (loop for k fixnum from 1 to n
		sum (let ((ck (cos (coerce k 'double-float)))
			  (kd (coerce k 'double-float)))
		      (/ 1.0d0 (* kd kd kd ck ck)))
		double-float)))



And here is what SBCL spits out on 


;;; Evaluating defun test5
; in: LAMBDA NIL
;     (COS (COERCE K 'DOUBLE-FLOAT))
; 
; note: unable to avoid inline argument range check
; because the argument range (DOUBLE-FLOAT) was not within 2^64

What exactly does this mean? Any way to supress it? I looked at the
assembler and I don't see an obvious problem. I don't get this note
when using sbcl with my powerpc system! Also, the code runs great
(matches the equivalent C code with gcc :)

;     (FORMAT T
;           "~,9f	Cookson Hills~%"
;           (LOOP FOR
;                 K
;                 FIXNUM
;                 FROM
;                 1
;                 TO
;                 N
;                 SUM
;                 (LET ((CK #) (KD #))
;                   (/ 1.0d0 (* KD KD KD CK CK)))
;                 DOUBLE-FLOAT))
; --> FORMAT FORMATTER FUNCTION BLOCK LET 
; ==>
;   (SB-FORMAT::FORMAT-FIXED STREAM
;                            #:FORMAT-ARG-6
;                            #:G682
;                            #:G683
;                            #:G684
;                            #:G685
;                            #:G686
;                            NIL)
; 
; note: doing float to pointer coercion (cost 13) from #:LOOP-SUM-1
; 
; compilation unit finished
;   printed 2 notes

This one is not a worry, but is there any way I can supress this last
note?

Cheers!
Shyamal

From: Christophe Rhodes
Subject: Re: Need help understanding a SBCL compilation note
Date: 
Message-ID: <sqodxg29an.fsf@cam.ac.uk>
Shyamal Prasad <·············@verizon.net> writes:

> Hi,
>
> I need a little help understanding a SBCL 0.9.12 (Debian unstable,
> i386/Pentium) note. Here is the function I'm compiling
>   [...]
> 	  (loop for k fixnum from 1 to n
> 		sum (let ((ck (cos (coerce k 'double-float)))

> ;;; Evaluating defun test5
> ; in: LAMBDA NIL
> ;     (COS (COERCE K 'DOUBLE-FLOAT))
> ; 
> ; note: unable to avoid inline argument range check
> ; because the argument range (DOUBLE-FLOAT) was not within 2^64
>
> What exactly does this mean? Any way to supress it? I looked at the
> assembler and I don't see an obvious problem. I don't get this note
> when using sbcl with my powerpc system! Also, the code runs great
> (matches the equivalent C code with gcc :)

The x86 chip has a hardware FCOS instruction which takes the cosine of
a float.  However, the float argument must be in the interval [-2^63,
2^63] (I think; I haven't checked the details), and so since SBCL
can't prove that it is, it needs to write some extra guard code around
the fcos instruction.

(Why SBCL can't work out that the argument is in fact always going to
be in that interval is another matter.  K is known to be of type
fixnum, so the COERCE type deriver should be able to figure out that
its result will be of type 
  (DOUBLE-FLOAT <most-negative-fixnum-minus-a-bit> <most-positive-fixnum-plus-a-bit>)
where the devil is in the details, given scope for confusing float
rounding modes, precision and so on.)

> ; note: doing float to pointer coercion (cost 13) from #:LOOP-SUM-1
>
> This one is not a worry, but is there any way I can supress this last
> note?

Not trivially, I'm afraid.  You might be able to do so with something
like
  (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
    (defun test-5 (x)
      (declare (sb-ext:unmuffle-conditions sb-ext:compiler-note))
      ...))
but I haven't tested it.  (The idea is to muffle conditions just
around the function itself, but I suspect this doesn't in fact do it.)

Christophe
From: Shyamal Prasad
Subject: Re: Need help understanding a SBCL compilation note
Date: 
Message-ID: <87y7wkku6l.fsf@turtle.local>
>>>>> "Christophe" == Christophe Rhodes <·····@cam.ac.uk> writes:

    Christophe> Shyamal Prasad <·············@verizon.net> writes:

    >> ;;; Evaluating defun test5 ; in: LAMBDA NIL ; (COS (COERCE K
    >> 'DOUBLE-FLOAT)) ; ; note: unable to avoid inline argument range
    >> check ; because the argument range (DOUBLE-FLOAT) was not
    >> within 2^64
    >> 

    Christophe> The x86 chip has a hardware FCOS instruction which
    Christophe> takes the cosine of a float.  However, the float
    Christophe> argument must be in the interval [-2^63, 2^63] (I
    Christophe> think; I haven't checked the details), and so since

Thanks for the prompt reply. That makes a lot of sense and it looks
like I have nothing to worry about. 

/Shyamal