Subject: Re: compile
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 08 Feb 2004 07:24:39 -0600
Newsgroups: comp.lang.lisp
Message-ID: <1YOdnXDMS6kKpbvdXTWc-w@speakeasy.net>
Edi Weitz  <edi@agharta.de> wrote:
+---------------
| You can make a promise to your compiler. Look up DECLARE in the ANSI
| spec. With corresponding optimization settings most CL compilers will
| believe you. Compare the following in CMUCL:
| 
|   (disassemble (compile nil (lambda (a b)
|                               (+ a b))))
| 
|   (disassemble (compile nil (lambda (a b)
|                               (declare (optimize speed (safety 0))
|                                        (fixnum a b))
|                               (+ a b))))
+---------------

You get an even bigger gain by declaring that the result stays in range:

    (disassemble (compile nil (lambda (a b)
                                (declare (optimize speed (safety 0))
                                         (fixnum a b))
                                (the fixnum (+ a b)))))

Of course, it's not cool to lie to the compiler, so you better mean it...


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607