Re: Stack vs stackless operation

Liste des GroupesRevenir à cl forth 
Sujet : Re: Stack vs stackless operation
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forth
Date : 27. Feb 2025, 08:29:44
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Feb27.082944@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6
User-Agent : xrn 10.11
Paul Rubin <no.email@nospam.invalid> writes:
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
: :=: ( addr1 addr2 -- )
    OVER @ >R  DUP @   ROT !   R> SWAP ! ;
>
: ex ( a1 a2 -- ) 2>r 2r@ @ swap  @ r> !  r> ! ;
>
looks a little simpler.

This inspires another one:

: exchange2 ( addr1 addr2 -- )
    dup >r @ over @ r> ! swap ! ;

With some other versions this results in the following benchmark
program:

[defined] !@ [if]
: exchange ( addr1 addr2 -- )
    over @ swap !@ swap ! ;
[then]

\ Paul Rubin <875xkwo5io.fsf@nightsong.com>
: ex ( addr1 addr2 -- )
    2>r 2r@ @ swap  @ r> !  r> ! ;

: ex-locals {: x y -- :} x @ y @ x ! y ! ;

\ Anton Ertl
: exchange2 ( addr1 addr2 -- )
    dup >r @ over @ r> ! swap ! ;

\ Marcel Hendrix
: :=: ( addr1 addr2 -- )
    OVER @ >R  DUP @   ROT !   R> SWAP ! ;

variable v1
variable v2

1 v1 !
2 v2 !

: bench ( "name" -- )
    v1 v2
    :noname ]] 100000000 0 do 2dup [[ parse-name evaluate ]] loop ; [[
    execute ;

Results (on Zen4):

gforth-fast (development):
      :=:        exchange         ex        ex-locals      exchange2
  814_881_277   879_389_133   928_825_521   875_574_895   808_543_975 cyc.
3_908_874_164 3_708_891_336 4_508_966_770 4_209_778_557 3_708_865_505 inst.

vfx64 5.43:
      :=:                        ex          ex-locals    exchange2
  335_298_202                 432_614_804   928_542_678   336_134_513 cyc.
1_166_400_242               1_366_264_943 2_866_547_067 1_166_280_641 inst.

And here's the code produced by gforth-fast:

:=:                ex                 ex-locals          exchange2
over    1->2       2>r    1->0        l    1->1         dup >r 1->1
  mov r15,$08[r10]   add r10,$08        mov rax,rbp      >r    1->1
@    2->2            mov r15,r13        add r10,$08        mov -$8[r14],r13
  mov r15,[r15]      mov r13,[r10]      lea rbp,-$8[rbp]   sub r14,$08
r    2->1           mov -$8[r14],r13   mov -$8[rax],r13 @    1->1
  mov -$8[r14],r15   sub r14,$10        mov r13,[r10]      mov r13,$00[r13]
  sub r14,$08        mov [r14],r15    >l @local0 1->1    over    1->2
dup    1->2        2r@    0->2        @local0    1->1      mov r15,$08[r10]
  mov r15,r13        mov r13,$08[r14]   mov rax,rbp      @    2->2
@    2->2            mov r15,[r14]      lea rbp,-$8[rbp]   mov r15,[r15]
  mov r15,[r15]    @    2->2            mov -$8[rax],r13 r>    2->3
rot    2->3          mov r15,[r15]    @    1->1            mov r9,[r14]
  mov r9,$08[r10]  swap    2->2         mov r13,$00[r13]   add r14,$08
  add r10,$08        mov rax,r13      @local1    1->2    !    3->1
!    3->1            mov r13,r15        mov r15,$08[rbp]   mov [r9],r15
  mov [r9],r15       mov r15,rax      @    2->2          swap    1->2
r>    1->2         @    2->2            mov r15,[r15]      mov r15,$08[r10]
  mov r15,[r14]      mov r15,[r15]    @local0    2->3      add r10,$08
  add r14,$08      r>    2->3           mov r9,$00[rbp]  !    2->0
swap    2->3         mov r9,[r14]     !    3->1            mov [r15],r13
  add r10,$08        add r14,$08        mov [r9],r15     ;s    0->1
  mov r9,r13       !    3->1          @local1    1->2      mov r13,$08[r10]
  mov r13,[r10]      mov [r9],r15       mov r15,$08[rbp]   add r10,$08
!    3->1          r>    1->2         !    2->0            mov rbx,[r14]
  mov [r9],r15       mov r15,[r14]      mov [r15],r13      add r14,$08
;s    1->1           add r14,$08      lp+2    0->1         mov rax,[rbx]
  mov rbx,[r14]    !    2->0            mov r13,$08[r10]   jmp eax
  add r14,$08        mov [r15],r13      add r10,$08
  mov rax,[rbx]    ;s    0->1           add rbp,$10
  jmp eax            mov r13,$08[r10] ;s    1->1
                     add r10,$08        mov rbx,[r14]
                     mov rbx,[r14]      add r14,$08
                     add r14,$08        mov rax,[rbx]
                     mov rax,[rbx]      jmp eax
                     jmp eax

- 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/

Date Sujet#  Auteur
24 Feb 25 * Stack vs stackless operation72LIT
24 Feb 25 +* Re: Stack vs stackless operation4minforth
24 Feb 25 i`* Re: Stack vs stackless operation3LIT
24 Feb 25 i `* Re: Stack vs stackless operation2minforth
24 Feb 25 i  `- Re: Stack vs stackless operation1LIT
24 Feb 25 +* Re: Stack vs stackless operation14Anton Ertl
24 Feb 25 i`* Re: Stack vs stackless operation13LIT
25 Feb 25 i `* Re: Stack vs stackless operation12Anton Ertl
25 Feb 25 i  `* Re: Stack vs stackless operation11LIT
25 Feb 25 i   `* Re: Stack vs stackless operation10Anton Ertl
25 Feb 25 i    `* Re: Stack vs stackless operation9LIT
25 Feb 25 i     +* Re: Stack vs stackless operation5minforth
25 Feb 25 i     i`* Re: Stack vs stackless operation4LIT
25 Feb 25 i     i `* Re: Stack vs stackless operation3minforth
25 Feb 25 i     i  `* Re: Stack vs stackless operation2LIT
25 Feb 25 i     i   `- Re: Stack vs stackless operation1Gerry Jackson
25 Feb 25 i     `* Re: Stack vs stackless operation3Anton Ertl
25 Feb 25 i      `* Re: Stack vs stackless operation2LIT
25 Feb 25 i       `- Re: Stack vs stackless operation1Anton Ertl
25 Feb 25 +* Re: Stack vs stackless operation9dxf
25 Feb 25 i`* Re: Stack vs stackless operation8LIT
25 Feb 25 i +* Re: Stack vs stackless operation6dxf
25 Feb 25 i i`* Re: Stack vs stackless operation5LIT
26 Feb 25 i i `* Re: Stack vs stackless operation4dxf
26 Feb 25 i i  `* Re: Stack vs stackless operation3LIT
26 Feb 25 i i   `* Re: Stack vs stackless operation2minforth
26 Feb 25 i i    `- Re: Stack vs stackless operation1LIT
25 Feb 25 i `- Re: Stack vs stackless operation1Hans Bezemer
25 Feb 25 +* Re: Stack vs stackless operation2LIT
25 Feb 25 i`- do...loop (was: Stack vs stackless operation)1Anton Ertl
25 Feb 25 +* Re: Stack vs stackless operation10LIT
26 Feb 25 i`* Re: Stack vs stackless operation9Hans Bezemer
26 Feb 25 i `* Re: Stack vs stackless operation8LIT
26 Feb 25 i  `* Re: Stack vs stackless operation7Hans Bezemer
26 Feb 25 i   `* Re: Stack vs stackless operation6LIT
27 Feb 25 i    `* Re: Stack vs stackless operation5LIT
27 Feb 25 i     `* Re: Stack vs stackless operation4LIT
2 Mar 25 i      `* Re: Stack vs stackless operation3LIT
5 Mar 25 i       `* Re: Stack vs stackless operation2Hans Bezemer
6 Mar 25 i        `- Re: Stack vs stackless operation1LIT
25 Feb 25 `* Re: Stack vs stackless operation32LIT
25 Feb 25  +* Re: Stack vs stackless operation10Anton Ertl
25 Feb 25  i+- Re: Stack vs stackless operation1LIT
26 Feb 25  i`* Re: Stack vs stackless operation8LIT
26 Feb 25  i +- Re: Stack vs stackless operation1LIT
26 Feb 25  i `* Re: Stack vs stackless operation6John Ames
26 Feb 25  i  `* Re: Stack vs stackless operation5LIT
27 Feb 25  i   `* Re: Stack vs stackless operation4dxf
27 Feb 25  i    `* Re: Stack vs stackless operation3LIT
27 Feb 25  i     `* Re: Stack vs stackless operation2Hans Bezemer
27 Feb 25  i      `- Re: Stack vs stackless operation1LIT
26 Feb 25  +* Re: Stack vs stackless operation2Waldek Hebisch
26 Feb 25  i`- Re: Stack vs stackless operation1Anton Ertl
26 Feb 25  `* Re: Stack vs stackless operation19mhx
26 Feb 25   +- Re: Stack vs stackless operation1minforth
26 Feb 25   +* Re: Stack vs stackless operation16Anton Ertl
26 Feb 25   i`* Re: Stack vs stackless operation15Anton Ertl
26 Feb 25   i +* Re: Stack vs stackless operation7Paul Rubin
26 Feb 25   i i+- Re: Stack vs stackless operation1minforth
27 Feb 25   i i`* Re: Stack vs stackless operation5Anton Ertl
27 Feb 25   i i +* Re: Stack vs stackless operation2Paul Rubin
27 Feb 25   i i i`- Re: Stack vs stackless operation1Anton Ertl
27 Feb 25   i i `* Re: Stack vs stackless operation2Gerry Jackson
27 Feb 25   i i  `- Re: Stack vs stackless operation1Anton Ertl
28 Feb 25   i `* Re: Stack vs stackless operation7Anton Ertl
28 Feb 25   i  `* Re: Stack vs stackless operation6Paul Rubin
1 Mar 25   i   `* Re: Stack vs stackless operation5Anton Ertl
1 Mar 25   i    +- Stack caching (: Stack vs stackless operation)1Anton Ertl
1 Mar 25   i    `* Re: Stack vs stackless operation3Anton Ertl
1 Mar 25   i     `* Re: Stack vs stackless operation2Anton Ertl
1 Mar 25   i      `- Re: Stack vs stackless operation1mhx
27 Feb 25   `- Re: Stack vs stackless operation1mhx

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal