2009-09-20 17:48:17 -04:00
|
|
|
USING: accessors arrays classes compiler compiler.tree.debugger
|
|
|
|
effects fry io kernel kernel.private math math.functions
|
|
|
|
math.private math.vectors math.vectors.simd
|
|
|
|
math.vectors.simd.private prettyprint random sequences system
|
|
|
|
tools.test vocabs assocs compiler.cfg.debugger words
|
|
|
|
locals math.vectors.specialization combinators cpu.architecture
|
|
|
|
math.vectors.simd.intrinsics namespaces byte-arrays alien
|
2009-09-23 21:23:25 -04:00
|
|
|
specialized-arrays classes.struct eval ;
|
2009-09-28 07:34:22 -04:00
|
|
|
QUALIFIED-WITH: alien.c-types c
|
|
|
|
SPECIALIZED-ARRAY: c:float
|
|
|
|
SIMD: c:char
|
|
|
|
SIMD: c:uchar
|
|
|
|
SIMD: c:short
|
|
|
|
SIMD: c:ushort
|
|
|
|
SIMD: c:int
|
|
|
|
SIMD: c:uint
|
|
|
|
SIMD: c:longlong
|
|
|
|
SIMD: c:ulonglong
|
|
|
|
SIMD: c:float
|
|
|
|
SIMD: c:double
|
2009-09-03 03:33:07 -04:00
|
|
|
IN: math.vectors.simd.tests
|
|
|
|
|
2009-09-23 21:23:25 -04:00
|
|
|
! Make sure the functor doesn't generate bogus vocabularies
|
|
|
|
2 [ [ "USE: math.vectors.simd SIMD: rubinius" eval( -- ) ] must-fail ] times
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-23 21:23:25 -04:00
|
|
|
[ f ] [ "math.vectors.simd.instances.rubinius" vocab ] unit-test
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-23 21:23:25 -04:00
|
|
|
! Test type propagation
|
2009-09-03 21:58:56 -04:00
|
|
|
[ V{ float } ] [ [ { float-4 } declare norm-sq ] final-classes ] unit-test
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-03 21:58:56 -04:00
|
|
|
[ V{ float } ] [ [ { float-4 } declare norm ] final-classes ] unit-test
|
|
|
|
|
2009-09-23 21:23:25 -04:00
|
|
|
[ V{ float-4 } ] [ [ { float-4 } declare normalize ] final-classes ] unit-test
|
|
|
|
|
|
|
|
[ V{ float-4 } ] [ [ { float-4 float-4 } declare v+ ] final-classes ] unit-test
|
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
! Test puns; only on x86
|
|
|
|
cpu x86? [
|
|
|
|
[ double-2{ 4 1024 } ] [
|
|
|
|
float-4{ 0 1 0 2 }
|
|
|
|
[ { float-4 } declare dup v+ underlying>> double-2 boa dup v+ ] compile-call
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ 33.0 ] [
|
|
|
|
double-2{ 1 2 } double-2{ 10 20 }
|
|
|
|
[ { double-2 double-2 } declare v+ underlying>> 3.0 float* ] compile-call
|
|
|
|
] unit-test
|
|
|
|
] when
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
! Fuzz testing
|
|
|
|
CONSTANT: simd-classes
|
|
|
|
{
|
|
|
|
char-16
|
|
|
|
uchar-16
|
|
|
|
char-32
|
|
|
|
uchar-32
|
|
|
|
short-8
|
|
|
|
ushort-8
|
|
|
|
short-16
|
|
|
|
ushort-16
|
|
|
|
int-4
|
|
|
|
uint-4
|
|
|
|
int-8
|
|
|
|
uint-8
|
2009-09-23 21:23:25 -04:00
|
|
|
longlong-2
|
|
|
|
ulonglong-2
|
|
|
|
longlong-4
|
|
|
|
ulonglong-4
|
2009-09-20 17:48:17 -04:00
|
|
|
float-4
|
|
|
|
float-8
|
|
|
|
double-2
|
|
|
|
double-4
|
|
|
|
}
|
|
|
|
|
|
|
|
: with-ctors ( -- seq )
|
|
|
|
simd-classes [ [ name>> "-with" append ] [ vocabulary>> ] bi lookup ] map ;
|
|
|
|
|
|
|
|
: boa-ctors ( -- seq )
|
|
|
|
simd-classes [ [ name>> "-boa" append ] [ vocabulary>> ] bi lookup ] map ;
|
|
|
|
|
2009-09-23 02:05:19 -04:00
|
|
|
: check-optimizer ( seq inputs quot eq-quot -- )
|
|
|
|
'[
|
|
|
|
@
|
2009-09-25 22:44:14 -04:00
|
|
|
{
|
|
|
|
[ "print-mr" get [ nip test-mr mr. ] [ 2drop ] if ]
|
|
|
|
[ "print-checks" get [ [ . ] bi@ ] [ 2drop ] if ]
|
|
|
|
[ [ call ] dip call ]
|
|
|
|
[ [ call ] dip compile-call ]
|
|
|
|
} 2cleave
|
|
|
|
@ not
|
2009-09-23 02:05:19 -04:00
|
|
|
] filter ; inline
|
2009-09-20 17:48:17 -04:00
|
|
|
|
|
|
|
"== Checking -new constructors" print
|
|
|
|
|
|
|
|
[ { } ] [
|
2009-09-23 02:05:19 -04:00
|
|
|
simd-classes [ [ [ ] ] dip '[ _ new ] ] [ = ] check-optimizer
|
2009-09-20 17:48:17 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ { } ] [
|
|
|
|
simd-classes [ '[ _ new ] compile-call [ zero? ] all? not ] filter
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
"== Checking -with constructors" print
|
|
|
|
|
|
|
|
[ { } ] [
|
|
|
|
with-ctors [
|
|
|
|
[ 1000 random '[ _ ] ] dip '[ { fixnum } declare _ execute ]
|
2009-09-23 02:05:19 -04:00
|
|
|
] [ = ] check-optimizer
|
2009-09-20 17:48:17 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
"== Checking -boa constructors" print
|
|
|
|
|
|
|
|
[ { } ] [
|
|
|
|
boa-ctors [
|
|
|
|
dup stack-effect in>> length
|
|
|
|
[ nip [ 1000 random ] [ ] replicate-as ]
|
|
|
|
[ fixnum <array> swap '[ _ declare _ execute ] ]
|
|
|
|
2bi
|
2009-09-23 02:05:19 -04:00
|
|
|
] [ = ] check-optimizer
|
2009-09-20 17:48:17 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
"== Checking vector operations" print
|
|
|
|
|
|
|
|
: random-vector ( class -- vec )
|
|
|
|
new [ drop 1000 random ] map ;
|
|
|
|
|
|
|
|
:: check-vector-op ( word inputs class elt-class -- inputs quot )
|
|
|
|
inputs [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
{ +vector+ [ class random-vector ] }
|
|
|
|
{ +scalar+ [ 1000 random elt-class float = [ >float ] when ] }
|
|
|
|
} case
|
|
|
|
] [ ] map-as
|
|
|
|
] [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
{ +vector+ [ class ] }
|
|
|
|
{ +scalar+ [ elt-class ] }
|
|
|
|
} case
|
|
|
|
] map
|
|
|
|
] bi
|
|
|
|
word '[ _ declare _ execute ] ;
|
|
|
|
|
2009-09-23 02:05:19 -04:00
|
|
|
: remove-float-words ( alist -- alist' )
|
2009-09-23 03:46:54 -04:00
|
|
|
[ drop { vsqrt n/v v/n v/ normalize } member? not ] assoc-filter ;
|
2009-09-23 02:05:19 -04:00
|
|
|
|
2009-09-24 04:32:39 -04:00
|
|
|
: remove-integer-words ( alist -- alist' )
|
2009-09-24 07:58:33 -04:00
|
|
|
[ drop { vlshift vrshift } member? not ] assoc-filter ;
|
2009-09-24 04:32:39 -04:00
|
|
|
|
2009-09-29 00:12:13 -04:00
|
|
|
: remove-special-words ( alist -- alist' )
|
|
|
|
! These have their own tests later
|
|
|
|
[ drop { hlshift hrshift vshuffle } member? not ] assoc-filter ;
|
2009-09-28 03:17:46 -04:00
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
: ops-to-check ( elt-class -- alist )
|
2009-09-23 02:05:19 -04:00
|
|
|
[ vector-words >alist ] dip
|
2009-09-28 03:17:46 -04:00
|
|
|
float = [ remove-integer-words ] [ remove-float-words ] if
|
2009-09-29 00:12:13 -04:00
|
|
|
remove-special-words ;
|
2009-09-23 02:05:19 -04:00
|
|
|
|
|
|
|
: check-vector-ops ( class elt-class compare-quot -- )
|
|
|
|
[
|
|
|
|
[ nip ops-to-check ] 2keep
|
|
|
|
'[ first2 inputs _ _ check-vector-op ]
|
|
|
|
] dip check-optimizer ; inline
|
2009-09-20 17:48:17 -04:00
|
|
|
|
2009-09-23 02:05:19 -04:00
|
|
|
: approx= ( x y -- ? )
|
|
|
|
{
|
|
|
|
{ [ 2dup [ float? ] both? ] [ -1.e8 ~ ] }
|
|
|
|
{ [ 2dup [ sequence? ] both? ] [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
{ [ 2dup [ fp-nan? ] both? ] [ 2drop t ] }
|
|
|
|
{ [ 2dup [ fp-nan? ] either? not ] [ -1.e8 ~ ] }
|
|
|
|
} cond
|
|
|
|
] 2all?
|
|
|
|
] }
|
|
|
|
} cond ;
|
2009-09-20 17:48:17 -04:00
|
|
|
|
|
|
|
: simd-classes&reps ( -- alist )
|
|
|
|
simd-classes [
|
2009-09-23 02:05:19 -04:00
|
|
|
{
|
|
|
|
{ [ dup name>> "float" head? ] [ float [ approx= ] ] }
|
2009-09-24 04:32:39 -04:00
|
|
|
{ [ dup name>> "double" head? ] [ float [ = ] ] }
|
2009-09-23 02:05:19 -04:00
|
|
|
[ fixnum [ = ] ]
|
|
|
|
} cond 3array
|
|
|
|
] map ;
|
2009-09-20 17:48:17 -04:00
|
|
|
|
|
|
|
simd-classes&reps [
|
2009-09-23 02:05:19 -04:00
|
|
|
[ [ { } ] ] dip first3 '[ _ _ _ check-vector-ops ] unit-test
|
|
|
|
] each
|
2009-09-20 17:48:17 -04:00
|
|
|
|
|
|
|
! Other regressions
|
|
|
|
[ 8000000 ] [
|
|
|
|
int-8{ 1000 1000 1000 1000 1000 1000 1000 1000 }
|
|
|
|
[ { int-8 } declare dup [ * ] [ + ] 2map-reduce ] compile-call
|
|
|
|
] unit-test
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
! Vector alien intrinsics
|
|
|
|
[ float-4{ 1 2 3 4 } ] [
|
|
|
|
[
|
|
|
|
float-4{ 1 2 3 4 }
|
|
|
|
underlying>> 0 float-4-rep alien-vector
|
|
|
|
] compile-call float-4 boa
|
2009-09-03 03:33:07 -04:00
|
|
|
] unit-test
|
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
[ B{ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 } ] [
|
|
|
|
16 [ 1 ] B{ } replicate-as 16 <byte-array>
|
|
|
|
[
|
|
|
|
0 [
|
|
|
|
{ byte-array c-ptr fixnum } declare
|
|
|
|
float-4-rep set-alien-vector
|
|
|
|
] compile-call
|
|
|
|
] keep
|
2009-09-03 03:33:07 -04:00
|
|
|
] unit-test
|
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
[ float-array{ 1 2 3 4 } ] [
|
|
|
|
[
|
|
|
|
float-array{ 1 2 3 4 } underlying>>
|
|
|
|
float-array{ 4 3 2 1 } clone
|
|
|
|
[ underlying>> 0 float-4-rep set-alien-vector ] keep
|
|
|
|
] compile-call
|
2009-09-03 03:33:07 -04:00
|
|
|
] unit-test
|
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
STRUCT: simd-struct
|
|
|
|
{ x float-4 }
|
|
|
|
{ y double-2 }
|
|
|
|
{ z double-4 }
|
|
|
|
{ w float-8 } ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
[ t ] [ [ simd-struct <struct> ] compile-call >c-ptr [ 0 = ] all? ] unit-test
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
[
|
2009-09-03 21:58:56 -04:00
|
|
|
float-4{ 1 2 3 4 }
|
2009-09-20 17:48:17 -04:00
|
|
|
double-2{ 2 1 }
|
|
|
|
double-4{ 4 3 2 1 }
|
2009-09-03 21:58:56 -04:00
|
|
|
float-8{ 1 2 3 4 5 6 7 8 }
|
2009-09-20 17:48:17 -04:00
|
|
|
] [
|
|
|
|
simd-struct <struct>
|
|
|
|
float-4{ 1 2 3 4 } >>x
|
|
|
|
double-2{ 2 1 } >>y
|
|
|
|
double-4{ 4 3 2 1 } >>z
|
|
|
|
float-8{ 1 2 3 4 5 6 7 8 } >>w
|
|
|
|
{ [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
|
2009-09-03 21:58:56 -04:00
|
|
|
] unit-test
|
|
|
|
|
2009-09-20 17:48:17 -04:00
|
|
|
[
|
|
|
|
float-4{ 1 2 3 4 }
|
|
|
|
double-2{ 2 1 }
|
|
|
|
double-4{ 4 3 2 1 }
|
2009-09-03 21:58:56 -04:00
|
|
|
float-8{ 1 2 3 4 5 6 7 8 }
|
2009-09-20 17:48:17 -04:00
|
|
|
] [
|
|
|
|
[
|
|
|
|
simd-struct <struct>
|
|
|
|
float-4{ 1 2 3 4 } >>x
|
|
|
|
double-2{ 2 1 } >>y
|
|
|
|
double-4{ 4 3 2 1 } >>z
|
|
|
|
float-8{ 1 2 3 4 5 6 7 8 } >>w
|
|
|
|
{ [ x>> ] [ y>> ] [ z>> ] [ w>> ] } cleave
|
|
|
|
] compile-call
|
2009-09-03 21:58:56 -04:00
|
|
|
] unit-test
|
2009-09-23 03:46:54 -04:00
|
|
|
|
|
|
|
[ ] [ char-16 new 1array stack. ] unit-test
|
2009-09-28 03:17:46 -04:00
|
|
|
|
|
|
|
[ int-4{ 256 512 1024 2048 } ]
|
|
|
|
[ int-4{ 1 2 4 8 } 1 hlshift ] unit-test
|
|
|
|
|
|
|
|
[ int-4{ 256 512 1024 2048 } ]
|
|
|
|
[ int-4{ 1 2 4 8 } [ { int-4 } declare 1 hlshift ] compile-call ] unit-test
|
|
|
|
|
|
|
|
[ int-4{ 1 2 4 8 } ]
|
|
|
|
[ int-4{ 256 512 1024 2048 } 1 hrshift ] unit-test
|
|
|
|
|
|
|
|
[ int-4{ 1 2 4 8 } ]
|
|
|
|
[ int-4{ 256 512 1024 2048 } [ { int-4 } declare 1 hrshift ] compile-call ] unit-test
|
2009-09-29 00:12:13 -04:00
|
|
|
|
|
|
|
! Shuffles
|
|
|
|
: test-shuffle ( input shuffle -- failures )
|
|
|
|
[ dup class 1array ] dip
|
|
|
|
'[ _ declare _ vshuffle ]
|
|
|
|
[ call ] [ compile-call ] 2bi = not ; inline
|
|
|
|
|
|
|
|
: shuffles-for ( seq -- shuffles )
|
|
|
|
length {
|
|
|
|
{ 2 [
|
|
|
|
{
|
|
|
|
{ 0 1 }
|
|
|
|
{ 1 1 }
|
|
|
|
{ 1 0 }
|
|
|
|
{ 0 0 }
|
|
|
|
}
|
|
|
|
] }
|
|
|
|
{ 4 [
|
|
|
|
{
|
|
|
|
{ 1 2 3 0 }
|
|
|
|
{ 0 1 2 3 }
|
|
|
|
{ 1 1 2 2 }
|
|
|
|
{ 0 0 1 1 }
|
|
|
|
{ 2 2 3 3 }
|
|
|
|
{ 0 1 0 1 }
|
|
|
|
{ 2 3 2 3 }
|
|
|
|
{ 0 0 2 2 }
|
|
|
|
{ 1 1 3 3 }
|
|
|
|
{ 0 1 0 1 }
|
|
|
|
{ 2 2 3 3 }
|
|
|
|
}
|
|
|
|
] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
: test-shuffles ( input -- failures )
|
|
|
|
dup shuffles-for [ test-shuffle ] with filter ; inline
|
|
|
|
|
|
|
|
[ { } ] [ float-4{ 1.0 2.0 3.0 4.0 } test-shuffles ] unit-test
|
|
|
|
[ { } ] [ int-4{ 1 2 3 4 } test-shuffles ] unit-test
|
|
|
|
[ { } ] [ uint-4{ 1 2 3 4 } test-shuffles ] unit-test
|
|
|
|
|
|
|
|
[ { } ] [ double-2{ 1.0 2.0 } test-shuffles ] unit-test
|
|
|
|
[ { } ] [ longlong-2{ 1 2 } test-shuffles ] unit-test
|
|
|
|
[ { } ] [ ulonglong-2{ 1 2 } test-shuffles ] unit-test
|