Re: Using C as a back end

anton@mips.complang.tuwien.ac.at (Anton Ertl)
31 Oct 2000 14:41:42 -0500

          From comp.compilers

Related articles
[16 earlier articles]
Re: Using C as a back end jacob@jacob.remcomp.fr (jacob navia) (2000-10-26)
Re: Using C as a back end nr@labrador.eecs.harvard.edu (2000-10-31)
Re: Using C as a back end sweeks@my-deja.com (Stephen T. Weeks) (2000-10-31)
Re: Using C as a back end zs@ender.cs.mu.oz.au (2000-10-31)
Re: Using C as a back end thp@cs.ucr.edu (Tom Payne) (2000-10-31)
Re: Using C as a back end engler@Stanford.EDU (2000-10-31)
Re: Using C as a back end anton@mips.complang.tuwien.ac.at (2000-10-31)
Re: Using C as a back end joachim_d@gmx.de (Joachim Durchholz) (2000-10-31)
Re: Using C as a back end conway@ender.cs.mu.oz.au (2000-11-01)
Re: Using C as a back end kst@cts.com (Keith Thompson) (2000-11-01)
Re: Using C as a back end rhyde@cs.ucr.edu (Randall Hyde) (2000-11-01)
Re: Using C as a back end rhyde@cs.ucr.edu (Randall Hyde) (2000-11-01)
Re: Using C as a back end vbdis@aol.com (2000-11-04)
[6 later articles]
| List of all articles for this month |

From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.compilers
Date: 31 Oct 2000 14:41:42 -0500
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
References: 00-10-148 00-10-154 00-10-212
Keywords: C
Posted-Date: 31 Oct 2000 14:41:42 EST

  Keith Thompson <kst@cts.com> writes:
>[You can get the effect of a computed goto in standard C using a
>switch full of goto's, and any decent compiler should generate about
>the same code as for an explicit computed goto, so I don't see that
>particular wart as a major one. -John]


Maybe you are thinking about something different, but in general there
is no way a compiler can generate the same code for a switch as for
GNU C's labels-as-values, because in general the compiler only look up
the target address when executing the switch, whereas with
labels-as-values you can do the lookup much earlier; in particular in
a (threaded-code) interpreter you just have to look up the address
once when generating/loading the interpreted code, whereas a
switch-based interpreter has to perform the lookup every time an
instruction is executed.


You can see empirical results for this difference on
http://www.complang.tuwien.ac.at/forth/threading/ (compare the columns
"direct" and "switch"). Some people will discount the switch results
because they were produced with gcc, which they claim is inferior to
other compilers, so here are also results for cc (DEC C V5.6-084 on
Digital UNIX V4.0) on a 289MHz 21064A:


method compiler User time
direct gcc-2.95.1 -O3 3.230s
switch gcc-2.95.1 -O3 5.898s
switch cc -O4 7.726s
switch cc -O5 7.728s


- anton
--
M. Anton Ertl Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
[Assigned goto, dammit. -John]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.