]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/simd-1/simd-1.factor
Specialized array overhaul
[factor.git] / extra / benchmark / simd-1 / simd-1.factor
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
6 IN: benchmark.simd-1
7
8 : <point> ( n -- float-4 )
9     >float [ sin ] [ cos 3 * ] [ sin sq 2 / ] tri
10     0.0 float-4-boa ; inline
11
12 : make-points ( len -- points )
13     iota [ <point> ] float-4-array{ } map-as ; inline
14
15 : normalize-points ( points -- )
16     [ normalize ] change-each ; inline
17
18 : max-points ( points -- point )
19     [ ] [ vmax ] map-reduce ; inline
20
21 : print-point ( point -- )
22     [ number>string ] { } map-as ", " join print ; inline
23
24 : simd-benchmark ( len -- )
25     >fixnum make-points [ normalize-points ] [ max-points ] bi print-point ;
26
27 : main ( -- )
28     5000000 simd-benchmark ;
29
30 MAIN: main