| Deutsch English Français Italiano |
|
<2025Mar1.083209@mips.complang.tuwien.ac.at> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!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: Re: Stack vs stackless operation
Date: Sat, 01 Mar 2025 07:32:09 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 77
Message-ID: <2025Mar1.083209@mips.complang.tuwien.ac.at>
References: <591e7bf58ebb1f90bd34fba20c730b83@www.novabbs.com> <34df278ef0a52d0eab9d035f45795389@www.novabbs.com> <a6c9d8a0aa7e1046af7948093e07cff0@www.novabbs.com> <2025Feb26.153250@mips.complang.tuwien.ac.at> <2025Feb26.184613@mips.complang.tuwien.ac.at> <2025Feb28.225505@mips.complang.tuwien.ac.at> <87wmd9n0xx.fsf@nightsong.com>
Injection-Date: Sat, 01 Mar 2025 09:08:10 +0100 (CET)
Injection-Info: dont-email.me; posting-host="8853c40709c89d32b754b24417cf3527";
logging-data="160495"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BP7rYhIuBRJEgdUkh+jkh"
Cancel-Lock: sha1:z1P8LBm4W0jkVvPwWL1FNWXiDzU=
X-newsreader: xrn 10.11
Bytes: 4704
Paul Rubin <no.email@nospam.invalid> writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>> !@ is now the nonatomic version.
>
>Is the nonatomic one useful often?
Some numbers of uses in the Gforth image:
11 !@
3 atomic!@
66 +!
> We've done without it all this time.
Sure, you can replace it with DUP @ >R ! R>. Having a word for that
relieves the programmer of producing such a sequence (possibly with a
bug) and the reader of having to analyse what's going on here.
I have now added stack-state variants for !@, resulting in better
performance in some cases. Is !@ used often enough to merit the extra
build time of Gforth? That's not clear, but the benefit I see is that
I want to provide a system where the programmer does not have to
wonder whether he should avoid !@ for better performance.
I also tried out another variant that uses !@:
: exchange4 ( addr1 addr2 -- )
dup @ rot !@ swap ! ;
The resulting code for EXCHANGE, EXCHANGE4, and EXCHANGE2 (the latter
without !@):
see-code exchange see-code exchange4 see-code exchange2
over 1->2 dup 1->2 dup >r 1->1
mov r15,$08[r12] mov r15,r8 >r 1->1
@ 2->2 @ 2->2 mov -$08[r13],r8
mov r15,[r15] mov r15,[r15] sub r13,$08
swap 2->3 rot 2->3 @ 1->1
add r12,$08 mov r9,$08[r12] mov r8,[r8]
mov r9,r8 add r12,$08 over 1->2
mov r8,[r12] !@ 3->2 mov r15,$08[r12]
!@ 3->2 mov rax,r15 @ 2->2
mov rax,r15 mov r15,[r9] mov r15,[r15]
mov r15,[r9] mov [r9],rax r> 2->3
mov [r9],rax swap 2->3 mov r9,$00[r13]
swap 2->3 add r12,$08 add r13,$08
add r12,$08 mov r9,r8 ! 3->1
mov r9,r8 mov r8,[r12] mov [r9],r15
mov r8,[r12] ! 3->1 swap 1->2
! 3->1 mov [r9],r15 mov r15,$08[r12]
mov [r9],r15 ;s 1->1 add r12,$08
;s 1->1 mov rbx,$00[r13] ! 2->0
mov rbx,$00[r13] add r13,$08 mov [r15],r8
add r13,$08 mov rax,[rbx] ;s 0->1
mov rax,[rbx] jmp eax mov r8,$08[r12]
jmp eax add r12,$08
mov rbx,$00[r13]
add r13,$08
mov rax,[rbx]
jmp eax
EXCHANGE performs 1 instruction less than EXCHANGE2, EXCHANGE4
performs 2 instructions less than EXCHANGE2; both contain three less
primitives.
Performance on Zen4:
exchange exchange4 exchange2
748_033_428 699_870_875 809_204_577 cycles
3_610_871_416 3_510_578_833 3_710_662_751 instructions
- 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/