home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.lisp
- Subject: Re: What do compilers optimize?
- Date: 31 Aug 1992 20:33:05 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 69
- Message-ID: <17tvm1INNqdc@early-bird.think.com>
- References: <7398@skye.ed.ac.uk>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <7398@skye.ed.ac.uk> jeff@aiai.ed.ac.uk (Jeff Dalton) writes:
- >(Do any Lisp implementors read this newsgroup?)
-
- KMP of Symbolics has been participating quite a bit lately. I know some
- Lucid people read it but don't post much.
-
- >Are there any implementations that do any of the following (or
- >something similar):
- >
- > * Turn a CASE in which the alternatives are integers into
- > an indirect transfer?
-
- Symbolics and Lucid do this. My gripe with the Symbolics implementation is
- that it won't do the optimization if the case values are a dense set not
- near 0 -- it doesn't want to create a sparse jump table, and it doesn't try
- to offset the value to the base of the set.
-
- Surprisingly, CMUCL doesn't do this optimization at all.
-
- An interesting enhancement to this optimization would be to recognize when
- the case values are a sparse set of dense sets, e.g.
-
- (case x
- ((0 1 2 3 4 5 6) ...)
- ((7 9 11) ...)
- ((30 31 32) ...)
- ((33 34 35) ...)
- ((95 97 99 101) ...))
-
- and transform this into
-
- (cond ((<= 0 x 11)
- (case x ((0 1 2 3 4 5 6) ...)
- ((7 9 11) ...)))
- ((<= 30 35)
- (case x ((30 31 32) ...)
- ((33 34 35) ...)))
- (t (case x ((95 97 99 101) ...))))
-
- I could imagine the above style of code being in the implementation of a
- byte code interpreter. A processor emulator might be similar, although the
- dense sets would likely be found clustered above power-of-two values,
- allowing for further optimization; instead of the outer level being a COND,
- it could be another CASE that indexes off the high-order bits of the
- opcode, which is likely to be a dense set that can be turned into a jump
- table.
-
- > * Use hashing for a CASE with many alternatives?
-
- Neither Symbolics, Lucid, nor CMUCL appear to do this.
-
- > * Allow fixnums (or floats) to be passed between procedures without
- > any heap allocations (maybe just for local procedures in the same
- > top-level form)?
-
- Most implementations implement fixnums as immediate values, so they are
- never allocated on the heap. Symbolics also implements single floats as
- immediate types. I don't expect any implementations for conventional
- 32-bit processors to do this, though, since single floats take 32 bits, and
- that doesn't leave any room for tags. I believe this was the original
- intent of the small-float type, but apparently it's not useful enough (most
- FP hardware only supports 32 and 64 bit floats, and the limited precision
- of smaller floats probably makes them pretty useless).
-
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-