1 USING: accessors arrays classes compiler.test compiler.tree.debugger
2 effects fry io kernel kernel.private math math.functions
3 math.private math.vectors math.vectors.simd math.ranges
4 math.vectors.simd.private prettyprint random sequences system
5 tools.test vocabs assocs compiler.cfg.debugger words
6 locals combinators cpu.architecture namespaces byte-arrays alien
7 specialized-arrays classes.struct eval classes.algebra sets
8 quotations math.constants compiler.units splitting math.matrices
9 math.vectors.simd.cords alien.data ;
10 FROM: math.vectors.simd.intrinsics => alien-vector set-alien-vector ;
11 QUALIFIED-WITH: alien.c-types c
12 SPECIALIZED-ARRAY: c:float
13 IN: math.vectors.simd.tests
15 ! Test type propagation
16 [ V{ float } ] [ [ { float-4 } declare norm-sq ] final-classes ] unit-test
18 [ V{ float } ] [ [ { float-4 } declare norm ] final-classes ] unit-test
20 [ V{ float-4 } ] [ [ { float-4 } declare normalize ] final-classes ] unit-test
22 [ V{ float-4 } ] [ [ { float-4 float-4 } declare v+ ] final-classes ] unit-test
24 [ V{ float } ] [ [ { float-4 } declare second ] final-classes ] unit-test
26 [ V{ int-4 } ] [ [ { int-4 int-4 } declare v+ ] final-classes ] unit-test
28 [ t ] [ [ { int-4 } declare second ] final-classes first integer class<= ] unit-test
30 [ V{ longlong-2 } ] [ [ { longlong-2 longlong-2 } declare v+ ] final-classes ] unit-test
32 [ V{ integer } ] [ [ { longlong-2 } declare second ] final-classes ] unit-test
34 ! Test puns; only on x86
36 [ double-2{ 4 1024 } ] [
38 [ { float-4 } declare dup v+ underlying>> double-2 boa dup v+ ] compile-call
43 CONSTANT: simd-classes
57 SYMBOLS: -> +vector+ +any-vector+ +scalar+ +boolean+ +nonnegative+ +literal+ ;
59 CONSTANT: vector-words
61 { [v-] { +vector+ +vector+ -> +vector+ } }
62 { distance { +vector+ +vector+ -> +nonnegative+ } }
63 { n*v { +scalar+ +vector+ -> +vector+ } }
64 { n+v { +scalar+ +vector+ -> +vector+ } }
65 { n-v { +scalar+ +vector+ -> +vector+ } }
66 { n/v { +scalar+ +vector+ -> +vector+ } }
67 { norm { +vector+ -> +nonnegative+ } }
68 { norm-sq { +vector+ -> +nonnegative+ } }
69 { normalize { +vector+ -> +vector+ } }
70 { v* { +vector+ +vector+ -> +vector+ } }
71 { vs* { +vector+ +vector+ -> +vector+ } }
72 { v*n { +vector+ +scalar+ -> +vector+ } }
73 { v*high { +vector+ +vector+ -> +vector+ } }
74 { v*hs+ { +vector+ +vector+ -> +vector+ } }
75 { v+ { +vector+ +vector+ -> +vector+ } }
76 { vs+ { +vector+ +vector+ -> +vector+ } }
77 { v+- { +vector+ +vector+ -> +vector+ } }
78 { v+n { +vector+ +scalar+ -> +vector+ } }
79 { v- { +vector+ +vector+ -> +vector+ } }
80 { vneg { +vector+ -> +vector+ } }
81 { vs- { +vector+ +vector+ -> +vector+ } }
82 { v-n { +vector+ +scalar+ -> +vector+ } }
83 { v. { +vector+ +vector+ -> +scalar+ } }
84 { vsad { +vector+ +vector+ -> +scalar+ } }
85 { v/ { +vector+ +vector+ -> +vector+ } }
86 { v/n { +vector+ +scalar+ -> +vector+ } }
87 { vceiling { +vector+ -> +vector+ } }
88 { vfloor { +vector+ -> +vector+ } }
89 { vmax { +vector+ +vector+ -> +vector+ } }
90 { vmin { +vector+ +vector+ -> +vector+ } }
91 { vavg { +vector+ +vector+ -> +vector+ } }
92 { vneg { +vector+ -> +vector+ } }
93 { vtruncate { +vector+ -> +vector+ } }
94 { sum { +vector+ -> +scalar+ } }
95 { vabs { +vector+ -> +vector+ } }
96 { vsqrt { +vector+ -> +vector+ } }
97 { vbitand { +vector+ +vector+ -> +vector+ } }
98 { vbitandn { +vector+ +vector+ -> +vector+ } }
99 { vbitor { +vector+ +vector+ -> +vector+ } }
100 { vbitxor { +vector+ +vector+ -> +vector+ } }
101 { vbitnot { +vector+ -> +vector+ } }
102 { vand { +vector+ +vector+ -> +vector+ } }
103 { vandn { +vector+ +vector+ -> +vector+ } }
104 { vor { +vector+ +vector+ -> +vector+ } }
105 { vxor { +vector+ +vector+ -> +vector+ } }
106 { vnot { +vector+ -> +vector+ } }
107 { vlshift { +vector+ +scalar+ -> +vector+ } }
108 { vrshift { +vector+ +scalar+ -> +vector+ } }
109 { (vmerge-head) { +vector+ +vector+ -> +vector+ } }
110 { (vmerge-tail) { +vector+ +vector+ -> +vector+ } }
111 { v<= { +vector+ +vector+ -> +vector+ } }
112 { v< { +vector+ +vector+ -> +vector+ } }
113 { v= { +vector+ +vector+ -> +vector+ } }
114 { v> { +vector+ +vector+ -> +vector+ } }
115 { v>= { +vector+ +vector+ -> +vector+ } }
116 { vunordered? { +vector+ +vector+ -> +vector+ } }
119 : vector-word-inputs ( schema -- seq ) { -> } split first ;
121 : with-ctors ( -- seq )
122 simd-classes [ [ name>> "-with" append ] [ vocabulary>> ] bi lookup-word ] map ;
124 : boa-ctors ( -- seq )
125 simd-classes [ [ name>> "-boa" append ] [ vocabulary>> ] bi lookup-word ] map ;
127 : check-optimizer ( seq test-quot eq-quot -- failures )
128 #! Use test-quot to generate a bunch of test cases from the
129 #! given inputs. Run each test case optimized and
130 #! unoptimized. Compare results with eq-quot.
132 #! seq: sequence of inputs
133 #! test-quot: ( input -- input-quot: ( -- values ) code-quot: ( values -- result ) )
134 #! eq-quot: ( result1 result2 -- ? )
137 [ dup [ class-of ] { } map-as ] dip '[ _ declare @ ]
139 [ "print-mr" get [ nip regs. ] [ 2drop ] if ]
140 [ "print-checks" get [ [ . ] bi@ ] [ 2drop ] if ]
141 [ [ [ call ] dip call ] call( quot quot -- result ) ]
142 [ [ [ call ] dip compile-call ] call( quot quot -- result ) ]
143 [ [ t "always-inline-simd-intrinsics" [ [ call ] dip compile-call ] with-variable ] call( quot quot -- result ) ]
145 [ drop @ ] [ nip @ ] 3bi and not
148 "== Checking -new constructors" print
151 simd-classes [ [ [ ] ] dip '[ _ new ] ] [ = ] check-optimizer
155 simd-classes [ '[ _ new ] compile-call [ zero? ] all? not ] filter
158 "== Checking -with constructors" print
162 [ 1000 random '[ _ ] ] dip '[ _ execute ]
163 ] [ = ] check-optimizer
166 [ HEX: ffffffff ] [ HEX: ffffffff uint-4-with first ] unit-test
168 [ HEX: ffffffff ] [ HEX: ffffffff [ uint-4-with ] compile-call first ] unit-test
170 [ HEX: ffffffff ] [ [ HEX: ffffffff uint-4-with ] compile-call first ] unit-test
172 "== Checking -boa constructors" print
176 [ stack-effect in>> length [ 1000 random ] [ ] replicate-as ] keep
178 ] [ = ] check-optimizer
181 [ HEX: ffffffff ] [ HEX: ffffffff 2 3 4 [ uint-4-boa ] compile-call first ] unit-test
183 "== Checking vector operations" print
185 : random-int-vector ( class -- vec )
186 new [ drop 1000 random ] map ;
188 : random-float-vector ( class -- vec )
192 10 swap <array> 0/0. suffix random
195 : random-vector ( class elt-class -- vec )
197 [ random-float-vector ]
198 [ random-int-vector ] if ;
200 :: check-vector-op ( word inputs class elt-class -- inputs quot )
203 { +vector+ [ class elt-class random-vector ] }
204 { +scalar+ [ 1000 random elt-class float = [ >float ] when ] }
207 word '[ _ execute ] ;
209 : remove-float-words ( alist -- alist' )
210 { vsqrt n/v v/n v/ normalize } unique assoc-diff ;
212 : remove-integer-words ( alist -- alist' )
213 { vlshift vrshift v*high v*hs+ } unique assoc-diff ;
215 : boolean-ops ( -- words )
216 { vand vandn vor vxor vnot } ;
218 : remove-boolean-words ( alist -- alist' )
219 boolean-ops unique assoc-diff ;
221 : ops-to-check ( elt-class -- alist )
222 [ vector-words >alist ] dip
223 float = [ remove-integer-words ] [ remove-float-words ] if
224 remove-boolean-words ;
226 : check-vector-ops ( class elt-class compare-quot -- )
228 [ nip ops-to-check ] 2keep
229 '[ first2 vector-word-inputs _ _ check-vector-op ]
230 ] dip check-optimizer ; inline
232 : (approx=) ( x y -- ? )
234 { [ 2dup [ fp-nan? ] both? ] [ 2drop t ] }
235 { [ 2dup [ fp-nan? ] either? ] [ 2drop f ] }
236 { [ 2dup [ fp-infinity? ] either? ] [ fp-bitwise= ] }
237 { [ 2dup [ float? ] both? ] [ -1.e8 ~ ] }
240 : approx= ( x y -- ? )
241 2dup [ sequence? ] both?
242 [ [ (approx=) ] 2all? ] [ (approx=) ] if ;
244 : exact= ( x y -- ? )
246 { [ 2dup [ float? ] both? ] [ fp-bitwise= ] }
247 { [ 2dup [ sequence? ] both? ] [ [ fp-bitwise= ] 2all? ] }
250 : simd-classes&reps ( -- alist )
253 { [ dup name>> "float" head? ] [ float [ approx= ] ] }
254 { [ dup name>> "double" head? ] [ float [ exact= ] ] }
260 [ [ { } ] ] dip first3 '[ _ _ _ check-vector-ops ] unit-test
263 "== Checking boolean operations" print
265 : random-boolean-vector ( class -- vec )
266 new [ drop 2 random zero? ] map ;
268 :: check-boolean-op ( word inputs class elt-class -- inputs quot )
271 { +vector+ [ class random-boolean-vector ] }
272 { +scalar+ [ 1000 random elt-class float = [ >float ] when ] }
275 word '[ _ execute ] ;
277 : check-boolean-ops ( class elt-class compare-quot -- seq )
279 [ boolean-ops [ dup vector-words at ] { } map>assoc ] 2dip
280 '[ first2 vector-word-inputs _ _ check-boolean-op ]
281 ] dip check-optimizer ; inline
284 [ [ { } ] ] dip first3 '[ _ _ _ check-boolean-ops ] unit-test
287 "== Checking vector blend" print
289 [ char-16{ 0 1 22 33 4 5 6 77 8 99 110 121 12 143 14 15 } ]
291 char-16{ t t f f t t t f t f f f t f t t }
292 char-16{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 }
293 char-16{ 0 11 22 33 44 55 66 77 88 99 110 121 132 143 154 165 } v?
296 [ char-16{ 0 1 22 33 4 5 6 77 8 99 110 121 12 143 14 15 } ]
298 char-16{ t t f f t t t f t f f f t f t t }
299 char-16{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 }
300 char-16{ 0 11 22 33 44 55 66 77 88 99 110 121 132 143 154 165 }
301 [ { char-16 char-16 char-16 } declare v? ] compile-call
304 [ int-4{ 1 22 33 4 } ]
305 [ int-4{ t f f t } int-4{ 1 2 3 4 } int-4{ 11 22 33 44 } v? ] unit-test
307 [ int-4{ 1 22 33 4 } ]
309 int-4{ t f f t } int-4{ 1 2 3 4 } int-4{ 11 22 33 44 }
310 [ { int-4 int-4 int-4 } declare v? ] compile-call
313 [ float-4{ 1.0 22.0 33.0 4.0 } ]
314 [ float-4{ t f f t } float-4{ 1.0 2.0 3.0 4.0 } float-4{ 11.0 22.0 33.0 44.0 } v? ] unit-test
316 [ float-4{ 1.0 22.0 33.0 4.0 } ]
318 float-4{ t f f t } float-4{ 1.0 2.0 3.0 4.0 } float-4{ 11.0 22.0 33.0 44.0 }
319 [ { float-4 float-4 float-4 } declare v? ] compile-call
322 "== Checking shifts and permutations" print
324 [ char-16{ 0 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 } ]
325 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } 1 hlshift ] unit-test
327 [ char-16{ 0 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 } ]
328 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } [ { char-16 } declare 1 hlshift ] compile-call ] unit-test
330 [ char-16{ 0 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 } ]
331 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } [ { char-16 } declare 1 >bignum hlshift ] compile-call ] unit-test
333 [ char-16{ 0 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 } ]
334 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } 1 [ { char-16 fixnum } declare hlshift ] compile-call ] unit-test
336 [ char-16{ 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 0 } ]
337 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } 1 hrshift ] unit-test
339 [ char-16{ 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 0 } ]
340 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } [ { char-16 } declare 1 hrshift ] compile-call ] unit-test
342 [ char-16{ 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 0 } ]
343 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } [ { char-16 } declare 1 >bignum hrshift ] compile-call ] unit-test
345 [ char-16{ 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 0 } ]
346 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } 1 [ { char-16 fixnum } declare hrshift ] compile-call ] unit-test
348 [ int-4{ 4 8 12 16 } ]
349 [ int-4{ 1 2 3 4 } 2 vlshift ] unit-test
351 [ int-4{ 4 8 12 16 } ]
352 [ int-4{ 1 2 3 4 } 2 [ { int-4 fixnum } declare vlshift ] compile-call ] unit-test
354 [ int-4{ 4 8 12 16 } ]
355 [ int-4{ 1 2 3 4 } 2 >bignum [ { int-4 bignum } declare vlshift ] compile-call ] unit-test
357 ! Invalid inputs should not cause the compiler to throw errors
359 [ [ { int-4 } declare t hrshift ] ( a -- b ) define-temp drop ] with-compilation-unit
363 [ [ { int-4 } declare { 3 2 1 } vshuffle ] ( a -- b ) define-temp drop ] with-compilation-unit
367 : shuffles-for ( n -- shuffles )
398 [ dup '[ _ random ] replicate 1array ]
401 : 2shuffles-for ( n -- shuffles )
430 [ dup 2 * '[ _ random ] replicate 1array ]
435 [ new length shuffles-for ] keep
437 _ [ [ _ new [ length iota ] keep like 1quotation ] dip '[ _ vshuffle ] ]
438 [ = ] check-optimizer
444 [ new length 2shuffles-for ] keep
448 [ [ length iota ] keep like ]
449 [ [ length dup dup + [a,b) ] keep like ] bi [ ] 2sequence
450 ] dip '[ _ vshuffle2-elements ] ]
451 [ = ] check-optimizer
455 "== Checking variable shuffles" print
457 : random-shift-vector ( class -- vec )
458 new [ drop 16 random ] map ;
460 :: test-shift-vector ( class -- ? )
462 class random-int-vector :> src
463 char-16 random-shift-vector :> perm
464 { class char-16 } :> decl
467 src perm [ decl declare vshuffle ] compile-call
471 { char-16 uchar-16 short-8 ushort-8 int-4 uint-4 longlong-2 ulonglong-2 }
472 [ 10 swap '[ [ t ] [ _ test-shift-vector ] unit-test ] times ] each
474 "== Checking vector tests" print
476 :: test-vector-tests-bool ( vector declaration -- none? any? all? )
479 [ [ declaration declare vnone? ] compile-call ]
480 [ [ declaration declare vany? ] compile-call ]
481 [ [ declaration declare vall? ] compile-call ] tri
482 ] call( -- none? any? all? ) ;
487 :: test-vector-tests-branch ( vector declaration -- none? any? all? )
490 [ [ declaration declare vnone? [ yes ] [ no ] if ] compile-call ]
491 [ [ declaration declare vany? [ yes ] [ no ] if ] compile-call ]
492 [ [ declaration declare vall? [ yes ] [ no ] if ] compile-call ] tri
493 ] call( -- none? any? all? ) ;
495 TUPLE: inconsistent-vector-test bool branch ;
497 : ?inconsistent ( bool branch -- ?/inconsistent )
498 2dup = [ drop ] [ inconsistent-vector-test boa ] if ;
500 :: test-vector-tests ( vector decl -- none? any? all? )
502 vector decl test-vector-tests-bool :> ( bool-none bool-any bool-all )
503 vector decl test-vector-tests-branch :> ( branch-none branch-any branch-all )
505 bool-none branch-none ?inconsistent
506 bool-any branch-any ?inconsistent
507 bool-all branch-all ?inconsistent
508 ] call( -- none? any? all? ) ;
511 [ float-4{ t t t t } { float-4 } test-vector-tests ] unit-test
513 [ float-4{ f t t t } { float-4 } test-vector-tests ] unit-test
515 [ float-4{ f f f f } { float-4 } test-vector-tests ] unit-test
518 [ double-2{ t t } { double-2 } test-vector-tests ] unit-test
520 [ double-2{ f t } { double-2 } test-vector-tests ] unit-test
522 [ double-2{ f f } { double-2 } test-vector-tests ] unit-test
525 [ int-4{ t t t t } { int-4 } test-vector-tests ] unit-test
527 [ int-4{ f t t t } { int-4 } test-vector-tests ] unit-test
529 [ int-4{ f f f f } { int-4 } test-vector-tests ] unit-test
531 "== Checking element access" print
533 ! Test element access -- it should box bignums for int-4 on x86
534 : test-accesses ( seq -- failures )
535 [ length iota dup [ >bignum ] map append ] keep
536 '[ [ _ 1quotation ] dip '[ _ swap nth ] ] [ = ] check-optimizer ; inline
538 [ { } ] [ float-4{ 1.0 2.0 3.0 4.0 } test-accesses ] unit-test
539 [ { } ] [ int-4{ HEX: 7fffffff 3 4 -8 } test-accesses ] unit-test
540 [ { } ] [ uint-4{ HEX: ffffffff 2 3 4 } test-accesses ] unit-test
542 [ HEX: 7fffffff ] [ int-4{ HEX: 7fffffff 3 4 -8 } first ] unit-test
543 [ -8 ] [ int-4{ HEX: 7fffffff 3 4 -8 } last ] unit-test
544 [ HEX: ffffffff ] [ uint-4{ HEX: ffffffff 2 3 4 } first ] unit-test
546 [ { } ] [ double-2{ 1.0 2.0 } test-accesses ] unit-test
547 [ { } ] [ longlong-2{ 1 2 } test-accesses ] unit-test
548 [ { } ] [ ulonglong-2{ 1 2 } test-accesses ] unit-test
550 "== Checking broadcast" print
551 : test-broadcast ( seq -- failures )
552 [ length iota >array ] keep
553 '[ [ _ 1quotation ] dip '[ _ vbroadcast ] ] [ = ] check-optimizer ;
555 [ { } ] [ float-4{ 1.0 2.0 3.0 4.0 } test-broadcast ] unit-test
556 [ { } ] [ int-4{ HEX: 7fffffff 3 4 -8 } test-broadcast ] unit-test
557 [ { } ] [ uint-4{ HEX: ffffffff 2 3 4 } test-broadcast ] unit-test
559 [ { } ] [ double-2{ 1.0 2.0 } test-broadcast ] unit-test
560 [ { } ] [ longlong-2{ 1 2 } test-broadcast ] unit-test
561 [ { } ] [ ulonglong-2{ 1 2 } test-broadcast ] unit-test
563 ! Make sure we use the fallback in the correct situations
564 [ int-4{ 3 3 3 3 } ] [ int-4{ 12 34 3 17 } 2 [ { int-4 fixnum } declare vbroadcast ] compile-call ] unit-test
566 "== Checking alien operations" print
568 [ float-4{ 1 2 3 4 } ] [
571 underlying>> 0 float-4-rep alien-vector
572 ] compile-call float-4 boa
575 [ B{ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 } ] [
576 16 [ 1 ] B{ } replicate-as 16 <byte-array>
579 { byte-array c-ptr fixnum } declare
580 float-4-rep set-alien-vector
585 [ float-array{ 1 2 3 4 } ] [
587 float-array{ 1 2 3 4 } underlying>>
588 float-array{ 4 3 2 1 } clone
589 [ underlying>> 0 float-4-rep set-alien-vector ] keep
599 [ t ] [ [ simd-struct <struct> ] compile-call >c-ptr [ 0 = ] all? ] unit-test
608 float-4{ 1 2 3 4 } >>x
609 longlong-2{ 2 1 } >>y
612 { [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
623 float-4{ 1 2 3 4 } >>x
624 longlong-2{ 2 1 } >>y
627 { [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
631 "== Misc tests" print
633 [ ] [ char-16 new 1array stack. ] unit-test
635 ! Test some sequence protocol stuff
636 [ t ] [ 4 double-4{ 1 2 3 4 } new-sequence double-4? ] unit-test
637 [ double-4{ 2 3 4 5 } ] [ double-4{ 1 2 3 4 } [ 1 + ] map ] unit-test
640 [ float-4{ 0.0 0.0 1.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 1.0 0.0 0.0 } cross ] unit-test
641 [ float-4{ 0.0 0.0 1.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 1.0 0.0 0.0 } [ { float-4 float-4 } declare cross ] compile-call ] unit-test
642 [ float-4{ 0.0 -1.0 0.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 0.0 1.0 0.0 } cross ] unit-test
643 [ float-4{ 0.0 -1.0 0.0 0.0 } ] [ float-4{ 1.0 0.0 0.0 0.0 } float-4{ 0.0 0.0 1.0 0.0 } [ { float-4 float-4 } declare cross ] compile-call ] unit-test
645 [ double-4{ 0.0 0.0 1.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 1.0 0.0 0.0 } cross ] unit-test
646 [ double-4{ 0.0 0.0 1.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 1.0 0.0 0.0 } [ { double-4 double-4 } declare cross ] compile-call ] unit-test
647 [ double-4{ 0.0 -1.0 0.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 0.0 1.0 0.0 } cross ] unit-test
648 [ double-4{ 0.0 -1.0 0.0 0.0 } ] [ double-4{ 1.0 0.0 0.0 0.0 } double-4{ 0.0 0.0 1.0 0.0 } [ { double-4 double-4 } declare cross ] compile-call ] unit-test
652 int-4{ 1000 1000 1000 1000 }
653 [ { int-4 } declare dup [ * ] [ + ] 2map-reduce ] compile-call
656 ! Coalescing was too aggressive
657 :: broken ( axis theta -- a b c )
658 axis { float-4 } declare drop
659 theta { float } declare drop
661 theta cos float-4-with :> cc
662 theta sin float-4-with :> ss
664 axis cc v+ :> diagonal
666 diagonal cc ss ; inline
669 float-4{ 1.0 0.0 1.0 0.0 } pi [ broken 3array ]
670 [ compile-call ] [ call ] 3bi =
673 ! Spilling SIMD values -- this basically just tests that the
674 ! stack was aligned properly by the runtime
676 : simd-spill-test-1 ( a b c -- v )
677 { float-4 float-4 float } declare
680 [ float-4{ 0 0 0 0 } ]
681 [ float-4{ 1 2 3 4 } float-4{ 4 5 6 7 } 0.0 simd-spill-test-1 ] unit-test
683 : simd-spill-test-2 ( a b d c -- v )
684 { float float-4 float-4 float } declare
685 [ [ 3.0 + ] 2dip v+ ] dip sin v*n n*v ;
687 [ float-4{ 0 0 0 0 } ]
688 [ 5.0 float-4{ 1 2 3 4 } float-4{ 4 5 6 7 } 0.0 simd-spill-test-2 ] unit-test
692 : callback-1 ( -- c )
693 c:int { c:int c:int c:int c:int c:int } cdecl [ + + + + ] alien-callback ;
695 : indirect-1 ( x x x x x c -- y )
696 c:int { c:int c:int c:int c:int c:int } cdecl alien-indirect ; inline
698 : simd-spill-test-3 ( a b d c -- v )
699 { float float-4 float-4 float } declare
700 [ [ 3.0 + ] 2dip v+ ] dip sin v*n n*v
701 10 5 100 50 500 callback-1 indirect-1 665 assert= ;
703 [ float-4{ 0 0 0 0 } ]
704 [ 5.0 float-4{ 1 2 3 4 } float-4{ 4 5 6 7 } 0.0 simd-spill-test-3 ] unit-test
706 ! Stack allocation of SIMD values -- make sure that everything is
709 : simd-stack-test ( -- b c )
711 [ 123 swap 0 c:int c:set-alien-value ]
712 [ float-4{ 1 2 3 4 } swap 0 float-4 c:set-alien-value ] bi*
713 ] with-out-parameters ;
715 [ 123 float-4{ 1 2 3 4 } ] [ simd-stack-test ] unit-test
717 ! Stack allocation + spilling
719 : (simd-stack-spill-test) ( -- n ) 17 ;
721 : simd-stack-spill-test ( x -- b c )
723 123 swap 0 c:int c:set-alien-value
724 >float (simd-stack-spill-test) float-4-with swap cos v*n
725 ] with-out-parameters ;
728 1.047197551196598 simd-stack-spill-test
729 [ float-4{ 8.5 8.5 8.5 8.5 } approx= t assert= ]