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


Groups > comp.lang.forth > #31570

Re: Optimizing C compilers vs. assembly language for Forth interpreters

From Bernd Paysan <bernd.paysan@gmx.de>
Newsgroups comp.lang.forth
Subject Re: Optimizing C compilers vs. assembly language for Forth interpreters
Date 2014-06-15 23:55 +0200
Organization 1&1 Internet AG
Message-ID <lnl4o6$vnj$1@online.de> (permalink)
References (8 earlier) <539c074b$0$6667$9b4e6d93@newsspool3.arcor-online.net> <2014Jun14.125924@mips.complang.tuwien.ac.at> <2_SdnT25uJH53wHOnZ2dnUVZ_rednZ2d@supernews.com> <2014Jun14.164055@mips.complang.tuwien.ac.at> <df6dnZ5Htr4R6gHOnZ2dnUVZ_qudnZ2d@supernews.com>

Show all headers | View raw


Andrew Haley wrote:

> Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> Actually it does not require expensive optimizations to get the branch
>> prediction accuracy of switch threading up to the accuracy we see with
>> well-implemented threaded-code:
> 
> Sure, but that is a very different matter: there's a lot more to
> optimizing a big interpreter than branch prediction, important though
> it is.

Yes, the other critical thing is register allocation.  This is another place 
where GCC and LLVM have troubles, at least on awful register starved 
architectures like x86.  The way to allocate registers for an interpreter is 
to have life range splitting, and then choose the most frequently used 
variables to live in registers across those switch jump boundaries, and be 
temporarily spilled out in those operations which need more registers or 
call functions where the registers might be globbered (several registers are 
caller-save, and in GCC out of scope for allocating as registers once you 
have a single call to something inside your VM).

The trouble with unfolding the switch statement nowadays also happens on 
computed gotos in GCC: Instead of leaving the gotos where they are, GCC 
folds them into one single central dispatcher goto, then tries to do very 
time-consuming and counter-productive analysis on it (which we disable with 
a switch, because the resulting code doesn't even run!), and the replicates 
the code again, but at that point is unable to optimize a few moves away.

GCC 2.95.2 compiled

jmp -4(IP)

and GCC 4.x compiles

movl -4(IP),%somereg
movl %somereg,%anotherreg
jmp %anotherreg

This is so obviously going wrong that the best thing to fix this problem 
would be to simply don't try to analyze control flow over computed gotos: It 
doesn't help, it produces code that doesn't and can't run (at least during 
the 3.x timeframe, when we fell over that problem), and even when you 
disable that fuckup, it still produces something that is considerably worse 
than it could be by applying much simpler rules.

But as I tried to release Gforth 0.7.3 through the official GNU way on 
Friday (something I've avoided on 0.7.1 and 0.7.2), and am still failing to 
get the required Permit A 38 (it is actually easier to run a complete server 
which allows me to publish my software than getting the GNU project to push 
two files into the gforth dictionary), it seems to be built into the way 
most humans think: way too complicated.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

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


Thread

Forth philosophy OneArb <o1neeno1@gmail.com> - 2014-06-10 13:23 -0700
  Re: Forth philosophy Roger Levy <roger.levy@gmail.com> - 2014-06-10 14:45 -0700
  Re: Forth philosophy Elizabeth D Rather <erather@forth.com> - 2014-06-10 12:51 -1000
    Re: Forth philosophy hughaguilar96@yahoo.com - 2014-06-10 16:14 -0700
  Re: Forth philosophy Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-06-11 10:03 +0100
    Re: Forth philosophy visualforth@rocketmail.com - 2014-06-11 11:11 -0700
      Re: Forth philosophy Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-06-11 21:57 +0100
  Re: Forth philosophy "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-11 19:30 -0400
    Re: Forth philosophy "Elizabeth D. Rather" <erather@forth.com> - 2014-06-11 14:26 -1000
      Re: Forth philosophy rickman <gnuarm@gmail.com> - 2014-06-12 00:24 -0400
        Re: Forth philosophy "Elizabeth D. Rather" <erather@forth.com> - 2014-06-11 18:58 -1000
          Re: Forth philosophy "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-12 07:33 -0400
            Re: Forth philosophy AKK <akk@nospam.org> - 2014-06-12 20:39 +0200
              Re: Forth philosophy "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-12 23:15 -0400
              Re: Forth philosophy anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-06-13 17:29 +0000
                Re: Forth philosophy AKK <akk@nospam.org> - 2014-06-14 12:26 +0200
                Re: Forth philosophy anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-06-14 10:59 +0000
                Re: Forth philosophy Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-14 07:39 -0500
                Optimizing C compilers vs. assembly language for Forth interpreters (was: Forth philosophy) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-06-14 14:40 +0000
                Re: Optimizing C compilers vs. assembly language for Forth interpreters Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-14 11:25 -0500
                Re: Optimizing C compilers vs. assembly language for Forth interpreters Bernd Paysan <bernd.paysan@gmx.de> - 2014-06-15 23:55 +0200
                Re: Forth philosophy albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-06-14 19:45 +0000
                Re: Forth philosophy Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-15 13:18 -0500
                Re: Forth philosophy AKK <akk@nospam.org> - 2014-06-16 21:14 +0200
                Re: Forth philosophy Bernd Paysan <bernd.paysan@gmx.de> - 2014-06-16 22:41 +0200
                Re: Forth philosophy AKK <akk@nospam.org> - 2014-06-17 13:32 +0200
                Re: Forth philosophy Bernd Paysan <bernd.paysan@gmx.de> - 2014-06-17 15:02 +0200
                Re: Forth philosophy mhx@iae.nl - 2014-06-16 13:41 -0700
        Re: Forth philosophy "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-12 07:33 -0400
        Re: Forth philosophy barrym95838@yahoo.com - 2014-06-13 21:48 -0700
          Re: Forth philosophy "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-14 01:01 -0400
      Re: Forth philosophy Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-12 03:02 -0500
      Re: Forth philosophy albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-06-12 10:43 +0000
      Re: Forth philosophy "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-12 07:32 -0400

csiph-web