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 ;
5 SPECIALIZED-ARRAY: float-4
8 : <point> ( n -- float-4 )
9 >float [ sin ] [ cos 3 * ] [ sin sq 2 / ] tri
10 0.0 float-4-boa ; inline
12 : make-points ( len -- points )
13 iota [ <point> ] float-4-array{ } map-as ; inline
15 : normalize-points ( points -- )
16 [ normalize ] change-each ; inline
18 : max-points ( points -- point )
19 [ ] [ vmax ] map-reduce ; inline
21 : print-point ( point -- )
22 [ number>string ] { } map-as ", " join print ; inline
24 : simd-benchmark ( len -- )
25 >fixnum make-points [ normalize-points ] [ max-points ] bi print-point ;
28 10 [ 500000 simd-benchmark ] times ;