Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.szaf.org!news.gnuher.de!rz.uni-karlsruhe.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Bernd Paysan Newsgroups: comp.lang.forth Subject: Re: CASE mis-understanding? Date: Fri, 24 Jan 2014 14:50:55 +0100 Organization: 1&1 Internet AG Lines: 34 Message-ID: References: <52e03ea6.129724862@news.demon.co.uk> <2014Jan23.182124@mips.complang.tuwien.ac.at> <7eSdneFEM7EVwXzPnZ2dnUVZ_q2dnZ2d@supernews.com> <2014Jan24.102538@mips.complang.tuwien.ac.at> NNTP-Posting-Host: p5dcd724c.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: online.de 1390571455 22952 93.205.114.76 (24 Jan 2014 13:50:55 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Fri, 24 Jan 2014 13:50:55 +0000 (UTC) User-Agent: KNode/4.11.4 Xref: csiph.com comp.lang.forth:28067 Anton Ertl wrote: > My students are those who are interested in efficient programs > (otherwise they would not have elected to take my course), so I guess > that they are above average in that respect. Maybe this is just a > failure of the courses in my university and every other computer > science program in the world teaches that C's switch is compiled into > an indirect branch on the machine level, but from what I hear, I doubt > it. The trend seems to be not to teach anything about the machine > level at all (and that includes my university). Ouch. When I studied at TU Munich, machine level was part of the beginner's four semester course. They had a VAX-based architecture for that part of the course, which did run in an awfully slow and bloated emulator (I much preferred optimizing code for the real machines), but this emulator even did a quad-core emulation, so the students could study multithreading (back then, even comparable expensive workstations had only one single CPU, not like today, where even a cheap mobile phone has at least a dual-core CPU...). My advise to your students is to compile the code with the -S switch (stopping at the assembler level), and look at the resulting file. That's what I use to optimize things, and that's what I recommend doing. The students will quickly find out that the case statement is converted to a jump table. For Gforth users, see-code is the word of choice to check what the compiler (in gforth-fast, the engine relevant for performance-sensitive stuff) actually does with the code. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/