From d14f150b587bff3d48829845e02eec264fc7a79e Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 1 Oct 2009 15:35:38 -0500 Subject: [PATCH] %test-vector instruction for vany?, vall?, vnone? --- .../cfg/comparisons/comparisons.factor | 3 +++ .../cfg/instructions/instructions.factor | 6 ++++++ .../compiler/cfg/intrinsics/intrinsics.factor | 3 +++ basis/compiler/codegen/codegen.factor | 1 + .../tree/propagation/simd/simd.factor | 6 ++++++ basis/cpu/architecture/architecture.factor | 2 ++ basis/cpu/ppc/ppc.factor | 1 + basis/cpu/x86/x86.factor | 21 +++++++++++++++++++ .../vectors/simd/intrinsics/intrinsics.factor | 6 ++++++ .../specialization/specialization.factor | 3 +++ 10 files changed, 52 insertions(+) diff --git a/basis/compiler/cfg/comparisons/comparisons.factor b/basis/compiler/cfg/comparisons/comparisons.factor index e7c19e7206..d538ee818c 100644 --- a/basis/compiler/cfg/comparisons/comparisons.factor +++ b/basis/compiler/cfg/comparisons/comparisons.factor @@ -9,6 +9,9 @@ SYMBOLS: cc< cc<= cc= cc> cc>= cc<> cc<>= cc/< cc/<= cc/= cc/> cc/>= cc/<> cc/<>= ; +SYMBOLS: + vcc-all vcc-any vcc-none ; + : negate-cc ( cc -- cc' ) H{ { cc< cc/< } diff --git a/basis/compiler/cfg/instructions/instructions.factor b/basis/compiler/cfg/instructions/instructions.factor index 1494348179..09e7736235 100644 --- a/basis/compiler/cfg/instructions/instructions.factor +++ b/basis/compiler/cfg/instructions/instructions.factor @@ -302,6 +302,12 @@ def: dst use: src1 src2 literal: rep cc ; +PURE-INSN: ##test-vector +def: dst/int-rep +use: src +temp: temp/int-rep +literal: rep vcc ; + PURE-INSN: ##add-vector def: dst use: src1 src2 diff --git a/basis/compiler/cfg/intrinsics/intrinsics.factor b/basis/compiler/cfg/intrinsics/intrinsics.factor index 0b565b686c..d8f34b4164 100644 --- a/basis/compiler/cfg/intrinsics/intrinsics.factor +++ b/basis/compiler/cfg/intrinsics/intrinsics.factor @@ -172,6 +172,9 @@ IN: compiler.cfg.intrinsics { math.vectors.simd.intrinsics:(simd-vbitor) [ [ ^^or-vector ] emit-binary-vector-op ] } { math.vectors.simd.intrinsics:(simd-vbitxor) [ [ ^^xor-vector ] emit-binary-vector-op ] } { math.vectors.simd.intrinsics:(simd-v=) [ [ cc= ^^compare-vector ] emit-binary-vector-op ] } + { math.vectors.simd.intrinsics:(simd-vany?) [ [ vcc-any ^^test-vector ] emit-unary-vector-op ] } + { math.vectors.simd.intrinsics:(simd-vall?) [ [ vcc-all ^^test-vector ] emit-unary-vector-op ] } + { math.vectors.simd.intrinsics:(simd-vnone?) [ [ vcc-none ^^test-vector ] emit-unary-vector-op ] } { math.vectors.simd.intrinsics:(simd-vlshift) [ [ ^^shl-vector ] emit-binary-vector-op ] } { math.vectors.simd.intrinsics:(simd-vrshift) [ [ ^^shr-vector ] emit-binary-vector-op ] } { math.vectors.simd.intrinsics:(simd-hlshift) [ [ ^^horizontal-shl-vector ] emit-horizontal-shift ] } diff --git a/basis/compiler/codegen/codegen.factor b/basis/compiler/codegen/codegen.factor index 98d1041772..7c4c593d16 100755 --- a/basis/compiler/codegen/codegen.factor +++ b/basis/compiler/codegen/codegen.factor @@ -167,6 +167,7 @@ CODEGEN: ##gather-vector-2 %gather-vector-2 CODEGEN: ##gather-vector-4 %gather-vector-4 CODEGEN: ##shuffle-vector %shuffle-vector CODEGEN: ##compare-vector %compare-vector +CODEGEN: ##test-vector %test-vector CODEGEN: ##box-vector %box-vector CODEGEN: ##add-vector %add-vector CODEGEN: ##saturated-add-vector %saturated-add-vector diff --git a/basis/compiler/tree/propagation/simd/simd.factor b/basis/compiler/tree/propagation/simd/simd.factor index 35ce810df0..c8be614886 100644 --- a/basis/compiler/tree/propagation/simd/simd.factor +++ b/basis/compiler/tree/propagation/simd/simd.factor @@ -46,6 +46,12 @@ IN: compiler.tree.propagation.simd \ (simd-v.) [ 2nip scalar-output-class ] "outputs" set-word-prop +{ + (simd-vany?) + (simd-vall?) + (simd-vnone?) +} [ { boolean } "default-output-classes" set-word-prop ] each + \ (simd-select) [ 2nip scalar-output-class ] "outputs" set-word-prop \ assert-positive [ diff --git a/basis/cpu/architecture/architecture.factor b/basis/cpu/architecture/architecture.factor index 629579ab1e..ffe77671a7 100644 --- a/basis/cpu/architecture/architecture.factor +++ b/basis/cpu/architecture/architecture.factor @@ -224,6 +224,7 @@ HOOK: %gather-vector-2 cpu ( dst src1 src2 rep -- ) HOOK: %gather-vector-4 cpu ( dst src1 src2 src3 src4 rep -- ) HOOK: %shuffle-vector cpu ( dst src shuffle rep -- ) HOOK: %compare-vector cpu ( dst src1 src2 rep cc -- ) +HOOK: %test-vector cpu ( dst src temp rep vcc -- ) HOOK: %add-vector cpu ( dst src1 src2 rep -- ) HOOK: %saturated-add-vector cpu ( dst src1 src2 rep -- ) HOOK: %add-sub-vector cpu ( dst src1 src2 rep -- ) @@ -258,6 +259,7 @@ HOOK: %gather-vector-2-reps cpu ( -- reps ) HOOK: %gather-vector-4-reps cpu ( -- reps ) HOOK: %shuffle-vector-reps cpu ( -- reps ) HOOK: %compare-vector-reps cpu ( -- reps ) +HOOK: %test-vector-reps cpu ( -- reps ) HOOK: %add-vector-reps cpu ( -- reps ) HOOK: %saturated-add-vector-reps cpu ( -- reps ) HOOK: %add-sub-vector-reps cpu ( -- reps ) diff --git a/basis/cpu/ppc/ppc.factor b/basis/cpu/ppc/ppc.factor index 81064491c1..cfad8259d8 100644 --- a/basis/cpu/ppc/ppc.factor +++ b/basis/cpu/ppc/ppc.factor @@ -268,6 +268,7 @@ M: ppc %gather-vector-2-reps { } ; M: ppc %gather-vector-4-reps { } ; M: ppc %shuffle-vector-reps { } ; M: ppc %compare-vector-reps { } ; +M: ppc %test-vector-reps { } ; M: ppc %add-vector-reps { } ; M: ppc %saturated-add-vector-reps { } ; M: ppc %add-sub-vector-reps { } ; diff --git a/basis/cpu/x86/x86.factor b/basis/cpu/x86/x86.factor index 85fed02429..877afaa390 100644 --- a/basis/cpu/x86/x86.factor +++ b/basis/cpu/x86/x86.factor @@ -747,6 +747,27 @@ M: x86 %compare-vector-reps { sse4.1? { longlong-2-rep ulonglong-2-rep } } } available-reps ; +:: (%test-vector) ( dst temp mask vcc -- ) + vcc { + { vcc-any [ dst dst TEST dst temp \ CMOVNE %boolean ] } + { vcc-none [ dst dst TEST dst temp \ CMOVE %boolean ] } + { vcc-all [ dst mask CMP dst temp \ CMOVE %boolean ] } + } case ; + +M:: x86 %test-vector ( dst src temp rep vcc -- ) + dst src rep { + { double-2-rep [ MOVMSKPD HEX: 3 ] } + { float-4-rep [ MOVMSKPS HEX: f ] } + [ drop PMOVMSKB HEX: ffff ] + } case :> mask + dst temp mask vcc (%test-vector) ; + +M: x86 %test-vector-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 %add-vector ( dst src1 src2 rep -- ) [ two-operand ] keep { diff --git a/basis/math/vectors/simd/intrinsics/intrinsics.factor b/basis/math/vectors/simd/intrinsics/intrinsics.factor index b5cb9cf634..cbdbade222 100644 --- a/basis/math/vectors/simd/intrinsics/intrinsics.factor +++ b/basis/math/vectors/simd/intrinsics/intrinsics.factor @@ -50,6 +50,9 @@ SIMD-OP: hlshift SIMD-OP: hrshift SIMD-OP: vshuffle SIMD-OP: v= +SIMD-OP: vany? +SIMD-OP: vall? +SIMD-OP: vnone? : (simd-with) ( x rep -- v ) bad-simd-call ; : (simd-gather-2) ( a b rep -- v ) bad-simd-call ; @@ -130,4 +133,7 @@ M: vector-rep supported-simd-op? { \ (simd-v=) [ %compare-vector-reps ] } { \ (simd-gather-2) [ %gather-vector-2-reps ] } { \ (simd-gather-4) [ %gather-vector-4-reps ] } + { \ (simd-vany?) [ %test-vector-reps ] } + { \ (simd-vall?) [ %test-vector-reps ] } + { \ (simd-vnone?) [ %test-vector-reps ] } } case member? ; diff --git a/basis/math/vectors/specialization/specialization.factor b/basis/math/vectors/specialization/specialization.factor index e1a4c00153..ffb148f55d 100644 --- a/basis/math/vectors/specialization/specialization.factor +++ b/basis/math/vectors/specialization/specialization.factor @@ -93,6 +93,9 @@ H{ { vshuffle { +vector+ +literal+ -> +vector+ } } { vbroadcast { +vector+ +literal+ -> +vector+ } } { v= { +vector+ +vector+ -> +vector+ } } + { vany? { +vector+ -> +scalar+ } } + { vall? { +vector+ -> +scalar+ } } + { vnone? { +vector+ -> +scalar+ } } } PREDICATE: vector-word < word vector-words key? ;