17.6.1.0910 CMOVE c-move STRING
( c-addr1 c-addr2 u -- )
If u is greater than zero, copy u consecutive characters from the data space starting at c-addr1 to that starting at c-addr2, proceeding character-by-character from lower addresses to higher addresses.
See:
Rationale:
If c-addr2 lies within the source region (i.e., when
c-addr2 is not less than c-addr1 and
c-addr2 is less than the quantity c-addr1 u
CHARS +), memory propagation occurs.
Assume a character string at address 100: "ABCD". Then after
the string at address 100 is "AAAA".
See A.6.1.1900 MOVE.
ContributeContributions
AntonErtl [211] CMOVE implementation based on MOVESuggested reference implementation2021-09-02 10:52:45
: cmove {: afrom ato u | u1 -- :}
ato afrom - u u< if \ pattern replication case
ato afrom - u over + to u1 begin
afrom afrom 2 pick + 2 pick u1 over - min move
2* dup u u>= until
drop
else \ the usual non-pattern case
ato afrom u move
then ;
This is not as simple as copying byte by byte, but significantly more efficient (e.g., factor >10 for 32-bit VFX 4.71 with patterns of length 2) for both cases if MOVE is implemented efficiently.