From: anton@mips.complang.tuwien.ac.at   
      
   Paul Rubin 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/   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|