Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #29730
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Epic fail |
| Date | 2014-04-20 12:00 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2014Apr20.140052@mips.complang.tuwien.ac.at> (permalink) |
| References | <alpine.BSF.2.00.1404171716050.71902@yoko.controlq.com> <2014Apr18.192721@mips.complang.tuwien.ac.at> <alpine.BSF.2.00.1404181447300.40766@yoko.controlq.com> |
Rob Sciuk <rob@controlq.com> writes:
>BTW: does Gforth optimize sequences such as "dup drop" => NOOP?
No. There are two optimizations that might achieve this, but in
Gforth don't:
1) Static superinstruction, where certain sequences of primitives are
replaced by optimized composite primitives (superinstructions). We
are optimizing IIRC 13 frequently-occuring sequences, e.g., LIT +, but
DUP DROP is not such a sequence.
2) Static stack caching: There are several versions of
frequently-occuring primitives, for different representations of the
stack.
E.g., consider "DROP 1": We start out with the canonical stack
representation (S1) of one item in a register, and the stack pointer
pointing to the next item. We have another stack representation (S0)
where there is no stack item in a register and the stack pointer
points to the top item, which is in memory. A DROP that goes from S1
to S0 is really cheap, almost a noop. A LIT that goes from S0 to S1
is also quite cheap. So Gforth chooses to use S0 as stack
representation between the DROP and the LIT:
: foo drop 1 ; see-code foo
$7F07B4266088 noop
0x00007f07b59e8af9: add $0x8,%rbp
$7F07B4266090 lit
$7F07B4266098 <1>
0x00007f07b59e8afd: mov 0x0(%rbp),%r14
0x00007f07b59e8b01: add $0x10,%rbp
$7F07B42660A0 ;s ok
Apart from the instruction pointer updates (the adds to %rbp), there
is only one instruction in this sequence.
However, static stack caching as implemented in Gforth does not
optimize DUP DROP into a noop, because Gforth has no state that
represents a DUPed top-of-stack.
On PowerPC, the sequence DUP DROP can be optimized better, but not
into a noop; there we have stack representations with more than one
register (more registers are usable), in particular S2, where the top
two stack items are in registers. A DUP from S1 to S2 is just a move
instruction, and a DROP from S2 to S1 is a noop, so on PowerPC this
sequence would be optimized into a move plus two IP updates.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2013: http://www.euroforth.org/ef13/
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
Epic fail Rob Sciuk <rob@controlq.com> - 2014-04-17 17:35 -0400
Re: Epic fail Bernd Paysan <bernd.paysan@gmx.de> - 2014-04-17 23:55 +0200
Re: Epic fail anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-18 17:27 +0000
Re: Epic fail Rob Sciuk <rob@controlq.com> - 2014-04-18 14:54 -0400
Re: Epic fail albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-04-19 11:53 +0000
Re: Epic fail anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-20 12:00 +0000
csiph-web