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, 23:53:47
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Feb27.235347@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6 7 8
User-Agent : xrn 10.11
Gerry Jackson <do-not-use@swldwa.uk> writes:
On 27/02/2025 07:29, Anton Ertl wrote:
\ Anton Ertl
: exchange2 ( addr1 addr2 -- )
     dup >r @ over @ r> ! swap ! ;
...
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.
...
How does a crude definition not involving the R stack compare:
: ex3  over @ over @ 3 pick ! over ! 2drop ;

exchange2                  ex3
dup >r     1->1           over    1->1
r    1->1                  mov     [r10],r13
  mov     -$08[r14],r13     sub     r10,$08
  sub     r14,$08           mov     r13,$10[r10]
@    1->1                 @    1->1
  mov     r13,$00[r13]      mov     r13,$00[r13]
over    1->2              over    1->2
  mov     r15,$08[r10]      mov     r15,$08[r10]
@    2->2                 @    2->2
  mov     r15,[r15]         mov     r15,[r15]
r>    2->3                fourth    2->3
  mov     r9,[r14]          mov     r9,$10[r10]
  add     r14,$08         !    3->1
!    3->1                   mov     [r9],r15
  mov     [r9],r15        over    1->2
swap    1->2                mov     r15,$08[r10]
  mov     r15,$08[r10]    !    2->0
  add     r10,$08           mov     [r15],r13
!    2->0                 2drop    0->0
  mov     [r15],r13         add     r10,$10
;s    0->1                ;s    0->1
  mov     r13,$08[r10]      mov     r13,$08[r10]
  add     r10,$08           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

EX3 plays to Gforth's strengths: copying words (e.g., OVER) instead of
shuffling words (e.g., SWAP), remove superfluous stuff with 2DROP.

It also plays to VFX's strengths: being analytic about the dats stack.
EXCHANGE2 was the fastest version (together with :=:) before, here's
that compared to EX3:

  exchange2       ex3
  334_718_398   273_592_214   cycles
1_167_276_392   967_258_380   instructions

EXCHANGE2                     EX3                        
PUSH    RBX                   MOV     RDX, [RBP]         
MOV     RDX, [RBP]            MOV     RDX, 0 [RDX]       
MOV     RDX, 0 [RDX]          MOV     RCX, 0 [RBX]       
POP     RCX                   MOV     RAX, [RBP]         
MOV     RBX, 0 [RBX]          MOV     0 [RAX], RCX       
MOV     0 [RCX], RDX          MOV     0 [RBX], RDX       
MOV     RDX, [RBP]            MOV     RBX, [RBP+08]      
MOV     0 [RDX], RBX          LEA     RBP, [RBP+10]      
MOV     RBX, [RBP+08]         RET/NEXT                   
LEA     RBP, [RBP+10]         ( 29 bytes, 9 instructions )
RET/NEXT
( 31 bytes, 11 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/

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