Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.lang.forth Subject: do...loop (was: Stack vs stackless operation) Date: Tue, 25 Feb 2025 18:17:55 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 32 Message-ID: <2025Feb25.191755@mips.complang.tuwien.ac.at> References: <591e7bf58ebb1f90bd34fba20c730b83@www.novabbs.com> <925ae8e5dcef84bf1f465b367a6016e2@www.novabbs.com> Injection-Date: Tue, 25 Feb 2025 19:41:00 +0100 (CET) Injection-Info: dont-email.me; posting-host="025acfbbe1d78c9898f57037ac05cd9b"; logging-data="2236277"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ieobGoFp0hh3wx1JPx8JR" Cancel-Lock: sha1:0BREjyQMAzxjvwzX1/udcCM5xYs= X-newsreader: xrn 10.11 Bytes: 2600 zbigniew2011@gmail.com (LIT) writes: >Now I'm pondering about DO..LOOP construct; actually >probably it doesn't necessarily need to rely on return >stack. There are many ways to skin this cat, and I have written at length about that here. For performance you should keep those data in registers that you update in the loop. E.g., a simple way is to have the index and the limit around, and to update the index; then you should keep the index in a register; leaving the unchanging limit in memory is not so bad for performance on many CPUs. You need to save the old index and old limit when entering another do...loop, and restore them on exiting the do...loop, including when you exit with UNLOOP or THROW. Both SwifthForth and VFX switched to keeping the loop control parameters in registers in their 64-bit ports, and at first forgot to restore the old loop control parameters on THROW; they have fixed this bug as soon as it was found. Instead of keeping index and limit, there are also variants that keep other values around, to make +LOOP more efficient (sometimes at the cost of a more expensive I). <2021Jan10.112340@mips.complang.tuwien.ac.at> discusses a number of these variants. - 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/