Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #135504
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: First result in riscv optimiser |
| Date | 2026-09-01 15:33 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2026Sep1.173341@mips.complang.tuwien.ac.at> (permalink) |
| References | <nnd$172defd2$1b2df6f6@e430673098f06a19> |
albert@spenarnc.xs4all.nl writes:
>The ciforth works in reverse of the usual optimisers. Peephole is the
>last step.
That's exactly like usual optimizers. Peephole optimization tends to
be used to catch some things that other optimizations have missed,
typically across the boundaries of the other optimizations.
>Now I have completed the second step: if code works on constant data,
>execute it at compile time, if possible.
>An example:
>albert@sinas2:~/PROJECT/optim$ optimiser
>
>: nonsense DUP 'DROP EXECUTE ;
> OK
> : test 2 4 * nonsense 13 + ;
> OK
> 'test inline&fold
> 2
> LIT
> *
> DUP
> LIT
> EXECUTE
> nonsense
> LIT
> +
> test
> OK
> SEE test
>
>: test
>0000,0000,0000,0015
>;
Gforth does not do inlining by itself yet, but it does have a literal
stack for constant folding and more. See
<2019Aug5.121829@mips.complang.tuwien.ac.at>. Let's take your
example, but using explicit inlining for NONSENSE:
inline: nonsense dup `drop execute ;inline
: test 2 4 * nonsense 13 + ;
see test
\ output follows:
: test
#21 ; ok
Gforth will do that on RISC-V as well as on other architectures,
because these things happen at the threaded-code level.
I don't think that these contrived examples prove much, and in general
I don't think that full constant folding will trigger often, but
partial constant folding (e.g., optimizing "5 -" into lit+ with the
immediate argument -5) is probably relatively frequent, and
occasionally, constant folding works in cases where a much
heavier-weight optimization would otherwise be needed. E.g.,
5e fvalue x
synonym y x
: foo to y ;
FOO is compiled to
: foo
<x> f! ;
where <X> is the body address of X. In the process of this
compilation, several levels of partial constant folding are involved.
There may be other ways to achieve this kind of compilation from this
code, but I think they would be substantially more complicated. IIRC
our EuroForth 2019 paper on the new Gforth header gives an example of
how that works.
- 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
First result in riscv optimiser albert@spenarnc.xs4all.nl - 2026-09-01 10:49 +0200
Re: First result in riscv optimiser anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-09-01 15:33 +0000
Re: First result in riscv optimiser albert@spenarnc.xs4all.nl - 2026-09-01 18:54 +0200
Re: First result in riscv optimiser albert@spenarnc.xs4all.nl - 2026-09-02 11:18 +0200
Re: First result in riscv optimiser Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-04 13:14 -0300
Re: First result in riscv optimiser albert@spenarnc.xs4all.nl - 2026-09-05 13:06 +0200
Re: First result in riscv optimiser Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-08 02:21 -0300
Re: First result in riscv optimiser albert@spenarnc.xs4all.nl - 2026-09-08 12:38 +0200
Re: First result in riscv optimiser Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-11 07:50 -0300
Re: First result in riscv optimiser Paul Rubin <no.email@nospam.invalid> - 2026-09-11 17:09 -0700
Re: First result in riscv optimiser albert@spenarnc.xs4all.nl - 2026-09-13 14:03 +0200
Re: First result in riscv optimiser antispam@fricas.org (Waldek Hebisch) - 2026-09-13 02:53 +0000
csiph-web