]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler: add intrinsic for PMOVMSKB/MOVMSKP[SD]
authorJoe Groff <arcata@gmail.com>
Sat, 12 Nov 2011 06:47:54 +0000 (22:47 -0800)
committerJoe Groff <arcata@gmail.com>
Mon, 14 Nov 2011 00:10:20 +0000 (16:10 -0800)
Combined with a fast bit-count this will let us rice byte-counting.

basis/compiler/cfg/instructions/instructions.factor
basis/compiler/cfg/intrinsics/simd/backend/backend.factor
basis/compiler/cfg/intrinsics/simd/simd-tests.factor
basis/compiler/cfg/intrinsics/simd/simd.factor
basis/compiler/codegen/codegen.factor
basis/compiler/tree/propagation/simd/simd.factor
basis/cpu/architecture/architecture.factor
basis/cpu/x86/sse/sse.factor
basis/math/vectors/simd/intrinsics/intrinsics.factor
basis/math/vectors/simd/simd.factor
basis/math/vectors/vectors.factor

index 812e206c958c6843b6d61099fa40be39141c2288..91c14887500dc4ebd824a068a24c136120b8988e 100644 (file)
@@ -380,6 +380,11 @@ def: dst
 use: src1 src2
 literal: rep cc ;
 
+FOLDABLE-INSN: ##move-vector-mask
+def: dst/int-rep
+use: src
+literal: rep ;
+
 FOLDABLE-INSN: ##test-vector
 def: dst/tagged-rep
 use: src1
index 84ffc208d5975bff0d49a1a9bf4b4ed067a8a22e..5c51afb8f9181a867b4bf4e25662b88baea87d62 100644 (file)
@@ -37,6 +37,7 @@ M: ##tail>head-vector insn-available? rep>> %unpack-vector-head-reps member? ;
 M: ##integer>float-vector insn-available? rep>> %integer>float-vector-reps member? ;
 M: ##float>integer-vector insn-available? rep>> %float>integer-vector-reps member? ;
 M: ##compare-vector insn-available? [ rep>> ] [ cc>> ] bi %compare-vector-reps member? ;
+M: ##move-vector-mask insn-available? rep>> %move-vector-mask-reps member? ;
 M: ##test-vector insn-available? rep>> %test-vector-reps member? ;
 M: ##add-vector insn-available? rep>> %add-vector-reps member? ;
 M: ##saturated-add-vector insn-available? rep>> %saturated-add-vector-reps member? ;
index 6d0deff5b33860a4398cc72f8c72d136a048519f..ff9ecd61124c5fbeeeb54b8d798c521ef88d5d80 100644 (file)
@@ -109,6 +109,7 @@ M: simple-ops-cpu %or-vector-reps    all-reps ;
 M: simple-ops-cpu %xor-vector-reps   all-reps ;
 M: simple-ops-cpu %merge-vector-reps all-reps ;
 M: simple-ops-cpu %sqrt-vector-reps  all-reps ;
+M: simple-ops-cpu %move-vector-mask-reps  all-reps ;
 M: simple-ops-cpu %test-vector-reps  all-reps ;
 M: simple-ops-cpu %signed-pack-vector-reps   all-reps ;
 M: simple-ops-cpu %unsigned-pack-vector-reps all-reps ;
index 7ef4b4cf6265097184a26783c1f51c937fed4028..1e1d1c462a2e7f86ae82f31cb08b64d47b61c78c 100644 (file)
@@ -555,6 +555,10 @@ PREDICATE: fixnum-vector-rep < int-vector-rep
     {
         [ vcc-none ^^test-vector ]
     } emit-v-vector-op ;
+: emit-simd-vgetmask ( node -- )
+    {
+        [ ^^move-vector-mask ]
+    } emit-v-vector-op ;
 
 : emit-simd-v>float ( node -- )
     {
@@ -700,6 +704,7 @@ PREDICATE: fixnum-vector-rep < int-vector-rep
         { alien-vector              [ emit-alien-vector             ] }
         { set-alien-vector          [ emit-set-alien-vector         ] }
         { assert-positive           [ drop                          ] }
+        { (simd-vgetmask)           [ emit-simd-vgetmask            ] }
     } enable-intrinsics ;
 
 enable-simd
index 3434085685fc00d30efbca912add888bc93b153e..1c510a2fcd8988da4ee02bd072f90588a26c3656 100755 (executable)
@@ -223,6 +223,7 @@ CODEGEN: ##unpack-vector-tail %unpack-vector-tail
 CODEGEN: ##integer>float-vector %integer>float-vector
 CODEGEN: ##float>integer-vector %float>integer-vector
 CODEGEN: ##compare-vector %compare-vector
+CODEGEN: ##move-vector-mask %move-vector-mask
 CODEGEN: ##test-vector %test-vector
 CODEGEN: ##add-vector %add-vector
 CODEGEN: ##saturated-add-vector %saturated-add-vector
index 6b72743374f0b2d10f7af4647fb50bc1473b0d21..4f1c1d3bb3c89e25269fee5ad93285a0713110c7 100644 (file)
@@ -69,6 +69,7 @@ CONSTANT: vector-other-intrinsics
         (simd-vany?)
         (simd-vall?)
         (simd-vnone?)
+        (simd-vgetmask)
         (simd-select)
         set-alien-vector
     }
@@ -104,6 +105,8 @@ vector>vector-intrinsics [ { byte-array } "default-output-classes" set-word-prop
     real [0,inf] <class/interval-info> value-info-intersect
 ] "outputs" set-word-prop
 
+\ (simd-vgetmask) { fixnum } "default-output-classes" set-word-prop
+
 : clone-with-value-infos ( node -- node' )
     clone dup in-d>> extract-value-info >>info ;
 
index 561787e2ba01d5cff461c162eb530c85e09734c0..272e08ab80002a74f45091391b12125ab28961b3 100644 (file)
@@ -322,6 +322,7 @@ HOOK: %unpack-vector-tail cpu ( dst src rep -- )
 HOOK: %integer>float-vector cpu ( dst src rep -- )
 HOOK: %float>integer-vector cpu ( dst src rep -- )
 HOOK: %compare-vector cpu ( dst src1 src2 rep cc -- )
+HOOK: %move-vector-mask cpu ( dst src rep -- )
 HOOK: %test-vector cpu ( dst src1 temp rep vcc -- )
 HOOK: %test-vector-branch cpu ( label src1 temp rep vcc -- )
 HOOK: %add-vector cpu ( dst src1 src2 rep -- )
@@ -381,6 +382,7 @@ HOOK: %integer>float-vector-reps cpu ( -- reps )
 HOOK: %float>integer-vector-reps cpu ( -- reps )
 HOOK: %compare-vector-reps cpu ( cc -- reps )
 HOOK: %compare-vector-ccs cpu ( rep cc -- {cc,swap?}s not? )
+HOOK: %move-vector-mask-reps cpu ( -- reps )
 HOOK: %test-vector-reps cpu ( -- reps )
 HOOK: %add-vector-reps cpu ( -- reps )
 HOOK: %saturated-add-vector-reps cpu ( -- reps )
index f0866cb897707ca1eb264503c71076c4c37aea9e..63332145ab2294dc35547583b6611d7ab6c6e828 100644 (file)
@@ -476,15 +476,24 @@ M: x86 %compare-vector-ccs
         { vcc-notall [ dst mask CMP dst temp \ CMOVNE (%boolean) ] }
     } case ;
 
-: %move-vector-mask ( dst src rep -- mask )
+: %move-vector-mask* ( dst src rep -- mask )
     {
         { double-2-rep [ MOVMSKPS HEX: f ] }
         { float-4-rep  [ MOVMSKPS HEX: f ] }
         [ drop PMOVMSKB HEX: ffff ]
     } case ;
 
+M: x86 %move-vector-mask ( dst src rep -- )
+    %move-vector-mask* drop ;
+
+M: x86 %move-vector-mask-reps
+    {
+        { sse? { float-4-rep } }
+        { sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
+    } available-reps ;
+
 M:: x86 %test-vector ( dst src temp rep vcc -- )
-    dst src rep %move-vector-mask :> mask
+    dst src rep %move-vector-mask* :> mask
     dst temp mask vcc %test-vector-mask ;
 
 :: %test-vector-mask-branch ( label temp mask vcc -- )
@@ -496,7 +505,7 @@ M:: x86 %test-vector ( dst src temp rep vcc -- )
     } case ;
 
 M:: x86 %test-vector-branch ( label src temp rep vcc -- )
-    temp src rep %move-vector-mask :> mask
+    temp src rep %move-vector-mask* :> mask
     label temp mask vcc %test-vector-mask-branch ;
 
 M: x86 %test-vector-reps
index 1defa827da6613aa8f4580381895cec2f22349c8..5a2cbe2fe86411f673be7b3f82cecbc949a130ba 100644 (file)
@@ -4,7 +4,8 @@ sequences.cords cpu.architecture fry generalizations grouping
 kernel libc locals macros math math.libm math.order
 math.ranges math.vectors sequences sequences.generalizations
 sequences.private sequences.unrolled sequences.unrolled.private
-specialized-arrays vocabs words effects.parser locals.parser ;
+specialized-arrays vocabs words effects.parser locals.parser
+math.bitwise ;
 QUALIFIED-WITH: alien.c-types c
 SPECIALIZED-ARRAYS:
     c:char c:short c:int c:longlong
@@ -127,6 +128,8 @@ SYNTAX: SIMD-INTRINSIC::
 ! XXX
 : bitwise-components-reduce ( a rep quot -- x )
     [ >bitwise-vector-rep >rep-array [ ] ] dip map-reduce ; inline
+: bitwise-components-reduce* ( a rep identity quot -- x )
+    [ >bitwise-vector-rep >rep-array ] 2dip reduce ; inline
 
 :: (vshuffle) ( a elts rep -- c )
     a rep >rep-array :> a'
@@ -259,6 +262,7 @@ SIMD-INTRINSIC: (simd-vunordered?)       ( a b rep -- c )
 SIMD-INTRINSIC: (simd-vany?)             ( a   rep -- ? ) [ bitor  ] bitwise-components-reduce zero? not ;
 SIMD-INTRINSIC: (simd-vall?)             ( a   rep -- ? ) [ bitand ] bitwise-components-reduce zero? not ;
 SIMD-INTRINSIC: (simd-vnone?)            ( a   rep -- ? ) [ bitor  ] bitwise-components-reduce zero?     ;
+SIMD-INTRINSIC: (simd-vgetmask)          ( a   rep -- n ) 0 [ [ 1 shift ] [ zero? 0 1 ? ] bi* bitor ] bitwise-components-reduce* ;
 SIMD-INTRINSIC: (simd-v>float)           ( a   rep -- c )
     [ [ >rep-array ] [ rep-length ] bi [ >float ] ]
     [ >float-vector-rep <rep-array> ] bi unrolled-map-as-unsafe underlying>> ;
index a0d949fb6860c5d6dcf00a0fcfdbb3b00cc8a5af..df54fc83461c353289acd543510b385a54d46669 100644 (file)
@@ -4,7 +4,7 @@ generic.parser kernel lexer literals locals macros math math.functions
 math.vectors math.vectors.private math.vectors.simd.intrinsics
 namespaces parser prettyprint.custom quotations sequences
 sequences.generalizations sequences.private vocabs vocabs.loader
-words ;
+words math.bitwise ;
 QUALIFIED-WITH: alien.c-types c
 IN: math.vectors.simd
 
@@ -221,6 +221,8 @@ M: simd-128 vany?
     dup simd-rep [ (simd-vany?)             ] [ call-next-method ] v->x-op  ; inline
 M: simd-128 vall?
     dup simd-rep [ (simd-vall?)             ] [ call-next-method ] v->x-op  ; inline
+M: simd-128 vcount
+    dup simd-rep [ (simd-vgetmask) assert-positive ] [ call-next-method ] v->x-op bit-count ; inline
 M: simd-128 vnone?
     dup simd-rep [ (simd-vnone?)            ] [ call-next-method ] v->x-op  ; inline
 
index eb322175a8a63e37a69446699764de53c251d246..466c8b4826fe36a422d59a7ae695c79fe84656a4 100644 (file)
@@ -162,6 +162,9 @@ M: object vnot [ not ] map ; inline
 GENERIC: vall? ( v -- ? )
 M: object vall? [ ] all? ; inline
 
+GENERIC: vcount ( v -- count )
+M: object vcount [ ] count ; inline
+
 GENERIC: vany? ( v -- ? )
 M: object vany? [ ] any? ; inline