Re: SEAForth questions again

Charles Shattuck <[email protected]>
Newsgroups gmane.comp.lang.forth.colorforth
Message-ID <[email protected]>
I think I can answer one of your questions.  The comments around the
definition of f*f say that it is for multiplying fixed point fractions,
not integers.  These fractions are represented, according to the
comment, as follows:

ss ifff fff ffff ffff

where ss are sign bits (not sure why there are two at this point), i is
an integer, either 0 or 1, and the f's are the bits that represent a
fraction.  For example, the number $8000 would represent 1.0.  $4000
would represent 0.5.  $2000 would be 0.25.  When you multiplied 2 by 5
you were really multiplying a very small fraction by another very small
fraction, and the answer was so small that it was truncated to zero.

I added this:

: asFraction ( num den - fraction) $8000 rot rot */ ;

to help me enter fractions and watch the results of f*f.  This
definition needs to come outside the 'machine' '[' pair, it is not
machineforth.  It is used as follows:

machine
: test-f*f
   [ 1 2 asFraction ]# [ 1 2 asFraction ]# . .
   f*f test-f*f -;

You should see $4000 (0.5) pushed onto the data stack twice, and the
result of f*f is $2000, meaning 0.25.

I assume f*f is only defined in the ROM for the cores with A/D and D/A
is because it will be useful for scaling A/D inputs.

As to how you would multiply the integers in your matrix example, I
don't have an easy answer to that yet, but I'll work on.

Charley.

On Fri, 2006-11-03 at 13:31 -0800, John Drake wrote:
> I've been trying to write my first SEAForth demo.
> To try and exploit the parrallelism I settled on
> matrix multiplication as a test program.  
> I'm trying to multiply a 2 row matrix by a two
> column matrix.  These are the steps I'm attempting.
> 
> 1) Data initially is in node 12
> 2) Row1 is passed to node 18
> 3) Row2 is passed to node 13
> 4) Column1 is passed to nodes 18 and 13 
>    simultaneously
> 5) Multiplications R1*C1 and R2*C1 done 
>    simultaneously
> 6) Column2 is passed to nodes 18 and 13 
>    simultaneously
> 7) Multiplications R1*C2 and R2*C2 done 
>    simultaneously
> 8) Results R1*C1, R1*C2, R2*C1, R2*C2 are 
>    returned to node 12
> 
> I looked at the code runvmram.f as an
> example.  It uses these steps.
> 
> 1) Data initially in node 12
> 2) Data passed through node 13 to node 14
> 3) Node 14 does a difference between the
>    previous and current data value and passes
>    result to node 15
> 4) Node 15 does a "running average" and passes
>    result to node 16
> 5) Node 16 "catches" the data into a buffer
> 
> Here's my first question.  The following code
> is from node 14.
> 
> \ ******* node 14 ********************
> \ differentiator
> \ pass "difference" between current and 
> \ previous to the next node
> 
> decimal
> 14 node !
> 0 org  
> machine
> 
> '--l-  a! . .   \ point reg a to left node
> 'r---  b! . .   \ point reg b to right node
> dup xor         \ init t to zero
> begin  
>   @a over over .  ( curr prev curr )
>   + not ( c c-p )  !b .  ( c ) \ will become p
>   4  drop . .
> again  
> 
> The "+ not" would seem to me to return the
> value -(c+p) rather than (c-p).  Am I missing
> something here?  (This isn't essential to my
> problem, but I'm just trying to understand the
> code.)
> 
> Anyway, here's my own code.  (Note: for the
> sake of brevity I'm only including code for
> nodes 12 and 13 as node 18 is a clone of
> node 13's code.)
> 
> \ ******* node 12 *************************
> \ Pass row1 to node 13, row2 to node 18
> \ and columns 1 and 2 to nodes 13 and 18 
> \ simultaneously
> decimal
> 
> 12 node!  
> $0 org  
> machine
> 
> : send-data
>    begin
>       'r--- b! . .   \ point reg b to right node
>       7 for
>         @p+ !b . unext
>         [  1 ,  2 , 3 , 4 , 5 ,  6 ,  7 ,  8 , ]
>       '-d-- b! . .   \ point reg b to down node
>       7 for
> 	@p+ !b . unext
>         [  9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , ]
>       'rd-- b! 	     \ point reg b to r and d nodes
>       0 !b . . \ dummy write for synch purposes
>       15 for
> 	@p+ !b . unext
>         [ 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 
>           25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , ]
>       $20 a! 'r--- b! 
>       @b !a+ @b !a+
>       '-d-- b! . .
>       @b !a+ @b !a+
>    again
> [
> 
> \ ******* node 13 *****************************
> \ Receive row1 then multiply it by columns 1 and 2 
> \ and return results.
> 
> decimal
> 13 node !  
> 0 org  
> machine
> 
> 'r---  b! . .  \ point b to right node
> $20 dup a! push  \ point a to buffer - push adr
> 
> 7 for 
>   @b !a+ . unext
> 
> @b drop . . 	\ dummy read for synchronization purposes
> 
> pop dup a! push	\ reset a to start of buffer 
> dup xor		\ initilize TOS to 0
> 7 for
>   @b @a+ f*f .
>   + next . .
> 
> dup dup xor .	\ preserve result: 0 TOS
> 
> pop a! . .      \ reset a to start of buffer
> 7 for
>   @b @a+ f*f .
>   + next . .
> 
> !b !b . .	\ Send results back to r node
> 
> Now for my next question.  After running this I
> didn't get correct results.  I'm not sure I'm 
> using f*f correctly.  I put the following test
> code in.
> 
> \ ******* node 23 **********************
> \ Test multiplication
> 
> decimal
> 23 node !
> 0 org  
> machine
> 
> 2 5 f*f .
> 
> But the end result was:
> 
> 23
> 0 .
> a=00000
> b=155
> p=005
> r=15555
> t=00000
> s=15555
> 
> That can't be right.  So I'm wondering what I'm
> doing wrong?  Here is a link to my entire sourcefile
> so someone else can look at this.  
> 
> http://www.quartus.net/twiki/pub/Main/VentureForth/matrix.f
> 
> Note that in order to run this you have to change 
> the rombios.f file.  By default only nodes 18 and 
> 23 have the f*f word compiled.  I copied and 
> pasted that to node 13.
> 
> Other than problems with f*f my code seems to
> work correctly.  It's interesting to watch the
> processors activate-deactivate and to see stuff
> running in parrallel.  While this is a trivial
> example, I did have to deal with solving
> deadlock and race conditions.  I think the 
> VentureForth environment is very helpful for
> immediately spotting such things.
> 
> Regards,
> 
> John M. Drake
> 
> 
> 
>  
> ____________________________________________________________________________________
> Get your email and see which of your friends are online - Right on the New Yahoo.com 
> (http://www.yahoo.com/preview) 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> Main web page - http://www.colorforth.com
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.