Path: utzoo!censor!becker!geac!jtsv16!uunet!samsung!think!leander.think.com!barmar From: barmar@leander.think.com (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: Can there be an efficient SWITCH form in CL? Message-ID: <31749@news.Think.COM> Date: 21 Nov 89 02:39:44 GMT References: <32711@ucbvax.BERKELEY.EDU> Sender: news@Think.COM Distribution: usa Organization: Thinking Machines Corporation, Cambridge MA Lines: 26 In article <32711@ucbvax.BERKELEY.EDU> norvig@cogsci.berkeley.edu (Peter Norvig) writes: > Or should we just insist that >compiler writers produce better code for (CASE n ...), and for >(aref (vector ...) n)? After racking our brains a couple of years ago over this one, we complained to Symbolics. As a result, the compiler in Genera 7.2 optimizes CASE macros when all the keys are non-negative fixnums and the space of keys isn't too sparse (if memory serves, "too sparse" is when fewer than half of the keys between 0 and the largest key are used). Earlier this year I sent them the minor modifications necessary to remove the reference to 0. By the way, depending on the memory architecture of the machine, converting a series of tests into a jump through a dispatch table might *not* be an optimization. Some systems simultaneously prefetch both branches of a conditional jump, but this can't be done easily with a dispatch. You can often get better overall performance by putting the most common cases first. This is why such optimization should be left to the compiler (although it's still a hard problem, since different models of Symbolics 36xx's have different prefetch and caching characteristics, yet there is only one compiler for the whole family). Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar