Re: Moving memory blocks in Forth
- From: foxchip <fox@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Nov 2007 07:06:13 -0800 (PST)
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
.
- References:
- Moving memory blocks in Forth
- From: Jürgen Böhm
- Moving memory blocks in Forth
- Prev by Date: Re: Moving memory blocks in Forth
- Next by Date: Re: Define SWAP through DUP and arithmetics?
- Previous by thread: Re: Moving memory blocks in Forth
- Next by thread: Re: Moving memory blocks in Forth
- Index(es):
Relevant Pages
|