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 ] map ;
124 : boa-ctors ( -- seq )
125 simd-classes [ [ name>> "-boa" append ] [ vocabulary>> ] bi lookup ] map ;
127 : check-optimizer ( seq quot eq-quot -- failures )
130 [ dup [ class ] { } map-as ] dip '[ _ declare @ ]
132 [ "print-mr" get [ nip regs. ] [ 2drop ] if ]
133 [ "print-checks" get [ [ . ] bi@ ] [ 2drop ] if ]
134 [ [ [ call ] dip call ] call( quot quot -- result ) ]
135 [ [ [ call ] dip compile-call ] call( quot quot -- result ) ]
136 [ [ t "always-inline-simd-intrinsics" [ [ call ] dip compile-call ] with-variable ] call( quot quot -- result ) ]
138 [ drop @ ] [ nip @ ] 3bi and not
141 "== Checking -new constructors" print
144 simd-classes [ [ [ ] ] dip '[ _ new ] ] [ = ] check-optimizer
148 simd-classes [ '[ _ new ] compile-call [ zero? ] all? not ] filter
151 "== Checking -with constructors" print
155 [ 1000 random '[ _ ] ] dip '[ _ execute ]
156 ] [ = ] check-optimizer
159 [ HEX: ffffffff ] [ HEX: ffffffff uint-4-with first ] unit-test
161 [ HEX: ffffffff ] [ HEX: ffffffff [ uint-4-with ] compile-call first ] unit-test
163 [ HEX: ffffffff ] [ [ HEX: ffffffff uint-4-with ] compile-call first ] unit-test
165 "== Checking -boa constructors" print
169 [ stack-effect in>> length [ 1000 random ] [ ] replicate-as ] keep
171 ] [ = ] check-optimizer
174 [ HEX: ffffffff ] [ HEX: ffffffff 2 3 4 [ uint-4-boa ] compile-call first ] unit-test
176 "== Checking vector operations" print
178 : random-int-vector ( class -- vec )
179 new [ drop 1000 random ] map ;
181 : random-float-vector ( class -- vec )
185 10 swap <array> 0/0. suffix random
188 : random-vector ( class elt-class -- vec )
190 [ random-float-vector ]
191 [ random-int-vector ] if ;
193 :: check-vector-op ( word inputs class elt-class -- inputs quot )
196 { +vector+ [ class elt-class random-vector ] }
197 { +scalar+ [ 1000 random elt-class float = [ >float ] when ] }
200 word '[ _ execute ] ;
202 : remove-float-words ( alist -- alist' )
203 { vsqrt n/v v/n v/ normalize } unique assoc-diff ;
205 : remove-integer-words ( alist -- alist' )
206 { vlshift vrshift v*high v*hs+ } unique assoc-diff ;
208 : boolean-ops ( -- words )
209 { vand vandn vor vxor vnot } ;
211 : remove-boolean-words ( alist -- alist' )
212 boolean-ops unique assoc-diff ;
214 : ops-to-check ( elt-class -- alist )
215 [ vector-words >alist ] dip
216 float = [ remove-integer-words ] [ remove-float-words ] if
217 remove-boolean-words ;
219 : check-vector-ops ( class elt-class compare-quot -- )
221 [ nip ops-to-check ] 2keep
222 '[ first2 vector-word-inputs _ _ check-vector-op ]
223 ] dip check-optimizer ; inline
225 : (approx=) ( x y -- ? )
227 { [ 2dup [ fp-nan? ] both? ] [ 2drop t ] }
228 { [ 2dup [ fp-nan? ] either? ] [ 2drop f ] }
229 { [ 2dup [ fp-infinity? ] either? ] [ fp-bitwise= ] }
230 { [ 2dup [ float? ] both? ] [ -1.e8 ~ ] }
233 : approx= ( x y -- ? )
234 2dup [ sequence? ] both?
235 [ [ (approx=) ] 2all? ] [ (approx=) ] if ;
237 : exact= ( x y -- ? )
239 { [ 2dup [ float? ] both? ] [ fp-bitwise= ] }
240 { [ 2dup [ sequence? ] both? ] [ [ fp-bitwise= ] 2all? ] }
243 : simd-classes&reps ( -- alist )
246 { [ dup name>> "float" head? ] [ float [ approx= ] ] }
247 { [ dup name>> "double" head? ] [ float [ exact= ] ] }
253 [ [ { } ] ] dip first3 '[ _ _ _ check-vector-ops ] unit-test
256 "== Checking boolean operations" print
258 : random-boolean-vector ( class -- vec )
259 new [ drop 2 random zero? ] map ;
261 :: check-boolean-op ( word inputs class elt-class -- inputs quot )
264 { +vector+ [ class random-boolean-vector ] }
265 { +scalar+ [ 1000 random elt-class float = [ >float ] when ] }
268 word '[ _ execute ] ;
270 : check-boolean-ops ( class elt-class compare-quot -- seq )
272 [ boolean-ops [ dup vector-words at ] { } map>assoc ] 2dip
273 '[ first2 vector-word-inputs _ _ check-boolean-op ]
274 ] dip check-optimizer ; inline
277 [ [ { } ] ] dip first3 '[ _ _ _ check-boolean-ops ] unit-test
280 "== Checking vector blend" print
282 [ char-16{ 0 1 22 33 4 5 6 77 8 99 110 121 12 143 14 15 } ]
284 char-16{ t t f f t t t f t f f f t f t t }
285 char-16{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 }
286 char-16{ 0 11 22 33 44 55 66 77 88 99 110 121 132 143 154 165 } v?
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 }
294 [ { char-16 char-16 char-16 } declare v? ] compile-call
297 [ int-4{ 1 22 33 4 } ]
298 [ int-4{ t f f t } int-4{ 1 2 3 4 } int-4{ 11 22 33 44 } v? ] unit-test
300 [ int-4{ 1 22 33 4 } ]
302 int-4{ t f f t } int-4{ 1 2 3 4 } int-4{ 11 22 33 44 }
303 [ { int-4 int-4 int-4 } declare v? ] compile-call
306 [ float-4{ 1.0 22.0 33.0 4.0 } ]
307 [ 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
309 [ float-4{ 1.0 22.0 33.0 4.0 } ]
311 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 }
312 [ { float-4 float-4 float-4 } declare v? ] compile-call
315 "== Checking shifts and permutations" print
317 [ char-16{ 0 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 } ]
318 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } 1 hlshift ] unit-test
320 [ char-16{ 0 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 } ]
321 [ 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
323 [ char-16{ 0 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 } ]
324 [ 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
326 [ char-16{ 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 0 } ]
327 [ char-16{ 1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 } 1 hrshift ] unit-test
329 [ char-16{ 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 0 } ]
330 [ 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
332 [ char-16{ 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8 0 } ]
333 [ 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
335 ! Invalid inputs should not cause the compiler to throw errors
337 [ [ { int-4 } declare t hrshift ] (( a -- b )) define-temp drop ] with-compilation-unit
341 [ [ { int-4 } declare { 3 2 1 } vshuffle ] (( a -- b )) define-temp drop ] with-compilation-unit
345 : shuffles-for ( n -- shuffles )
376 [ dup '[ _ random ] replicate 1array ]
379 : 2shuffles-for ( n -- shuffles )
408 [ dup 2 * '[ _ random ] replicate 1array ]
413 [ new length shuffles-for ] keep
415 _ [ [ _ new [ length iota ] keep like 1quotation ] dip '[ _ vshuffle ] ]
416 [ = ] check-optimizer
422 [ new length 2shuffles-for ] keep
426 [ [ length iota ] keep like ]
427 [ [ length dup dup + [a,b) ] keep like ] bi [ ] 2sequence
428 ] dip '[ _ vshuffle2-elements ] ]
429 [ = ] check-optimizer
433 "== Checking variable shuffles" print
435 : random-shift-vector ( class -- vec )
436 new [ drop 16 random ] map ;
438 :: test-shift-vector ( class -- ? )
440 class random-int-vector :> src
441 char-16 random-shift-vector :> perm
442 { class char-16 } :> decl
445 src perm [ decl declare vshuffle ] compile-call
449 { char-16 uchar-16 short-8 ushort-8 int-4 uint-4 longlong-2 ulonglong-2 }
450 [ 10 swap '[ [ t ] [ _ test-shift-vector ] unit-test ] times ] each
452 "== Checking vector tests" print
454 :: test-vector-tests-bool ( vector declaration -- none? any? all? )
457 [ [ declaration declare vnone? ] compile-call ]
458 [ [ declaration declare vany? ] compile-call ]
459 [ [ declaration declare vall? ] compile-call ] tri
460 ] call( -- none? any? all? ) ;
465 :: test-vector-tests-branch ( vector declaration -- none? any? all? )
468 [ [ declaration declare vnone? [ yes ] [ no ] if ] compile-call ]
469 [ [ declaration declare vany? [ yes ] [ no ] if ] compile-call ]
470 [ [ declaration declare vall? [ yes ] [ no ] if ] compile-call ] tri
471 ] call( -- none? any? all? ) ;
473 TUPLE: inconsistent-vector-test bool branch ;
475 : ?inconsistent ( bool branch -- ?/inconsistent )
476 2dup = [ drop ] [ inconsistent-vector-test boa ] if ;
478 :: test-vector-tests ( vector decl -- none? any? all? )
480 vector decl test-vector-tests-bool :> ( bool-none bool-any bool-all )
481 vector decl test-vector-tests-branch :> ( branch-none branch-any branch-all )
483 bool-none branch-none ?inconsistent
484 bool-any branch-any ?inconsistent
485 bool-all branch-all ?inconsistent
486 ] call( -- none? any? all? ) ;
489 [ float-4{ t t t t } { float-4 } test-vector-tests ] unit-test
491 [ float-4{ f t t t } { float-4 } test-vector-tests ] unit-test
493 [ float-4{ f f f f } { float-4 } test-vector-tests ] unit-test
496 [ double-2{ t t } { double-2 } test-vector-tests ] unit-test
498 [ double-2{ f t } { double-2 } test-vector-tests ] unit-test
500 [ double-2{ f f } { double-2 } test-vector-tests ] unit-test
503 [ int-4{ t t t t } { int-4 } test-vector-tests ] unit-test
505 [ int-4{ f t t t } { int-4 } test-vector-tests ] unit-test
507 [ int-4{ f f f f } { int-4 } test-vector-tests ] unit-test
509 "== Checking element access" print
511 ! Test element access -- it should box bignums for int-4 on x86
512 : test-accesses ( seq -- failures )
513 [ length iota >array ] keep
514 '[ [ _ 1quotation ] dip '[ _ swap nth ] ] [ = ] check-optimizer ; inline
516 [ { } ] [ float-4{ 1.0 2.0 3.0 4.0 } test-accesses ] unit-test
517 [ { } ] [ int-4{ HEX: 7fffffff 3 4 -8 } test-accesses ] unit-test
518 [ { } ] [ uint-4{ HEX: ffffffff 2 3 4 } test-accesses ] unit-test
520 [ HEX: 7fffffff ] [ int-4{ HEX: 7fffffff 3 4 -8 } first ] unit-test
521 [ -8 ] [ int-4{ HEX: 7fffffff 3 4 -8 } last ] unit-test
522 [ HEX: ffffffff ] [ uint-4{ HEX: ffffffff 2 3 4 } first ] unit-test
524 [ { } ] [ double-2{ 1.0 2.0 } test-accesses ] unit-test
525 [ { } ] [ longlong-2{ 1 2 } test-accesses ] unit-test
526 [ { } ] [ ulonglong-2{ 1 2 } test-accesses ] unit-test
528 "== Checking broadcast" print
529 : test-broadcast ( seq -- failures )
530 [ length iota >array ] keep
531 '[ [ _ 1quotation ] dip '[ _ vbroadcast ] ] [ = ] check-optimizer ;
533 [ { } ] [ float-4{ 1.0 2.0 3.0 4.0 } test-broadcast ] unit-test
534 [ { } ] [ int-4{ HEX: 7fffffff 3 4 -8 } test-broadcast ] unit-test
535 [ { } ] [ uint-4{ HEX: ffffffff 2 3 4 } test-broadcast ] unit-test
537 [ { } ] [ double-2{ 1.0 2.0 } test-broadcast ] unit-test
538 [ { } ] [ longlong-2{ 1 2 } test-broadcast ] unit-test
539 [ { } ] [ ulonglong-2{ 1 2 } test-broadcast ] unit-test
541 ! Make sure we use the fallback in the correct situations
542 [ int-4{ 3 3 3 3 } ] [ int-4{ 12 34 3 17 } 2 [ { int-4 fixnum } declare vbroadcast ] compile-call ] unit-test
544 "== Checking alien operations" print
546 [ float-4{ 1 2 3 4 } ] [
549 underlying>> 0 float-4-rep alien-vector
550 ] compile-call float-4 boa
553 [ B{ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 } ] [
554 16 [ 1 ] B{ } replicate-as 16 <byte-array>
557 { byte-array c-ptr fixnum } declare
558 float-4-rep set-alien-vector
563 [ float-array{ 1 2 3 4 } ] [
565 float-array{ 1 2 3 4 } underlying>>
566 float-array{ 4 3 2 1 } clone
567 [ underlying>> 0 float-4-rep set-alien-vector ] keep
577 [ t ] [ [ simd-struct <struct> ] compile-call >c-ptr [ 0 = ] all? ] unit-test
586 float-4{ 1 2 3 4 } >>x
587 longlong-2{ 2 1 } >>y
590 { [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
601 float-4{ 1 2 3 4 } >>x
602 longlong-2{ 2 1 } >>y
605 { [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
609 "== Misc tests" print
611 [ ] [ char-16 new 1array stack. ] unit-test
613 ! Test some sequence protocol stuff
614 [ t ] [ 4 double-4{ 1 2 3 4 } new-sequence double-4? ] unit-test
615 [ double-4{ 2 3 4 5 } ] [ double-4{ 1 2 3 4 } [ 1 + ] map ] unit-test
618 [ 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
619 [ 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
621 [ 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
622 [ 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
626 int-4{ 1000 1000 1000 1000 }
627 [ { int-4 } declare dup [ * ] [ + ] 2map-reduce ] compile-call
630 ! Coalescing was too aggressive
631 :: broken ( axis theta -- a b c )
632 axis { float-4 } declare drop
633 theta { float } declare drop
635 theta cos float-4-with :> cc
636 theta sin float-4-with :> ss
638 axis cc v+ :> diagonal
640 diagonal cc ss ; inline
643 float-4{ 1.0 0.0 1.0 0.0 } pi [ broken 3array ]
644 [ compile-call ] [ call ] 3bi =
647 ! Spilling SIMD values -- this basically just tests that the
648 ! stack was aligned properly by the runtime
650 : simd-spill-test-1 ( a b c -- v )
651 { float-4 float-4 float } declare
654 [ float-4{ 0 0 0 0 } ]
655 [ float-4{ 1 2 3 4 } float-4{ 4 5 6 7 } 0.0 simd-spill-test-1 ] unit-test
657 : simd-spill-test-2 ( a b d c -- v )
658 { float float-4 float-4 float } declare
659 [ [ 3.0 + ] 2dip v+ ] dip sin v*n n*v ;
661 [ float-4{ 0 0 0 0 } ]
662 [ 5.0 float-4{ 1 2 3 4 } float-4{ 4 5 6 7 } 0.0 simd-spill-test-2 ] unit-test
666 : callback-1 ( -- c )
667 c:int { c:int c:int c:int c:int c:int } cdecl [ + + + + ] alien-callback ;
669 : indirect-1 ( x x x x x c -- y )
670 c:int { c:int c:int c:int c:int c:int } cdecl alien-indirect ; inline
672 : simd-spill-test-3 ( a b d c -- v )
673 { float float-4 float-4 float } declare
674 [ [ 3.0 + ] 2dip v+ ] dip sin v*n n*v
675 10 5 100 50 500 callback-1 indirect-1 665 assert= ;
677 [ float-4{ 0 0 0 0 } ]
678 [ 5.0 float-4{ 1 2 3 4 } float-4{ 4 5 6 7 } 0.0 simd-spill-test-3 ] unit-test
680 ! Stack allocation of SIMD values -- make sure that everything is
683 : simd-stack-test ( -- b c )
685 [ 123 swap 0 c:int c:set-alien-value ]
686 [ float-4{ 1 2 3 4 } swap 0 float-4 c:set-alien-value ] bi*
687 ] [ ] with-out-parameters ;
689 [ 123 float-4{ 1 2 3 4 } ] [ simd-stack-test ] unit-test
691 ! Stack allocation + spilling
693 : (simd-stack-spill-test) ( -- n ) 17 ;
695 : simd-stack-spill-test ( x -- b c )
697 123 swap 0 c:int c:set-alien-value
698 >float (simd-stack-spill-test) float-4-with swap cos v*n
699 ] [ ] with-out-parameters ;
702 1.047197551196598 simd-stack-spill-test
703 [ float-4{ 8.5 8.5 8.5 8.5 } approx= t assert= ]