I was playing with the new colorForth releases and got on a tangent...
I have always wanted to know why SWAP and not XCHG
and I believe it is well described here...
http://en.wikipedia.org/wiki/XOR_swap_algorithm
I was looking at the swap situation described in
http://greenarraychips.com/home/documents/greg/cf-code-library.htm
and remembered there was such a thing as xor exchange type of swap,
hence the wikipedia page.
About most of the way down there is a section on XCHG that describes
it's tendancy to LOCK and to need hundreds of cycles for other devices
to do "their thing" in order to work properly.
I suppose I've been confused on this issue for a while.
I hope this is informative. Did you already know?
Ray
Did you mean why was the name 'SWAP' chosen over 'XCHG'? It seems to
me that 'SWAP' is preferred because it's actually a word and is no
longer to type than 'XCHG'. I think the locking mentioned in the
article was to ensure that only one task has access to memory at a
time. In the Green Arrays example the exclusive or can only be
performed on the stack, not in memory, thus the 'over push' and 'pop'.
The most important thing for a Green Arrays programmer to remember
about 'SWAP' though, is that 'OVER' does the job just fine, as long as
you can afford to abandon the extra third item on the stack. It's
called 'programming with abandon'. It's because of the circular
stacks. I think you'll like it.
One more thing. The documentation on the Green Arrays website is
intended to help people learn to program Green Arrays chips, not to
help people program PC's in colorforth. The goal right now is to sell
chips.
Thanks for the pointer to the Wikipedia article,
Charley.
On Fri, Jan 29, 2010 at 5:40 PM, charley <csha...@surewest.net> wrote:
> Hi Ray,
>
> Did you mean why was the name 'SWAP' chosen over 'XCHG'? It seems to
> me that 'SWAP' is preferred because it's actually a word and is no
> longer to type than 'XCHG'. I think the locking mentioned in the
> article was to ensure that only one task has access to memory at a
> time. In the Green Arrays example the exclusive or can only be
> performed on the stack, not in memory, thus the 'over push' and 'pop'.
>
Hi Charley, my great pleasure to make your acquaintance...
Your sim is so sweet! Nicely done.
I was referring to the fact that Block 20 defines a 3 register swap,
( for them that might not know ) between EAX ( the value pointed to by
the pointer held in ) ESI, and the address register EDX.
This really is a non--issue, unless one, like myself, knew about the
Pentium two register OP XCHG, for which I assumed would be more
efficient. This before I ( FINALLY) looked it up like I should of 114
months ago.
> The most important thing for a Green Arrays programmer to remember
> about 'SWAP' though, is that 'OVER' does the job just fine, as long as
> you can afford to abandon the extra third item on the stack. It's
> called 'programming with abandon'. It's because of the circular
> stacks. I think you'll like it.
So very clever!
( my focus moving from Pentium to Chip but to say...)
In Pentium colorForth, there is always, well, nearly, some way
to eliminate SWAP. And just like in the description you give above,
OVER ( then to do later) DROP, PUSH+POP combos, clever
alignments of the vectors with swap avoidance in mind... ( which
is another way of saying swapping during edit time going backwards
from ultimate usage through any necessary preparatory
conditioning of values to their ultimate definitions, possibly)
Now, if one were not in the 'InnerColorCircle" of developers, having
to spend copious time trying to figure out "why include SWAP on
block 20 at all?" and it has to be that EDX residue address.
I mean by residue, the fact that one can load EDX with an address
during SWAP, and if one can make benefit of such a situation
that might be pretty darn handy. I've not done it yet. Prob'ly
should before I take this any further.
>
> One more thing. The documentation on the Green Arrays website is
> intended to help people learn to program Green Arrays chips, not to
> help people program PC's in colorforth. The goal right now is to sell
> chips.
>
> Thanks for the pointer to the Wikipedia article,
> Charley.
>
>
My new personal goal is both ideas. :) Good luck to GA!
and again, Charley, this thing... NICE!
Thanks for your work and your reply
Ray
--
Raymond St. Marie ii,
public E-mail Ray.s...@gmail.com
a quickstart guide http://colorforthray.info
http://groups.google.com/group/Color-Forth
Community Blog http://colorForth.net
Community Wiki http://ForthWorks.com/c4th
The Movies http://YouTube.com/Raystm2