From 6c6f85428c0bae60edf9e14677f72827e31dbea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Fri, 10 Apr 2015 22:11:57 +0200 Subject: [PATCH] compiler.cfg.intrinsics.simd: refactoring to use assocs instead of case-s for lookups + tests --- .../cfg/intrinsics/simd/simd-tests.factor | 102 +++++++++++++++++- .../compiler/cfg/intrinsics/simd/simd.factor | 90 +++++++++------- 2 files changed, 153 insertions(+), 39 deletions(-) diff --git a/basis/compiler/cfg/intrinsics/simd/simd-tests.factor b/basis/compiler/cfg/intrinsics/simd/simd-tests.factor index 8d5cc8b4db..2df5a58e53 100644 --- a/basis/compiler/cfg/intrinsics/simd/simd-tests.factor +++ b/basis/compiler/cfg/intrinsics/simd/simd-tests.factor @@ -2,8 +2,8 @@ USING: arrays assocs biassocs byte-arrays byte-arrays.hex classes compiler.cfg compiler.cfg.comparisons compiler.cfg.instructions compiler.cfg.intrinsics.simd compiler.cfg.intrinsics.simd.backend -compiler.cfg.registers compiler.cfg.stacks.height -compiler.cfg.stacks.local compiler.tree compiler.tree.propagation.info +compiler.cfg.registers compiler.cfg.stacks.height compiler.cfg.stacks.local +compiler.test compiler.tree compiler.tree.propagation.info cpu.architecture fry hashtables kernel locals make namespaces sequences system tools.test words ; 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 ] 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 [ simple-ops-cpu [ emit-simd-v+ ] test-emit-nonliteral-rep ] [ bad-simd-intrinsic? ] must-fail-with diff --git a/basis/compiler/cfg/intrinsics/simd/simd.factor b/basis/compiler/cfg/intrinsics/simd/simd.factor index 402b70adac..93db54f7cc 100644 --- a/basis/compiler/cfg/intrinsics/simd/simd.factor +++ b/basis/compiler/cfg/intrinsics/simd/simd.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2009 Slava Pestov, Joe Groff. ! 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 compiler.cfg.hats compiler.cfg.instructions compiler.cfg.intrinsics compiler.cfg.intrinsics.alien @@ -13,49 +13,65 @@ IN: compiler.cfg.intrinsics.simd ! 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 ) - signed-rep { - { char-16-rep [ uchar-array{ - 0x80 0x80 0x80 0x80 - 0x80 0x80 0x80 0x80 - 0x80 0x80 0x80 0x80 - 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 ; + signed-rep rep>bit-mask at underlying>> ; + +CONSTANT: rep>neg-zero { + { float-4-rep float-array{ -0.0 -0.0 -0.0 -0.0 } } + { double-2-rep double-array{ -0.0 -0.0 } } +} : ^load-neg-zero-vector ( rep -- dst ) - { - { 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 ] } - } case ; + rep>neg-zero at underlying>> ^^load-literal ; + +CONSTANT: rep>add-sub { + { 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 ) - signed-rep { - { 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 ] } - { char-16-rep [ char-array{ -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 } underlying>> ^^load-literal ] } - { short-8-rep [ short-array{ -1 0 -1 0 -1 0 -1 0 } underlying>> ^^load-literal ] } - { int-4-rep [ int-array{ -1 0 -1 0 } underlying>> ^^load-literal ] } - { longlong-2-rep [ longlong-array{ -1 0 } underlying>> ^^load-literal ] } - } case ; + signed-rep rep>add-sub at underlying>> ^^load-literal ; + +CONSTANT: rep>half { + { float-4-rep float-array{ 0.5 0.5 0.5 0.5 } } + { double-2-rep double-array{ 0.5 0.5 } } +} : ^load-half-vector ( rep -- dst ) - { - { 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 ; + rep>half at underlying>> ^^load-literal ; : >variable-shuffle ( shuffle rep -- shuffle' ) rep-component-type heap-size