Xref: utzoo comp.arch:17138 comp.lang.misc:5165 Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!mentor.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.arch,comp.lang.misc Subject: Re: It looks like he's at it again! Summary: Optimization ain't so simple Message-ID: <2358@l.cc.purdue.edu> Date: 15 Jul 90 13:35:17 GMT References: <2328@l.cc.purdue.edu> <1990Jul10.072443.4844@cs.UAlberta.CA> <37569@ucbvax.BERKELEY.EDU> Followup-To: comp.arch,comp.lang.misc Organization: Purdue University Statistics Department Lines: 52 In article <37569@ucbvax.BERKELEY.EDU>, tve@sprite.berkeley.edu (Thorsten von Eicken) writes: > In article <3060@osc.COM> jgk@osc.COM (Joe Keane) writes: > >One real problem with using C for threaded interpreters is that there is no > >way to make an arbitrary jump instruction. If you could `goto' some address > >expression there would be no problem. > Yep, typically the C program ends up being a hunge switch statement: > loop: switch(next_thread) { > case 0: .... goto loop; > case 1: .... goto loop; > } > and one hopes that a) a jump table is produced (and not a binary search > tree) and b) the compiler doesn't dump core with some silly error when > the number of cases reaches into the thousands... > > Or can anyone suggest a better method? For which problem? The assumption that there is a best way to handle all switches is erroneous in the first place. There are natural situations in which the switch variable is an integer, with the probabilities of successive integers decreasing sufficiently rapidly. In that case, if there is a bound after which some "default" procedure is followed, the following may beat it. switch(i){ if(i > 1) goto i2; ................. i2: if(i > 2) goto i3: ................. } I am not assuming that one necessarily returns to the loop. How for hardware dependence considerations. Many, if not most machines, have a 3-way compare. In that case, the compare operations can be halved, at no cost. switch(i){ compare i with 2; if (>=) goto i2; ................. i2: if (>) goto i3; .............. } -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet) {purdue,pur-ee}!l.cc!cik(UUCP)