1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel io math math.functions math.parser math.vectors
4 math.vectors.simd sequences specialized-arrays ;
6 SPECIALIZED-ARRAY: float-4
9 : <point> ( n -- float-4 )
10 >float [ sin ] [ cos 3 * ] [ sin sq 2 / ] tri
11 0.0 float-4-boa ; inline
13 : make-points ( len -- points )
14 iota [ <point> ] float-4-array{ } map-as ; inline
16 : normalize-points ( points -- )
17 [ normalize ] change-each ; inline
19 : max-points ( points -- point )
20 [ ] [ vmax ] map-reduce ; inline
22 : print-point ( point -- )
23 [ number>string ] { } map-as ", " join print ; inline
25 : simd-benchmark ( len -- )
26 >fixnum make-points [ normalize-points ] [ max-points ] bi print-point ;
29 10 [ 500000 simd-benchmark ] times ;