Phillip Eaton <
pjea...@gmail.com> writes:
>At this point, I'd thinking that memory constraints were becoming somewhat =
>irrelevant and so ITC/DTC should have been superseded by Subroutine Threade=
>d Code, as what ITC/DTC offers in memory is negated by the complexity and p=
>erformance degradation of using an inner interpreter. =20
>
>But 30+ years on, even though Chuck's Machine Forth seems to have started g=
>etting closer to the underlying CPU instructions, this hasn't happen. Of th=
>e many "new" Forths to have been created, many seem to have been based on t=
>he old ITC/DTC Forths of the past.=20
>
>Isn't building an STC Forth from assembly language the most efficient, simp=
>le and performant way of doing things? I'm guessing it would also be easier=
> to optimise automatically, too.=20
First of all, there is a difference between STC and native code,
although there is no hard boundary between them.
It seems to me that commercial Forth systems have switched to native
code in the 1990s, and there are also non-commercial Forth systems
like FLK and ntf/lxf that use native code.
Native code is certainly fastest (unless you do things like mixing
code and data on CPUs that don't like that). It's not the simplest,
but I think that the reluctance to do native code among
build-your-own-Forth implementors is more due to not having a good
model to go by than due to the actual complexity.
Whether STC is faster than DTC depends on tha actual CPU; you can find
some results on <
http://www.complang.tuwien.ac.at/forth/threading/>.
In straight-line code, STC has to perform a call and a return per
word, while DTC performs only one jump per word, but does some
additional work on the data side.
>I'm currently using CamelForth 6809 (DTC) and, whilst the 8/16-bit 6809 is =
>particularly Forth-friendly with it's two hardware stacks and NEXT is very =
>efficient, it's still bugging me that being STC would strip out an extra le=
>vel of complexity and perhaps give a performance boost.
For straight-line code, STC costs 12 cycles per primitive (JSR 7, RTS
5). My 6809 is a little rusty and my 6809 book is hiding from me, but
it seems to me that JMP [,X++] would implement DTC dispatch, and that
it costs 12 cycles, too. The 6809 has 64KB address space, so the
extra byte per compiled word is a good reason to use DTC.
>So, I'm interested in opinions here:
>1. Is my assertation that post- the early 80s, STC is a no-brainer and the =
>other models are obsolete?
>2. If 1. is true, why are so many people still working with non-STC Forths =
>nowadays?
Many of the build-it-yourself implementors seem to be more interested
in the "feeling of mastery and understanding" than in performance.
The fact that people are building Forth systems for the 8086 or the
6809 shows that these systems are not intended to exploit modern
hardware to its fullest.
The existing material on threaded code is apparently more amenable to
being adopted for a build-it-yourself implementation than the material
for native-code systems. FLK has no accompanying material; cmForth
has (Footsteps in an Empty Valley), but given it's focus on
unavailable hardware it's apparently not inspring. Gforth uses
techniques that are useful for native-code compilers, and has material
explaining that (in particular "The new Gforth Header" [paysan19]),
but apparently the complexity of Gforth is a deterrent. The
commercial systems were not designed to inspire build-it-yourself
implementors, and are certainly not accompanied by such material.
I have started on a system that is intended to be a model for modern
concepts, including native-code generation, but have not gotten very
far before other things required my time. We'll see when I will find
the time, and whether that system will fulfill its intended role.
>3. If 1. is false, what are the key reason why ITC/DTC are still relevant?
In Gforth, we are using a DTC base for portability reasons: it can be
implemented with gcc. This also allows us to have native code for
most straight-line code with very little machine-specific code,
falling back to DTC for control flow and non-relocatable primitives.
@InProceedings{paysan19,
author = {Bernd Paysan and M. Anton Ertl},
title = {The new {Gforth} Header},
crossref = {euroforth19},
pages = {5--20},
url = {
http://www.euroforth.org/ef19/papers/paysan.pdf},
url-slides = {
http://www.euroforth.org/ef19/papers/paysan-slides.pdf},
video = {
https://wiki.forth-ev.de/doku.php/events:ef2019:header},
OPTnote = {refereed},
abstract = {The new Gforth header is designed to directly
implement the requirements of Forth-94 and
Forth-2012. Every header is an object with a fixed
set of fields (code, parameter, count, name, link)
and methods (\texttt{execute}, \texttt{compile,},
\texttt{(to)}, \texttt{defer@}, \texttt{does},
\texttt{name>interpret}, \texttt{name>compile},
\texttt{name>string}, \texttt{name>link}). The
implementation of each method can be changed
per-word (prototype-based object-oriented
programming). We demonstrate how to use these
features to implement optimization of constants,
\texttt{fvalue}, \texttt{defer}, \texttt{immediate},
\texttt{to} and other dual-semantics words, and
\texttt{synonym}.}
}
@Proceedings{euroforth19,
title = {35th EuroForth Conference},
booktitle = {35th EuroForth Conference},
year = {2019},
key = {EuroForth'19},
url = {
http://www.euroforth.org/ef19/papers/proceedings.pdf}
}
- 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 2020:
https://euro.theforth.net/2020