home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd6.lzh
/
TST
/
matrix_mult.tst
< prev
next >
Wrap
Text File
|
1989-12-21
|
1KB
|
52 lines
.( Loading Matrix Multiplication benchmark...) cr
\ A classical benchmark of an O(n**3) algorithm; Matrix Multiplication
\
\ Part of the programs gathered by John Hennessy for the MIPS
\ RISC project at Stanford. Translated to forth by Matin Freamen,
\ Johns Hopkins University/Applied Physics Laboratory.
4 constant cell
: cells ( n -- m) cell * ;
: align ( -- ) here cell 1- and allot ;
variable seed
: initiate-seed ( -- ) 74755 seed ! ;
: random ( -- n ) seed @ 1309 * 13849 + 65535 and dup seed ! ;
40 constant rowsize
rowsize rowsize * cells constant matsize
align create ima rowsize 1+ dup * cells allot
align create imb rowsize 1+ dup * cells allot
align create imr rowsize 1+ dup * cells allot
: initiate-matrix ( m[rowsize+1][rowsize+1] -- )
dup matsize + swap do
random dup 120 / 120 * - 60 - i !
cell +loop ;
: innerproduct ( a[r][*] b[*][c] -- result)
0 rowsize 0 do
>r over @ over @ * r> + >r
cell + swap rowsize cells + swap
r>
loop
swap drop swap drop ;
: matrix-mult ( -- )
initiate-seed
ima initiate-matrix
imb initiate-matrix
imr ima matsize + ima do
imb rowsize cells + imb do
j i innerproduct over ! cell +
cell +loop
rowsize cells +loop
drop ;
forth only