]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/benchmark/raytracer-simd/raytracer-simd.factor
factor: trim using lists
[factor.git] / extra / benchmark / raytracer-simd / raytracer-simd.factor
index 866891dd31a7b9d31c63c4dc046bbd5a4dfe6b9a..dd5bcfaae0d90f4fa05d3ecad63f571f23388ad7 100644 (file)
@@ -1,10 +1,10 @@
 ! Factor port of the raytracer benchmark from
 ! http://www.ffconsultancy.com/languages/ray_tracer/index.html
 
-USING: arrays accessors io io.files io.files.temp
+USING: arrays accessors generalizations io.files io.files.temp
 io.encodings.binary kernel math math.constants math.functions
-math.vectors math.vectors.simd math.vectors.simd.cords
-math.parser make sequences words combinators ;
+math.vectors math.vectors.simd.cords math.parser make sequences
+words combinators ;
 IN: benchmark.raytracer-simd
 
 << SYNTAX: no-compile last-word t "no-compile" set-word-prop ; >>
@@ -42,7 +42,7 @@ C: <sphere> sphere
 
 : sphere-v ( sphere ray -- v ) [ center>> ] [ orig>> ] bi* v- ; inline no-compile
 
-: sphere-b ( v ray -- b ) dir>> v. ; inline no-compile
+: sphere-b ( v ray -- b ) dir>> vdot ; inline no-compile
 
 : sphere-d ( sphere b v -- d ) [ radius>> sq ] [ sq ] [ norm-sq ] tri* - + ; inline no-compile
 
@@ -98,7 +98,7 @@ CONSTANT: initial-hit T{ hit f double-4{ 0.0 0.0 0.0 0.0 } 1/0. }
 : sray-intersect ( ray scene hit -- ray )
     swap [ ray-o light vneg <ray> ] dip initial-intersect ; inline no-compile
 
-: ray-g ( hit -- g ) normal>> light v. ; inline no-compile
+: ray-g ( hit -- g ) normal>> light vdot ; inline no-compile
 
 : cast-ray ( ray scene -- g )
     2dup initial-intersect dup lambda>> 1/0. = [
@@ -129,7 +129,7 @@ CONSTANT: create-offsets
 : create-group ( level c r -- scene )
     2dup create-bound [
         2dup <sphere> ,
-        create-offsets [ create-step , ] with with with each
+        create-offsets [ create-step , ] 3 nwith each
     ] make-group ;
 
 : create ( level c r -- scene )
@@ -140,20 +140,20 @@ CONSTANT: create-offsets
 
 : ray-pixel ( scene point -- ray-grid )
     [ 0.0 ] 2dip
-    oversampling iota [
-        oversampling iota [
+    oversampling <iota> [
+        oversampling <iota> [
             ss-point v+ normalize
             double-4{ 0.0 0.0 -4.0 0.0 } swap <ray>
             swap cast-ray +
-        ] with with with each
-    ] with with each ; inline no-compile
+        ] 3 nwith each
+    ] 2with each ; inline no-compile
 
 : ray-trace ( scene -- grid )
-    size iota <reversed> [
-        size iota [
+    size <iota> <reversed> [
+        size <iota> [
             [ size 0.5 * - ] bi@ swap size
             0.0 double-4-boa ray-pixel
-        ] with with map
+        ] 2with map
     ] with map ;
 
 : pgm-header ( w h -- )
@@ -161,13 +161,13 @@ CONSTANT: create-offsets
 
 : pgm-pixel ( n -- ) 255 * 0.5 + >fixnum , ;
 
-: run ( -- string )
+: run-raytracer-simd ( -- string )
     levels double-4{ 0.0 -1.0 0.0 0.0 } 1.0 create ray-trace [
         size size pgm-header
         [ [ oversampling sq / pgm-pixel ] each ] each
     ] B{ } make ;
 
 : raytracer-simd-benchmark ( -- )
-    run "raytracer.pnm" temp-file binary set-file-contents ;
+    run-raytracer-simd "raytracer.pnm" temp-file binary set-file-contents ;
 
 MAIN: raytracer-simd-benchmark