Re: Moving memory blocks in Forth



On Nov 27, 10:11 pm, Jürgen Böhm <jbo...@xxxxxxx> wrote:
Hello,

currently I am designing a stack-processor for Lisp applications and
made some tests on the speed of a routine for moving a block of N words
(4 byte/word). As my instruction set is not so powerful I need 10 to 12
instructions per moved word - now I am really curious how many
instructions one would need using Forth.

Standard Forth has MOVE ( addr1 addr2 count -- ) to move words so one
might say one word. If you don't have a MOVE already implemented then
you will have to write it using more primitive Forth words. You can
write it in Forth or using a Forth assembler. Traditionally in non-
optimizing compilers it would be a code word in assembler so that
it would be as efficient as possible.

Unfortunately my knowledge of Forth is nearly nil, so I would like
to ask here at the group how a typical Forth program for the task
(moving N words starting from address a to address b and following)
could look.

To generalize a bit, I am under the impression that heap oriented
processing (computing with arrays, moving memory blocks and the like)
generally causes some efficiency problems with stack oriented
languages/CPUs compared with register CPUs - would you agree with that,
or does your experience shows otherwise?

Moving memory blocks requires two memory pointers and as high level
Forth has only the top of stack as a pointer a high level version
may have stack juggling although an optimizing compiler might
eliminate it int he compiled code using the native instruction
set to do it most efficiently. Optimizing compilers try to
take advantage of whatever register machines have to offer.

Machines designed to do Forth may not have memory to memory move
opcodes and may load to the stack and store from the stack using
pointers in registers. And the stack storage between memory is
a register also so only two memory operations are needed. But
the machines are designed to do efficient what they do most
often and copying memory from on location to another is done
far less often than copying from one processor to another
in small parallel Forth hardware.

Because we do memory to memory copy so infrequently we
have only one auto-incrementing addressing register for loads
and stores since usually in the parallel architecture one
pointer will not increment. With two auto-incrementing
pointer opcodes MOVE could be something like

: MOVE ( a1 a2 cnt -- ) \ move cnt+1 words from a1 to a2
push b! a! begin @a+ !b+ unext ;

which is two words of code and a one word loop and has
only data fetches and stores inside the loop.

If you are designing the processor then you can select
opcodes designed to what you intend to do with the chip.

Standard Forth also offers CMOVE and CMOVE> to move bytes
down or up in case the memory areas overlap.

Best Wishes
.



Relevant Pages

  • Re: If Macs have no spyware....
    ... >had made a complete code review of its operating system and removed all ... and writing new data into those memory locations would ... >but when the data exists on the stack, it can cause very large problems. ... >location that needs to be written in place of the correct execution ...
    (comp.sys.mac.advocacy)
  • Re: If Macs have no spyware....
    ... First you yammer about being a Mac advocate, then bad mouth me for dumping XP in favor of a Mac. ... Supposedly Microsoft had made a complete code review of its operating system and removed all the buffers which could overflow. ... the fundamental problem is that the basic architecture of Windows has two fatal flaws in its memory management and while these remain in the software the ad hoc patches will never be enough to make Windows a secure operating system. ... These problems are bad enough when dealing with data in the one routine but when the data exists on the stack, it can cause very large problems. ...
    (comp.sys.mac.advocacy)
  • Re: Maybe we should stop "Paging Beth Stone" already...
    ... I'll want to work on my OS while running my OS, so the assembler that it's written with has to run under it. ... You have to swap CR3 if you want seperate memory spaces. ... The alternate stacks aren't used by the processor unless the task calls a different protection level, so they're not part of the TSS swap. ... This lets any application use up to a gigabyte of stack before Linux is forced to tell it that it's gone too far. ...
    (alt.lang.asm)
  • Re: When is "volatile" used instead of "lock" ?
    ... to get the address of a stack variable to a background thread. ... I'm suggesting that the memory model ... lock pattern works without making the instance member volatile; ... fields shared amongst more than one thread despite following the locking ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Resolving internal links
    ... You have to pass all workspace in via ... Which highlights another issue - you could not use Fortify (or similar code which uses these functions to replace the memory allocators) within the main application code unless you also used it within the module. ... At best you'll reference memory which does not exist and cause an abort. ... will only be able to use 256 bytes of stack space IIRC. ...
    (comp.sys.acorn.programmer)