Article View: comp.sys.ti.explorer
Article #98fixnum vs single-float multiplies
From: seibert
Date: Thu, 19 Oct 1989 14:49
Date: Thu, 19 Oct 1989 14:49
70 lines
3711 bytes
3711 bytes
Hello lispm experts. I have a conundrum that the local folks haven't been
able to explain to me. I hope you can help. I'm investigating fixnum vs
single-float multiplies. It appears to me that a single-float multiply is
faster than a fixnum multiply. I've appended to this message the (short) test
functions I'm using and a sample output. I understand why using bignums is
slower than fixnums, and the progression of CPU timings as the number of bits
used in the integer representation increases, but not why the single-float
multiply appears to be in the same ball-park as the fixnum multiply.
I've tried the tests with and without: declarations, setfs, ash, and multiple
repetitions within the timing brackets. These results are from an Explorer I,
but I get essentially the same results on my Symbolics machine.
The idea of the code is to take a "nbrr" and time how much CPU time is needed
to square it using a single-float representation and a range of integer rep'ns.
Here's the code....
(defvar bbits 8)
(defvar right -7)
(defvar nbrr (/ 3.0))
(defvar str t)
(defmacro i* (i j) `(the fixnum
(ash (* (the fixnum ,i)
(the fixnum ,j))
(the fixnum right))))
(defun foo ()
(let ((inbr (floor (* nbrr (ash 1 (1- bbits)))))
(result nil))
(timeit ()
(setf result (i* inbr inbr)))
(format str " ~3d bits result: ~10,7f ~12A; ~12A inbr ~d"
bbits (* result (/ 1.0 (ash 1 (1- bbits))))
(type-of result) (type-of inbr) inbr)))
(defun foobar ()
(do ((bbits 4 (+ bbits 4)))
((= bbits 60))
(setf right (- 1 bbits))
(foo))
(format str "~%floating point... ")
(let ((nbrw nbrr)
(result nil))
(timeit ()
(setf result (* nbrw nbrw)))
(format str " result: ~10,7f ~12A; ~12A nbr ~20,17f"
result (type-of result) (type-of nbrw) nbrw)))
When I invoke foobar, here's the output....
CPU: 18.0 us 4 bits result: 0.0000000 FIXNUM ; FIXNUM inbr 2
CPU: 19.0 us 8 bits result: 0.1015625 FIXNUM ; FIXNUM inbr 42
CPU: 18.0 us 12 bits result: 0.1108398 FIXNUM ; FIXNUM inbr 682
CPU: 56.0 us 16 bits result: 0.1110840 FIXNUM ; FIXNUM inbr 10922
CPU: 60.0 us 20 bits result: 0.1111088 FIXNUM ; FIXNUM inbr 174762
CPU: 62.0 us 24 bits result: 0.1111110 FIXNUM ; FIXNUM inbr 2796202
CPU: 67.0 us 28 bits result: 0.1111111 FIXNUM ; BIGNUM inbr 44739244
CPU: 54.0 us 32 bits result: 0.1111111 BIGNUM ; BIGNUM inbr 715827904
CPU: 91.0 us 36 bits result: 0.1111111 BIGNUM ; BIGNUM inbr 11453246464
CPU: 90.0 us 40 bits result: 0.1111111 BIGNUM ; BIGNUM inbr 183251943424
CPU: 90.0 us 44 bits result: 0.1111111 BIGNUM ; BIGNUM inbr 2932031094784
CPU: 89.0 us 48 bits result: 0.1111111 BIGNUM ; BIGNUM inbr 46912497516544
CPU: 95.0 us 52 bits result: 0.1111111 BIGNUM ; BIGNUM inbr 750599960264704
CPU: 95.0 us 56 bits result: 0.1111111 BIGNUM ; BIGNUM inbr 12009599364235264
floating point...
CPU: 25.0 us result: 0.1111111 SINGLE-FLOAT; SINGLE-FLOAT nbr 0.33333334000000000
Thanks for your help. _Ms
--
Michael Seibert seibert@xn.ll.mit.edu ll-xn!seibert
Technical Details
Message-ID:
<1576@xn.LL.MIT.EDU>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ll-xn!seibertShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ll-xn!seibert From: seibert@XN.LL.MIT.EDU (seibert) Newsgroups: comp.sys.ti.explorer Subject: fixnum vs single-float multiplies Message-ID: <1576@xn.LL.MIT.EDU> Date: 19 Oct 89 14:49:56 GMT Organization: MIT Lincoln Laboratory, Lexington, MA Lines: 70