Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!bagate!cbmvax!jesup From: jesup@cbmvax.commodore.com (Randell Jesup) Newsgroups: comp.sys.amiga.programmer Subject: Re: Lemmings - a tutorial Part V (last) Message-ID: <20437@cbmvax.commodore.com> Date: 7 Apr 91 06:24:31 GMT References: <1991Mar31.003933.1483@mintaka.lcs.mit.edu> <1991Apr1.020748.26863@mintaka.lcs.mit.edu> <18ee3f47.ARN125e@jsmami Organization: Commodore, West Chester, PA Lines: 47 .UUCP> <1991Apr5.234958.23678@starnet.uucp> Sender: Reply-To: jesup@cbmvax.commodore.com (Randell Jesup) Followup-To: Distribution: Organization: Commodore, West Chester, PA Keywords: In article <1991Apr5.234958.23678@starnet.uucp> sschaem@starnet.uucp (Stephan Schaem) writes: > Come one how many people here dont use jump table instead of multi cmp? > An example would be for instruction encoding for a compiler. > Intead of up to 16 test (that would have been done in probability > usage) you replace it by 10 instruction (with an offset jump table). > > The C compiler need to ANDERSTAND what you are doing for it to do > 'perfect' compilation. Guess what? C compilers do use jump tables (when it's profitable). In fact, I think SAS C has at least 3 or 4 (maybe more) different "types" of code generated for switch statements. It calculates all the performance issues for you. In asm, if you are using the optimal version, and then add a few more cases, your implementation may no longer be optimimal, but may well take hours or days (including debugging) to recode, while the C compiler can do it in seconds. Trust me, I know, having had to modify "optimized" asm switch statements in a part of dos we contracted from an outsider for - he used a jump-table of bra.s's. When we had to add code, things started breaking, because there was too much code to reach with bra.s. Then it got to the point where there wasn't enough space to reach with bra.s with the table right in the middle of the routines, even with lots of careful reordering to get the entrypoints in range. I finally had to make some entries in the table point to additional branches to the actual destination. Sure, I could have bought the rom space and made them bra's (but we were tight on space), or I could have worked out whether another switch implementation was now smaller/ faster (but I didn't have time). If it was in C it would have been handled for me, and I could have concentrated on getting the algorithm right, instead of concentrating on whether a branch is within +- 128 bytes. This is one reason why assembler is expensive: maintenance and bug-fixes. -- Randell Jesup, Keeper of AmigaDos, Commodore Engineering. {uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.commodore.com BIX: rjesup Disclaimer: Nothing I say is anything other than my personal opinion. Thus spake the Master Ninjei: "To program a million-line operating system is easy, to change a man's temperament is more difficult." (From "The Zen of Programming") ;-)