]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg.intrinsics.simd: refactoring to use assocs instead of case-s for lookups...
authorBjörn Lindqvist <bjourne@gmail.com>
Fri, 10 Apr 2015 20:11:57 +0000 (22:11 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 29 Apr 2015 16:31:56 +0000 (09:31 -0700)
basis/compiler/cfg/intrinsics/simd/simd-tests.factor
basis/compiler/cfg/intrinsics/simd/simd.factor

index 8d5cc8b4dbd4cd2be2fc4a013b6f3187e138be0e..2df5a58e53eafd10ad66fc58e94cce71de230d78 100644 (file)
@@ -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
index 402b70adace738d0be7228bd9fc92c940cba20c3..93db54f7cc3eb06c364f58697e9aa1bbb8e86bc1 100644 (file)
@@ -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
 
-: sign-bit-mask ( rep -- byte-array )
-    signed-rep {
-        { char-16-rep [ uchar-array{
+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
-        } underlying>> ] }
-        { short-8-rep [ ushort-array{
+        }
+    }
+    {
+        short-8-rep ushort-array{
             0x8000 0x8000 0x8000 0x8000
             0x8000 0x8000 0x8000 0x8000
-        } underlying>> ] }
-        { int-4-rep [ uint-array{
+        }
+    }
+    {
+        int-4-rep uint-array{
             0x8000,0000 0x8000,0000
             0x8000,0000 0x8000,0000
-        } underlying>> ] }
-        { longlong-2-rep [ ulonglong-array{
+        }
+    }
+    {
+        longlong-2-rep ulonglong-array{
             0x8000,0000,0000,0000
             0x8000,0000,0000,0000
-        } underlying>> ] }
-    } case ;
+        }
+    }
+}
+
+: sign-bit-mask ( rep -- byte-array )
+    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