Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1348

Re: How to type braces for computed gotos

From wclodius@earthlink.net (William Clodius)
Newsgroups comp.compilers
Subject Re: How to type braces for computed gotos
Date 2014-07-22 22:36 -0600
Organization Compilers Central
Message-ID <14-07-058@comp.compilers> (permalink)
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>

Show all headers | View raw


glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:

> William Clodius <wclodius@earthlink.net> 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.

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Best "simple" C Compiler I've ever seen andrewchamberss@gmail.com - 2014-05-04 18:23 -0700
  Re: Best "simple" C Compiler I've ever seen federation2005@netzero.com - 2014-06-30 12:42 -0700
  How to type braces for computed gotos (was: Best "simple" C Compiler I've ever seen) federation2005@netzero.com - 2014-07-18 14:44 -0700
    Re: How to type braces for computed gotos glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-07-19 02:21 +0000
      Re: How to type braces for computed gotos Ivan Godard <ivan@ootbcomp.com> - 2014-07-18 21:59 -0700
      Re: How to type braces for computed gotos federation2005@netzero.com - 2014-07-21 10:32 -0700
    Re: How to type braces for computed gotos (was: Best "simple" C Compiler I've ever seen) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-07-21 11:45 +0000
      Re: How to type braces for computed gotos glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-07-21 16:19 +0000
      Re: How to type braces for computed gotos wclodius@earthlink.net (William Clodius) - 2014-07-21 21:44 -0600
        Re: How to type braces for computed gotos glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-07-23 00:35 +0000
          Re: How to type braces for computed gotos wclodius@earthlink.net (William Clodius) - 2014-07-22 22:36 -0600
            Re: How to type braces for computed gotos anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-07-25 22:38 -0400

csiph-web