From: ···········@alcoa.com
Subject: Coercing single-float to double-float
Date: 
Message-ID: <73fdep$csl$1@nnrp1.dejanews.com>
I have an application where I need to perform single-float to double-float
conversions. In the processing of optimizing this application on ACL 5.0 I
replaced: (coerce singlenum 'double-float) with: (* 1.0d0 singlenum) to get
much speed improvement. Why is the second option so much faster and more
importantly is the following always true: (= (coerce singlenum 'double-float)
(* 1.0d0 singlenum)) ?

John Watton
Aluminum Company of America

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

From: Steve Gonedes
Subject: Re: Coercing single-float to double-float
Date: 
Message-ID: <m2btlwgyf3.fsf@KludgeUnix.com>
···········@alcoa.com writes:

< I have an application where I need to perform single-float to double-float
< conversions. In the processing of optimizing this application on ACL 5.0 I
< replaced: (coerce singlenum 'double-float) with: (* 1.0d0 singlenum) to get
< much speed improvement. Why is the second option so much faster and more
< importantly is the following always true: (= (coerce singlenum 'double-float)
< (* 1.0d0 singlenum)) ?

The function coerce tries to make some input into some other output.
The assembly print out (disassemble #'coerce) is around 2300 lines.
You should try using the function double-float, and declare your
argument as a single-float - this should buy you much better
performance than coerce...
From: Rainer Joswig
Subject: Re: Coercing single-float to double-float
Date: 
Message-ID: <joswig-2511981025550001@pbg3.lavielle.com>
In article <··············@KludgeUnix.com>, Steve Gonedes
<········@worldnet.att.net> wrote:

> ···········@alcoa.com writes:
> 
> < I have an application where I need to perform single-float to double-float
> < conversions. In the processing of optimizing this application on ACL 5.0 I
> < replaced: (coerce singlenum 'double-float) with: (* 1.0d0 singlenum) to get
> < much speed improvement. Why is the second option so much faster and more
> < importantly is the following always true: (= (coerce singlenum
'double-float)
> < (* 1.0d0 singlenum)) ?
> 
> The function coerce tries to make some input into some other output.
> The assembly print out (disassemble #'coerce) is around 2300 lines.

Just to remind people. Don't expect that what
you see as the disassembled function COERCE will appear in your
machine code.

(defun test (x)
  (coerce x 'double-float))

If I disassemble that on my Lisp machine - coerce is not
there. It has been replaced by a call to CLI::COERCE-TO-DOUBLE-FLOAT .

-- 
http://www.lavielle.com/~joswig
From: ···········@alcoa.com
Subject: Re: Coercing single-float to double-float
Date: 
Message-ID: <73gu9e$l6h$1@nnrp1.dejanews.com>
In article <··············@KludgeUnix.com>,
  Steve Gonedes <········@worldnet.att.net> wrote:

> The function coerce tries to make some input into some other output.
> The assembly print out (disassemble #'coerce) is around 2300 lines.
> You should try using the function double-float, and declare your
> argument as a single-float - this should buy you much better
> performance than coerce...

I looked up the function double-float which I was unfamiliar with and found
that it exists in ACL 5.0 but is not ANSI. I did not notice it to be faster.
Another option is (float singlenum 1.0d0) which is a little faster. So here
are the options I now have:

(coerce singlenum 'double-float)    ; slow
(* 1.0d0 singlenum)                 ; fast
(float singlenum 1.0d0)             ; fastest
#+:allegro (double-float singlenum) ; fast

in each case the variable singlenum is declared so with (speed 3). Anyone have
another way to convert a single-float to a double?



-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
From: Tim Bradshaw
Subject: Re: Coercing single-float to double-float
Date: 
Message-ID: <ey3vhk4ynsz.fsf@todday.aiai.ed.ac.uk>
* Steve Gonedes wrote:

> The function coerce tries to make some input into some other output.
> The assembly print out (disassemble #'coerce) is around 2300 lines.
> You should try using the function double-float, and declare your
> argument as a single-float - this should buy you much better
> performance than coerce...

That's highly implementation-dependent.  CMUCL generates a single
instruction for this case of COERCE with suitable declarations and a
literal type name, and I expect other compilers can do similar things.

It might be better from the point of view of readability to use the
*-float functions, but it's only faster if it actually *is* faster in
your code.  It's certainly worth while making sure that there are
suitable declarations as well (which also helps readability I think).

--tim