Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #42087
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: old `leave` renamed to `exhaust` |
| Date | 2015-09-19 15:02 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2015Sep19.170230@mips.complang.tuwien.ac.at> (permalink) |
| References | (5 earlier) <y7pior0acvxj.ch2dlom72stl$.dlg@40tude.net> <2015Sep15.171318@mips.complang.tuwien.ac.at> <mtieeo$h7v$1@speranza.aioe.org> <2015Sep19.124814@mips.complang.tuwien.ac.at> <mtjpq7$3rd$1@speranza.aioe.org> |
"HAA" <someone@microsoft.com> writes:
>Anton Ertl wrote:
>> "HAA" <someone@microsoft.com> writes:
>> >Anton Ertl wrote:
>> >>
>> >> The current looping constructs for negative stride in Gforth still
>> >> have one weakness, though:
>> >>
>> >> When walking backwards over an array addr u of cells, we would like to
>> >> start with addr u 1- cells + and end with addr, but that's relatively
>> >> cumbersome to express, e.g.:
>> >>
>> >> addr 1 cells - addr u 1- cells + ?do ... i ... 1 cells -loop
>> >>
>> >> or (less run-time efficiency)
>> >>
>> >> addr addr u cells + ?do ... i 1 cells - ... 1 cells -loop
>> >>
>> >> - anton
>> >
>> >Typically addr u will be constants and u > 1 which your program can exploit:
>> >
>> > 0 u 1- do ... i cells addr + ... -1 +loop
>>
>> You need to replace 0 with -1 in order to be equivalent to the
>> variants above.
>
>Such a change would result in u+1 iterations
Yes, sorry, I had not noticed that you use the broken "-1 +loop".
As a simple task (with the proper counted loop), implement a word:
rev-type ( c-addr u -- )
that prints an ASCII string in reverse. E.g.
s" dog" cr char " emit rev-type char " emit \ prints "god"
s" x" cr char " emit rev-type char " emit \ prints "x"
s" " cr char " emit rev-type char " emit \ prints ""
>> Depending on the implementation and CPU, this may be
>> slower at run-time than the variants above.
>
>On VFX -1 +LOOP is 3 machine instructions and CELLS ADDR +
>is 2 instructions.
On VFX no words (as in the first variant) is 0 instructions.
>I don't see the runtime for -LOOP being less.
Let's just use Gforth's compat/loops.fs with VFX, and for
: foo u-do i @ + 1 cells -loop ;
(loop setup elided, because it does not affect the inner loop)
we get the following inner loop:
( 080BF5F8 8B1424 ) MOV EDX, [ESP]
( 080BF5FB 031A ) ADD EBX, 0 [EDX]
( 080BF5FD 830424FC ) ADD [ESP], -04
( 080BF601 83442404FC ) ADD [ESP+04], -04
( 080BF606 71F0 ) JNO 080BF5F8
Let's do the equivalent with your code:
: bar do over i cells + @ + -1 +loop ;
The inner loop is:
( 080BF5F0 8B1424 ) MOV EDX, [ESP]
( 080BF5F3 C1E202 ) SHL EDX, 02
( 080BF5F6 035500 ) ADD EDX, [EBP]
( 080BF5F9 031A ) ADD EBX, 0 [EDX]
( 080BF5FB 830424FF ) ADD [ESP], -01
( 080BF5FF 83442404FF ) ADD [ESP+04], -01
( 080BF604 71EA ) JNO 080BF5F0
Two instructions more; the -LOOP implementation in compat/loops.fs
implementation has some limitations, in particular, it's based on
+LOOP, so it cannot be more efficient than +LOOP; but the overhead of
computing addresses in the inner loop is still there in your code.
- 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 2015: http://www.rigwit.co.uk/EuroForth2015/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
old `leave` renamed to `exhaust` Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2015-09-07 20:29 +0000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-08 14:52 +1000
Re: old `leave` renamed to `exhaust` Mark Wills <markwills1970@gmail.com> - 2015-09-08 00:57 -0700
Re: old `leave` renamed to `exhaust` Bernd Paysan <bernd.paysan@gmx.de> - 2015-09-08 15:19 +0200
Re: old `leave` renamed to `exhaust` Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2015-09-08 16:25 +0000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-09 11:39 +1000
Re: old `leave` renamed to `exhaust` Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2015-09-09 10:42 +0000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-10 14:05 +1000
Re: old `leave` renamed to `exhaust` Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2015-09-10 13:33 +0000
Re: old `leave` renamed to `exhaust` Coos Haak <chforth@hccnet.nl> - 2015-09-10 22:04 +0200
Re: old `leave` renamed to `exhaust` Coos Haak <chforth@hccnet.nl> - 2015-09-10 22:13 +0200
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-11 13:14 +1000
Re: old `leave` renamed to `exhaust` Coos Haak <chforth@hccnet.nl> - 2015-09-11 12:30 +0200
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-11 21:47 +1000
Re: old `leave` renamed to `exhaust` Bernd Paysan <bernd.paysan@gmx.de> - 2015-09-11 14:09 +0200
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-12 11:29 +1000
Re: old `leave` renamed to `exhaust` "Elizabeth D. Rather" <erather@forth.com> - 2015-09-11 16:05 -1000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-14 12:25 +1000
Re: old `leave` renamed to `exhaust` "Elizabeth D. Rather" <erather@forth.com> - 2015-09-13 17:53 -1000
Re: old `leave` renamed to `exhaust` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-09-14 08:33 +0000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-15 16:55 +1000
Re: old `leave` renamed to `exhaust` hughaguilar96@gmail.com - 2015-09-15 01:46 -0700
Re: old `leave` renamed to `exhaust` Coos Haak <chforth@hccnet.nl> - 2015-09-15 15:14 +0200
Re: old `leave` renamed to `exhaust` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-09-15 15:13 +0000
Re: old `leave` renamed to `exhaust` hughaguilar96@gmail.com - 2015-09-15 16:13 -0700
Re: old `leave` renamed to `exhaust` jim.brakefield@ieee.org - 2015-09-15 17:05 -0700
Re: old `leave` renamed to `exhaust` hughaguilar96@gmail.com - 2015-09-15 18:35 -0700
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-19 11:42 +1000
Re: old `leave` renamed to `exhaust` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-09-19 10:48 +0000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-20 00:01 +1000
Re: old `leave` renamed to `exhaust` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-09-19 15:02 +0000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-21 15:51 +1000
Re: old `leave` renamed to `exhaust` "Elizabeth D. Rather" <erather@forth.com> - 2015-09-15 08:45 -1000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-16 11:18 +1000
Re: old `leave` renamed to `exhaust` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-09-16 06:10 +0000
Re: old `leave` renamed to `exhaust` "HAA" <someone@microsoft.com> - 2015-09-17 15:15 +1000
Re: old `leave` renamed to `exhaust` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-09-17 06:04 +0000
Re: old `leave` renamed to `exhaust` Coos Haak <chforth@hccnet.nl> - 2015-09-11 14:16 +0200
csiph-web