compiler.cfg.intrinsics.simd: refactoring to use assocs instead of case-s for lookups + tests

db4
Björn Lindqvist 2015-04-10 22:11:57 +02:00 committed by John Benediktsson
parent 745d3f29b2
commit 6c6f85428c
2 changed files with 153 additions and 39 deletions

View File

@ -2,8 +2,8 @@
USING: arrays assocs biassocs byte-arrays byte-arrays.hex USING: arrays assocs biassocs byte-arrays byte-arrays.hex
classes compiler.cfg compiler.cfg.comparisons compiler.cfg.instructions classes compiler.cfg compiler.cfg.comparisons compiler.cfg.instructions
compiler.cfg.intrinsics.simd compiler.cfg.intrinsics.simd.backend compiler.cfg.intrinsics.simd compiler.cfg.intrinsics.simd.backend
compiler.cfg.registers compiler.cfg.stacks.height compiler.cfg.registers compiler.cfg.stacks.height compiler.cfg.stacks.local
compiler.cfg.stacks.local compiler.tree compiler.tree.propagation.info compiler.test compiler.tree compiler.tree.propagation.info
cpu.architecture fry hashtables kernel locals make namespaces sequences cpu.architecture fry hashtables kernel locals make namespaces sequences
system tools.test words ; system tools.test words ;
IN: compiler.cfg.intrinsics.simd.tests IN: compiler.cfg.intrinsics.simd.tests
@ -525,6 +525,104 @@ unit-test
[ shuffle-imm-cpu 1 float-4-rep [ emit-simd-select ] test-emit-literal ] [ shuffle-imm-cpu 1 float-4-rep [ emit-simd-select ] test-emit-literal ]
unit-test unit-test
! ^load-neg-zero-vector
{
V{
T{ ##load-reference
{ dst 1 }
{ obj B{ 0 0 0 128 0 0 0 128 0 0 0 128 0 0 0 128 } }
}
T{ ##load-reference
{ dst 2 }
{ obj B{ 0 0 0 0 0 0 0 128 0 0 0 0 0 0 0 128 } }
}
}
} [
[
{ float-4-rep double-2-rep } [ ^load-neg-zero-vector drop ] each
] V{ } make
] cfg-unit-test
! ^load-add-sub-vector
{
V{
T{ ##load-reference
{ dst 1 }
{ obj B{ 0 0 0 128 0 0 0 0 0 0 0 128 0 0 0 0 } }
}
T{ ##load-reference
{ dst 2 }
{ obj B{ 0 0 0 0 0 0 0 128 0 0 0 0 0 0 0 0 } }
}
T{ ##load-reference
{ dst 3 }
{ obj
B{ 255 0 255 0 255 0 255 0 255 0 255 0 255 0 255 0 }
}
}
T{ ##load-reference
{ dst 4 }
{ obj
B{ 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 }
}
}
T{ ##load-reference
{ dst 5 }
{ obj
B{ 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 }
}
}
T{ ##load-reference
{ dst 6 }
{ obj
B{ 255 255 255 255 255 255 255 255 0 0 0 0 0 0 0 0 }
}
}
}
} [
[
{
float-4-rep
double-2-rep
char-16-rep
short-8-rep
int-4-rep
longlong-2-rep
} [ ^load-add-sub-vector drop ] each
] V{ } make
] cfg-unit-test
! ^load-half-vector
{
V{
T{ ##load-reference
{ dst 1 }
{ obj B{ 0 0 0 63 0 0 0 63 0 0 0 63 0 0 0 63 } }
}
T{ ##load-reference
{ dst 2 }
{ obj B{ 0 0 0 0 0 0 224 63 0 0 0 0 0 0 224 63 } }
}
}
} [
[
{ float-4-rep double-2-rep } [ ^load-half-vector drop ] each
] V{ } make
] cfg-unit-test
! sign-bit-mask
{
{
B{ 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 }
B{ 0 128 0 128 0 128 0 128 0 128 0 128 0 128 0 128 }
B{ 0 0 0 128 0 0 0 128 0 0 0 128 0 0 0 128 }
B{ 0 0 0 0 0 0 0 128 0 0 0 0 0 0 0 128 }
}
} [
{ char-16-rep short-8-rep int-4-rep longlong-2-rep } [ sign-bit-mask ] map
] unit-test
! test with nonliteral/invalid reps ! test with nonliteral/invalid reps
[ simple-ops-cpu [ emit-simd-v+ ] test-emit-nonliteral-rep ] [ simple-ops-cpu [ emit-simd-v+ ] test-emit-nonliteral-rep ]
[ bad-simd-intrinsic? ] must-fail-with [ bad-simd-intrinsic? ] must-fail-with

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009 Slava Pestov, Joe Groff. ! Copyright (C) 2009 Slava Pestov, Joe Groff.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays byte-arrays combinators USING: accessors alien.c-types arrays assocs byte-arrays combinators
combinators.short-circuit compiler.cfg.comparisons combinators.short-circuit compiler.cfg.comparisons
compiler.cfg.hats compiler.cfg.instructions compiler.cfg.hats compiler.cfg.instructions
compiler.cfg.intrinsics compiler.cfg.intrinsics.alien compiler.cfg.intrinsics compiler.cfg.intrinsics.alien
@ -13,49 +13,65 @@ IN: compiler.cfg.intrinsics.simd
! compound vector ops ! compound vector ops
CONSTANT: rep>bit-mask {
{
char-16-rep uchar-array{
0x80 0x80 0x80 0x80
0x80 0x80 0x80 0x80
0x80 0x80 0x80 0x80
0x80 0x80 0x80 0x80
}
}
{
short-8-rep ushort-array{
0x8000 0x8000 0x8000 0x8000
0x8000 0x8000 0x8000 0x8000
}
}
{
int-4-rep uint-array{
0x8000,0000 0x8000,0000
0x8000,0000 0x8000,0000
}
}
{
longlong-2-rep ulonglong-array{
0x8000,0000,0000,0000
0x8000,0000,0000,0000
}
}
}
: sign-bit-mask ( rep -- byte-array ) : sign-bit-mask ( rep -- byte-array )
signed-rep { signed-rep rep>bit-mask at underlying>> ;
{ char-16-rep [ uchar-array{
0x80 0x80 0x80 0x80 CONSTANT: rep>neg-zero {
0x80 0x80 0x80 0x80 { float-4-rep float-array{ -0.0 -0.0 -0.0 -0.0 } }
0x80 0x80 0x80 0x80 { double-2-rep double-array{ -0.0 -0.0 } }
0x80 0x80 0x80 0x80 }
} underlying>> ] }
{ short-8-rep [ ushort-array{
0x8000 0x8000 0x8000 0x8000
0x8000 0x8000 0x8000 0x8000
} underlying>> ] }
{ int-4-rep [ uint-array{
0x8000,0000 0x8000,0000
0x8000,0000 0x8000,0000
} underlying>> ] }
{ longlong-2-rep [ ulonglong-array{
0x8000,0000,0000,0000
0x8000,0000,0000,0000
} underlying>> ] }
} case ;
: ^load-neg-zero-vector ( rep -- dst ) : ^load-neg-zero-vector ( rep -- dst )
{ rep>neg-zero at underlying>> ^^load-literal ;
{ float-4-rep [ float-array{ -0.0 -0.0 -0.0 -0.0 } underlying>> ^^load-literal ] }
{ double-2-rep [ double-array{ -0.0 -0.0 } underlying>> ^^load-literal ] } CONSTANT: rep>add-sub {
} case ; { float-4-rep float-array{ -0.0 0.0 -0.0 0.0 } }
{ double-2-rep double-array{ -0.0 0.0 } }
{ char-16-rep char-array{ -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 } }
{ short-8-rep short-array{ -1 0 -1 0 -1 0 -1 0 } }
{ int-4-rep int-array{ -1 0 -1 0 } }
{ longlong-2-rep longlong-array{ -1 0 } }
}
: ^load-add-sub-vector ( rep -- dst ) : ^load-add-sub-vector ( rep -- dst )
signed-rep { signed-rep rep>add-sub at underlying>> ^^load-literal ;
{ float-4-rep [ float-array{ -0.0 0.0 -0.0 0.0 } underlying>> ^^load-literal ] }
{ double-2-rep [ double-array{ -0.0 0.0 } underlying>> ^^load-literal ] } CONSTANT: rep>half {
{ char-16-rep [ char-array{ -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 } underlying>> ^^load-literal ] } { float-4-rep float-array{ 0.5 0.5 0.5 0.5 } }
{ short-8-rep [ short-array{ -1 0 -1 0 -1 0 -1 0 } underlying>> ^^load-literal ] } { double-2-rep double-array{ 0.5 0.5 } }
{ int-4-rep [ int-array{ -1 0 -1 0 } underlying>> ^^load-literal ] } }
{ longlong-2-rep [ longlong-array{ -1 0 } underlying>> ^^load-literal ] }
} case ;
: ^load-half-vector ( rep -- dst ) : ^load-half-vector ( rep -- dst )
{ rep>half at underlying>> ^^load-literal ;
{ float-4-rep [ float-array{ 0.5 0.5 0.5 0.5 } underlying>> ^^load-literal ] }
{ double-2-rep [ double-array{ 0.5 0.5 } underlying>> ^^load-literal ] }
} case ;
: >variable-shuffle ( shuffle rep -- shuffle' ) : >variable-shuffle ( shuffle rep -- shuffle' )
rep-component-type heap-size rep-component-type heap-size