From cb646db54ae55253ee89216c3f680ea855ddd4ca Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 30 Sep 2009 11:34:19 -0500 Subject: [PATCH 1/4] add a "test-mr." word to compiler.cfg.debugger equivalent to "test-mr mr." --- basis/compiler/cfg/debugger/debugger.factor | 5 ++++- extra/typed/debugger/debugger.factor | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/basis/compiler/cfg/debugger/debugger.factor b/basis/compiler/cfg/debugger/debugger.factor index 9d91215f3d..d4e8c5401a 100644 --- a/basis/compiler/cfg/debugger/debugger.factor +++ b/basis/compiler/cfg/debugger/debugger.factor @@ -44,6 +44,9 @@ M: word test-cfg nl ] each ; +: test-mr. ( quot -- ) + test-mr mr. ; inline + ! Prettyprinting : pprint-loc ( loc word -- ) > pprint* block> ; @@ -79,4 +82,4 @@ M: rs-loc pprint* \ R pprint-loc ; [ [ defs-vreg ] [ defs-vreg-rep ] bi 2dup and [ 2array ] [ 2drop f ] if ] bi [ suffix ] when* ] map concat - ] map concat >hashtable representations set ; \ No newline at end of file + ] map concat >hashtable representations set ; diff --git a/extra/typed/debugger/debugger.factor b/extra/typed/debugger/debugger.factor index 452af16a2e..c5f83c0378 100644 --- a/extra/typed/debugger/debugger.factor +++ b/extra/typed/debugger/debugger.factor @@ -4,5 +4,7 @@ IN: typed.debugger : typed-test-mr ( word -- mrs ) "typed-word" word-prop test-mr ; inline +: typed-test-mr. ( word -- ) + "typed-word" word-prop test-mr mr. ; inline : typed-optimized. ( word -- ) "typed-word" word-prop optimized. ; inline From 3c51312987ac3b26b31a380df726f098143979f0 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 30 Sep 2009 11:51:44 -0500 Subject: [PATCH 2/4] benchmarks for math.matrices and math.matrices.simd building and multiplying 3D matrices (vector versions are still slow because v? and vmask aren't intrinsic yet) --- .../3d-matrix-scalar/3d-matrix-scalar.factor | 23 +++++++++++++++ .../3d-matrix-vector/3d-matrix-vector.factor | 28 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 extra/benchmark/3d-matrix-scalar/3d-matrix-scalar.factor create mode 100644 extra/benchmark/3d-matrix-vector/3d-matrix-vector.factor diff --git a/extra/benchmark/3d-matrix-scalar/3d-matrix-scalar.factor b/extra/benchmark/3d-matrix-scalar/3d-matrix-scalar.factor new file mode 100644 index 0000000000..d629eda6bd --- /dev/null +++ b/extra/benchmark/3d-matrix-scalar/3d-matrix-scalar.factor @@ -0,0 +1,23 @@ +USING: kernel locals math math.matrices math.order math.vectors +prettyprint sequences ; +IN: benchmark.3d-matrix-scalar + +:: p-matrix ( dim fov near far -- matrix ) + dim dup first2 min v/n fov v*n near v*n + near far frustum-matrix4 ; + +:: mv-matrix ( pitch yaw location -- matrix ) + { 1.0 0.0 0.0 } pitch rotation-matrix4 + { 0.0 1.0 0.0 } yaw rotation-matrix4 + location vneg translation-matrix4 m. m. ; + +:: 3d-matrix ( -- ) + f :> result! + 100000 [ + { 1024.0 768.0 } 0.7 0.25 1024.0 p-matrix :> p + 3.0 1.0 { 10.0 -0.0 2.0 } mv-matrix :> mv + mv p m. result! + ] times + result . ; + +MAIN: 3d-matrix diff --git a/extra/benchmark/3d-matrix-vector/3d-matrix-vector.factor b/extra/benchmark/3d-matrix-vector/3d-matrix-vector.factor new file mode 100644 index 0000000000..1b57bb902f --- /dev/null +++ b/extra/benchmark/3d-matrix-vector/3d-matrix-vector.factor @@ -0,0 +1,28 @@ +USING: kernel locals math math.matrices.simd math.order math.vectors +math.vectors.simd prettyprint sequences typed ; +QUALIFIED-WITH: alien.c-types c +SIMD: c:float +IN: benchmark.3d-matrix-vector + +: v2min ( xy -- xx ) + dup { 1 0 2 3 } vshuffle vmin ; inline + +TYPED:: p-matrix ( dim: float-4 fov: float near: float far: float -- matrix: matrix4 ) + dim dup v2min v/ fov v*n near v*n + near far frustum-matrix4 ; + +TYPED:: mv-matrix ( pitch: float yaw: float location: float-4 -- matrix: matrix4 ) + float-4{ 1.0 0.0 0.0 0.0 } pitch rotation-matrix4 + float-4{ 0.0 1.0 0.0 0.0 } yaw rotation-matrix4 + location vneg translation-matrix4 m4. m4. ; + +:: 3d-matrix ( -- ) + f :> result! + 100000 [ + float-4{ 1024.0 768.0 0.0 0.0 } 0.7 0.25 1024.0 p-matrix :> p + 3.0 1.0 float-4{ 10.0 -0.0 2.0 0.0 } mv-matrix :> mv + mv p m4. result! + ] times + result . ; + +MAIN: 3d-matrix From a2771aa1669604a1537e67b51ad364c8a6e011c7 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 30 Sep 2009 12:58:32 -0500 Subject: [PATCH 3/4] pit math.matrices and math.matrices.simd against each other in calculating matrix exponentials --- .../matrix-exponential-scalar.factor | 24 +++++++++++++++++++ .../matrix-exponential-simd.factor | 18 ++++++++++++++ extra/math/matrices/simd/simd.factor | 15 +++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 extra/benchmark/matrix-exponential-scalar/matrix-exponential-scalar.factor create mode 100644 extra/benchmark/matrix-exponential-simd/matrix-exponential-simd.factor diff --git a/extra/benchmark/matrix-exponential-scalar/matrix-exponential-scalar.factor b/extra/benchmark/matrix-exponential-scalar/matrix-exponential-scalar.factor new file mode 100644 index 0000000000..de4bf1ffe7 --- /dev/null +++ b/extra/benchmark/matrix-exponential-scalar/matrix-exponential-scalar.factor @@ -0,0 +1,24 @@ +USING: locals math math.combinatorics math.matrices +prettyprint sequences typed ; +IN: benchmark.matrix-exponential-scalar + +:: e^m ( m iterations -- e^m ) + { + { 0.0 0.0 0.0 0.0 } + { 0.0 0.0 0.0 0.0 } + { 0.0 0.0 0.0 0.0 } + { 0.0 0.0 0.0 0.0 } + } + iterations iota [| i | + m i m^n i factorial >float m/n m+ + ] each ; + +:: matrix-e ( -- ) + f :> result! + 4 identity-matrix :> i4 + 10000 [ + i4 20 e^m result! + ] times + result . ; + +MAIN: matrix-e diff --git a/extra/benchmark/matrix-exponential-simd/matrix-exponential-simd.factor b/extra/benchmark/matrix-exponential-simd/matrix-exponential-simd.factor new file mode 100644 index 0000000000..a23b3f2843 --- /dev/null +++ b/extra/benchmark/matrix-exponential-simd/matrix-exponential-simd.factor @@ -0,0 +1,18 @@ +USING: locals math math.combinatorics math.matrices.simd +prettyprint sequences typed ; +IN: benchmark.matrix-exponential-simd + +TYPED:: e^m4 ( m: matrix4 iterations: fixnum -- e^m: matrix4 ) + zero-matrix4 + iterations iota [| i | + m i m4^n i factorial >float m4/n m4+ + ] each ; + +:: matrix-e ( -- ) + f :> result! + 10000 [ + identity-matrix4 20 e^m4 result! + ] times + result . ; + +MAIN: matrix-e diff --git a/extra/math/matrices/simd/simd.factor b/extra/math/matrices/simd/simd.factor index 014cd86265..0c4c3e1866 100644 --- a/extra/math/matrices/simd/simd.factor +++ b/extra/math/matrices/simd/simd.factor @@ -1,6 +1,6 @@ ! (c)Joe Groff bsd license USING: accessors classes.struct generalizations kernel locals -math math.functions math.matrices.simd math.vectors +math math.combinatorics math.functions math.matrices.simd math.vectors math.vectors.simd sequences sequences.private specialized-arrays typed ; QUALIFIED-WITH: alien.c-types c @@ -105,6 +105,19 @@ CONSTANT: identity-matrix4 } } +CONSTANT: zero-matrix4 + S{ matrix4 f + float-4-array{ + float-4{ 0.0 0.0 0.0 0.0 } + float-4{ 0.0 0.0 0.0 0.0 } + float-4{ 0.0 0.0 0.0 0.0 } + float-4{ 0.0 0.0 0.0 0.0 } + } + } + +TYPED:: m4^n ( m: matrix4 n: fixnum -- m^n: matrix4 ) + identity-matrix4 n [ m m4. ] times ; + TYPED:: scale-matrix4 ( factors: float-4 -- matrix: matrix4 ) matrix4 (struct) :> c From e0f3b72c65c485cd881427ecaa68c9c2498f788c Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 30 Sep 2009 13:21:25 -0500 Subject: [PATCH 4/4] break math.vectors docs into subsections --- basis/math/vectors/vectors-docs.factor | 72 ++++++++++++++------------ 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/basis/math/vectors/vectors-docs.factor b/basis/math/vectors/vectors-docs.factor index cd539a14e4..1d323822bd 100644 --- a/basis/math/vectors/vectors-docs.factor +++ b/basis/math/vectors/vectors-docs.factor @@ -1,10 +1,21 @@ USING: help.markup help.syntax math math.functions sequences ; IN: math.vectors -ARTICLE: "math-vectors" "Vector arithmetic" -"Any Factor sequence can be used to represent a mathematical vector, however for best performance, the sequences defined by the " { $vocab-link "specialized-arrays" } " and " { $vocab-link "math.vectors.simd" } " vocabularies should be used." -$nl -"Acting on vectors by a scalar:" +ARTICLE: "math-vectors-arithmetic" "Vector arithmetic" +"Vector/vector binary operations:" +{ $subsection v+ } +{ $subsection v- } +{ $subsection v+- } +{ $subsection v* } +{ $subsection v/ } +"Vector unary operations:" +{ $subsection vneg } +{ $subsection vabs } +{ $subsection vsqrt } +{ $subsection vfloor } +{ $subsection vceiling } +{ $subsection vtruncate } +"Vector/scalar and scalar/vector binary operations:" { $subsection vneg } { $subsection v*n } { $subsection n*v } @@ -14,24 +25,21 @@ $nl { $subsection n+v } { $subsection v-n } { $subsection n-v } -"Vector unary operations:" -{ $subsection vneg } -{ $subsection vabs } -{ $subsection vsqrt } -{ $subsection vfloor } -{ $subsection vceiling } -{ $subsection vtruncate } -"Vector/vector binary operations:" -{ $subsection v+ } -{ $subsection v- } -{ $subsection v+- } -{ $subsection v* } -{ $subsection v/ } "Saturated arithmetic (only on " { $link "specialized-arrays" } "):" { $subsection vs+ } { $subsection vs- } { $subsection vs* } -"Componentwise vector operations:" +"Inner product and norm:" +{ $subsection v. } +{ $subsection norm } +{ $subsection norm-sq } +{ $subsection normalize } +"Comparing entire vectors:" +{ $subsection distance } +{ $subsection v~ } ; + +ARTICLE: "math-vectors-logic" "Vector componentwise logic" +"Element comparisons:" { $subsection v< } { $subsection v<= } { $subsection v= } @@ -40,6 +48,8 @@ $nl { $subsection vunordered? } { $subsection vmax } { $subsection vmin } +{ $subsection vsupremum } +{ $subsection vinfimum } "Bitwise operations:" { $subsection vbitand } { $subsection vbitandn } @@ -47,31 +57,29 @@ $nl { $subsection vbitxor } { $subsection vlshift } { $subsection vrshift } -"Componentwise logical operations:" +"Element logical operations:" { $subsection vand } { $subsection vor } { $subsection vxor } { $subsection vmask } { $subsection v? } -"Shuffling:" -{ $subsection vshuffle } -"Inner product and norm:" -{ $subsection v. } -{ $subsection norm } -{ $subsection norm-sq } -{ $subsection normalize } -"Comparing entire vectors:" -{ $subsection distance } -{ $subsection v~ } -"Other functions:" -{ $subsection vsupremum } -{ $subsection vinfimum } +"Element shuffling:" +{ $subsection vshuffle } ; + +ARTICLE: "math-vectors-misc" "Miscellaneous vector functions" { $subsection trilerp } { $subsection bilerp } { $subsection vlerp } { $subsection vnlerp } { $subsection vbilerp } ; + +ARTICLE: "math-vectors" "Vector operations" +"Any Factor sequence can be used to represent a mathematical vector, however for best performance, the sequences defined by the " { $vocab-link "specialized-arrays" } " and " { $vocab-link "math.vectors.simd" } " vocabularies should be used." +{ $subsection "math-vectors-arithmetic" } +{ $subsection "math-vectors-logic" } +{ $subsection "math-vectors-misc" } ; + ABOUT: "math-vectors" HELP: vneg