]> gitweb.factorcode.org Git - factor.git/blob - basis/math/vectors/simd/alien/alien-tests.factor
52b8db9bd1d9f0be38e97229f23e7e8b08925a48
[factor.git] / basis / math / vectors / simd / alien / alien-tests.factor
1 IN: math.vectors.simd.alien.tests
2 USING: cpu.architecture math.vectors.simd
3 math.vectors.simd.intrinsics accessors math.vectors.simd.alien
4 kernel classes.struct tools.test compiler sequences byte-arrays
5 alien math kernel.private specialized-arrays.float combinators ;
6
7 ! Vector alien intrinsics
8 [ float-4{ 1 2 3 4 } ] [
9     [
10         float-4{ 1 2 3 4 }
11         underlying>> 0 float-4-rep alien-vector
12     ] compile-call float-4 boa
13 ] unit-test
14
15 [ B{ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 } ] [
16     16 [ 1 ] B{ } replicate-as 16 <byte-array>
17     [
18         0 [
19             { byte-array c-ptr fixnum } declare
20             float-4-rep set-alien-vector
21         ] compile-call
22     ] keep
23 ] unit-test
24
25 [ float-array{ 1 2 3 4 } ] [
26     [
27         float-array{ 1 2 3 4 } underlying>>
28         float-array{ 4 3 2 1 } clone
29         [ underlying>> 0 float-4-rep set-alien-vector ] keep
30     ] compile-call
31 ] unit-test
32
33 STRUCT: simd-struct
34 { x float-4 }
35 { y double-2 }
36 { z double-4 }
37 { w float-8 } ;
38
39 [ t ] [ [ simd-struct <struct> ] compile-call >c-ptr [ 0 = ] all? ] unit-test
40
41 [
42     float-4{ 1 2 3 4 }
43     double-2{ 2 1 }
44     double-4{ 4 3 2 1 }
45     float-8{ 1 2 3 4 5 6 7 8 }
46 ] [
47     simd-struct <struct>
48     float-4{ 1 2 3 4 } >>x
49     double-2{ 2 1 } >>y
50     double-4{ 4 3 2 1 } >>z
51     float-8{ 1 2 3 4 5 6 7 8 } >>w
52     { [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
53 ] unit-test
54
55 [
56     float-4{ 1 2 3 4 }
57     double-2{ 2 1 }
58     double-4{ 4 3 2 1 }
59     float-8{ 1 2 3 4 5 6 7 8 }
60 ] [
61     [
62         simd-struct <struct>
63         float-4{ 1 2 3 4 } >>x
64         double-2{ 2 1 } >>y
65         double-4{ 4 3 2 1 } >>z
66         float-8{ 1 2 3 4 5 6 7 8 } >>w
67         { [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
68     ] compile-call
69 ] unit-test