Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: wclodius@earthlink.net (William Clodius) Newsgroups: comp.compilers Subject: Re: How to type braces for computed gotos Date: Tue, 22 Jul 2014 22:36:40 -0600 Organization: Compilers Central Lines: 51 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-07-058@comp.compilers> References: <14-05-013@comp.compilers> <14-07-033@comp.compilers> <14-07-048@comp.compilers> <14-07-054@comp.compilers> <14-07-056@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1406122776 41525 2001:470:1f07:1126:0:676f:7373:6970 (23 Jul 2014 13:39:36 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Wed, 23 Jul 2014 13:39:36 +0000 (UTC) Keywords: Fortran, syntax Posted-Date: 23 Jul 2014 09:39:36 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1348 glen herrmannsfeldt wrote: > William Clodius wrote: > > (snip on labeled variable GOTO, Fortran ASSIGNed GOTO, and such) > ... > If you consider something like Duff's device, then it isn't so obvious > that computed GOTO is so different from C's switch/case. (Well, when > the labels are sequential starting at one.) > > As I noted previously, the Fortran standard now considers SELECT CASE > as a replacement for computed GOTO, though the latter hasn't yet been > removed from the standard. In the case of Anton I think for the applications he is best know for, high performance interpreters, the lack of syntactic block is a minor advantage in that the 100 SELECT CASE(i) CASE(0) ... GO TO 100 CASE(1) ... GO TO 100 CASE(2) ... can be replaced by GO TO(10, 11, 12, ...) I 10 ... GO TO(10, 11, 12, ...) I 11 ... GO TO(10, 11, 12, ...) I 12 ... Saving an extra step in indirection. The bigger problem is the fall through semantics for out of range with its implicit additonal test and branch before the goto's implicit branch table. That can be avoided by a modulo operation GO TO(10, 11, 12, ...) MODULO(I, N) +1 where N is the number of labels appearing in the computed GOTO. If I is an 8 bit integer and N is 256 a sufficiently smart compiler should recognize the semantics of an unsigned 8 bit integer, fit the jump table in a single level 1 cache line, optimize out the MODULO, the addition of 1, and the test for out of range and give him the efficiency he used to get with gcc's "computed goto". Whether that sufficintly smart compiler is gfortran with gcc's backend would be a different matter.