• Re: Actually... why =?UTF-8?B?bm90Pw==?=

    From Anton Ertl@21:1/5 to LIT on Wed Jun 11 21:16:06 2025
    zbigniew2011@gmail.com (LIT) writes:
    I mean: when a variable if found,
    instead of its CFA - 'LIT PFA' should
    be compiled directly. When a constant
    is found — 'LIT <value>' should be compiled,
    instead of constant's CFA.

    That's what you get in Gforth since before 0.7:

    variable v ok
    5 constant c ok
    : foo v c ; ok
    simple-see foo
    $7FCBB58A0DF8 lit 0->0
    $7FCBB58A0E00 v
    $7FCBB58A0E08 lit 0->0
    $7FCBB58A0E10 #5
    $7FCBB58A0E18 ;s 0->0 ok

    The disassembly varies a little by version.

    Do I miss anything, any eventual problem?

    It requires more work in COMPILE, than just doing a ",". But having a user-extensible intelligent COMPILE, (like Gforth) offers a number of advantages, especially for native-code compilers.

    - 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: https://forth-standard.org/
    EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to LIT on Thu Jun 12 10:08:02 2025
    zbigniew2011@gmail.com (LIT) writes:
    It requires more work in COMPILE, than just doing a ",". But having a
    user-extensible intelligent COMPILE, (like Gforth) offers a number of
    advantages, especially for native-code compilers.
    ...
    It's actually unbelievable! All it takes is rather
    minor modification in INTERPRET.

    It only requires a change to COMPILE,. No change in INTERPRET.

    So throughout
    all these years since 70s FORTH could execute
    the programs significantly faster - but they
    were all the time selling/giving away the listings
    that DIDN'T feature such advantageous change?

    In the 1970s and early 1980s the bigger problem was code size rather
    than code performance. And if you compile a variable or constant into
    the CFA of the variable, this costs one cell, whereas compiling it
    into LIT followed by the address or value costs two cells. You can
    try this out in Gforth, which includes a traditional-style ITC engine
    (that compiles with "," in nearly all cases) and an engine that uses
    an intelligent COMPILE,. When you do

    variable v
    5 constant c
    : foo v c ;
    simple-see foo

    the output is:

    gforth
    $7F728BAA0DF8 lit 0->0 $7F23366A0E10 v
    $7F728BAA0E00 v $7F23366A0E18 c
    $7F728BAA0E08 lit 0->0 $7F23366A0E20 ;s
    $7F728BAA0E10 #5
    $7F728BAA0E18 ;s 0->0

    As for performance, here is what I measure on gforth-itc:

    sieve bubble matrix fib fft compile,
    0.173 0.187 0.142 0.253 0.085 ,
    0.164 0.191 0.134 0.242 0.088 opt-compile,

    There is quite a bit of variation between the runs on the Zen4 machine
    where I measured this.

    Invocation with

    gforth-itc onebench.fs # for compiling with ,
    gforth-itc -e "' opt-compile, is compile," onebench.fs

    And even today the compiler creators don't apply
    it, for no particular reason?

    Which compiler creators do you have in mind? Those that compile for
    MS-DOS? With 64KB segments, they may prefer to be stingy with the
    code size.

    - 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: https://forth-standard.org/
    EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to zbigniew2011@gmail.com on Thu Jun 12 16:21:16 2025
    zbigniew2011@gmail.com (LIT) writes:
    [Someone wrote:]
    In the 1970s and early 1980s the bigger problem was code size rather
    than code performance. And if you compile a variable or constant into
    the CFA of the variable, this costs one cell, whereas compiling it
    into LIT followed by the address or value costs two cells.

    Please, have a mercy... :D it's A SINGLE cell you're
    talking about.

    It's a doubling of the threaded code for every use of a variable,
    constant, colon definition (call <addr>), etc.

    Even, if (let's assume) the two bytes
    may(?) have some meaning during 70s, still in the 80s -
    in the era, when 16 KB of RAM, and soon later 64 KB
    became de facto standard - it wasn't sane decision(?)
    to cripple the compiler(s) by "saving" (literally)
    a few bytes.

    If it's only a few bytes, that would mean that variables, constants,
    colon definitions etc. are not invoked much. In that case the savings
    in run-time are also likely to be small.

    As for the relevance of the difference in 64KB, I know of Forth
    programs that use more than 64KB, so it's not as if 64KB make it
    unnecessary to be economical with space.

    I measured loading brew (without running a benchmark) into gforth-itc.
    When compiling with "," (default in gforth-itc), the size on a 64-bit
    system grew by 748560 bytes, while with "opt-compile,", it grew by
    939448 bytes. That's a factor 1.255 difference.

    64 KB is a whole lot compared to "savings"
    of (literally) two-byte size per VARIABLE/CONSTANT
    definition. Say we've got 200 of them together
    in the program — so 400 bytes has been "saved"
    at a cost of significantly degraded performance.

    If we take the factor 1.255, a program that fits into 64KB when
    compiling with "," needs more than 80KB with "OPT-COMPILE,". Now trim
    this factor from the program in order to make it fit. The easiest way
    is to go back to compiling with ",".

    As for "significantly degraded performance", as long as you stick with
    ITC, my results don't show that.

    - 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: https://forth-standard.org/
    EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)