]> gitweb.factorcode.org Git - factor.git/commitdiff
benchmarks for math.matrices and math.matrices.simd building and multiplying 3D matri...
authorJoe Groff <arcata@gmail.com>
Wed, 30 Sep 2009 16:51:44 +0000 (11:51 -0500)
committerJoe Groff <arcata@gmail.com>
Wed, 30 Sep 2009 16:51:44 +0000 (11:51 -0500)
extra/benchmark/3d-matrix-scalar/3d-matrix-scalar.factor [new file with mode: 0644]
extra/benchmark/3d-matrix-vector/3d-matrix-vector.factor [new file with mode: 0644]

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 (file)
index 0000000..d629eda
--- /dev/null
@@ -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 (file)
index 0000000..1b57bb9
--- /dev/null
@@ -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