From ea051063a48427c70d6ba36d1588393cbcd79ec5 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 7 Oct 2009 12:35:21 -0500 Subject: [PATCH 1/2] convert all-ones vector ##load-reference/##load-constant to a ##fill-vector insn --- .../representations/representations.factor | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/basis/compiler/cfg/representations/representations.factor b/basis/compiler/cfg/representations/representations.factor index a2311ca964..2ff293ce5c 100644 --- a/basis/compiler/cfg/representations/representations.factor +++ b/basis/compiler/cfg/representations/representations.factor @@ -226,24 +226,40 @@ SYMBOL: phi-mappings M: ##phi conversions-for-insn [ , ] [ [ inputs>> values ] [ dst>> ] bi phi-mappings get set-at ] bi ; -! When a literal zero vector is unboxed, we replace the ##load-reference -! with a ##zero-vector instruction since this is more efficient. +! When a literal zeroes/ones vector is unboxed, we replace the ##load-reference +! with a ##zero-vector or ##fill-vector instruction since this is more efficient. : convert-to-zero-vector? ( insn -- ? ) { [ dst>> rep-of vector-rep? ] - [ obj>> B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } = ] + [ obj>> B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } = ] + } 1&& ; +: convert-to-fill-vector? ( insn -- ? ) + { + [ dst>> rep-of vector-rep? ] + [ obj>> B{ 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 } = ] } 1&& ; -: convert-to-zero-vector ( insn -- ) - dst>> dup rep-of ##zero-vector ; +: (convert-to-zero/fill-vector) ( insn -- dst rep ) + dst>> dup rep-of ; inline + +: conversions-for-load-insn ( insn -- ?insn ) + { + { + [ dup convert-to-zero-vector? ] + [ (convert-to-zero/fill-vector) ##zero-vector f ] + } + { + [ dup convert-to-fill-vector? ] + [ (convert-to-zero/fill-vector) ##fill-vector f ] + } + [ ] + } cond ; M: ##load-reference conversions-for-insn - dup convert-to-zero-vector? - [ convert-to-zero-vector ] [ call-next-method ] if ; + conversions-for-load-insn [ call-next-method ] when* ; M: ##load-constant conversions-for-insn - dup convert-to-zero-vector? - [ convert-to-zero-vector ] [ call-next-method ] if ; + conversions-for-load-insn [ call-next-method ] when* ; M: vreg-insn conversions-for-insn [ compute-renaming-set ] [ perform-renaming ] bi ; @@ -312,4 +328,4 @@ PRIVATE> [ insert-conversions ] [ ] } cleave - representations get cfg get (>>reps) ; \ No newline at end of file + representations get cfg get (>>reps) ; From 47cfb7d3a57dd308dd3f475e327242c7e8375913 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 7 Oct 2009 12:46:08 -0500 Subject: [PATCH 2/2] fix ##load-constant/##scalar>vector folding when constant is a fixnum --- .../cfg/value-numbering/rewrite/rewrite.factor | 2 +- .../value-numbering/value-numbering-tests.factor | 16 +++++++++++++++- basis/math/vectors/simd/simd-tests.factor | 2 ++ core/layouts/layouts.factor | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/basis/compiler/cfg/value-numbering/rewrite/rewrite.factor b/basis/compiler/cfg/value-numbering/rewrite/rewrite.factor index 9827e02bf5..56ec16eed6 100755 --- a/basis/compiler/cfg/value-numbering/rewrite/rewrite.factor +++ b/basis/compiler/cfg/value-numbering/rewrite/rewrite.factor @@ -459,7 +459,7 @@ M: ##shuffle-vector rewrite value>> over rep>> { { float-4-rep [ float>bits 4 >le (fold-scalar>vector) ] } { double-2-rep [ double>bits 8 >le (fold-scalar>vector) ] } - [ rep-component-type heap-size >le (fold-scalar>vector) ] + [ [ untag-fixnum ] dip rep-component-type heap-size >le (fold-scalar>vector) ] } case ; M: ##scalar>vector rewrite diff --git a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor index b959a09e19..5f8eda2c08 100644 --- a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor +++ b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor @@ -4,7 +4,7 @@ cpu.architecture tools.test kernel math combinators.short-circuit accessors sequences compiler.cfg.predecessors locals compiler.cfg.dce compiler.cfg.ssa.destruction compiler.cfg.loop-detection compiler.cfg.representations compiler.cfg assocs vectors arrays -layouts namespaces alien ; +layouts literals namespaces alien ; IN: compiler.cfg.value-numbering.tests : trim-temps ( insns -- insns ) @@ -1215,6 +1215,20 @@ cell 8 = [ } value-numbering-step ] unit-test +[ + { + T{ ##load-constant f 0 $[ 55 tag-fixnum ] } + T{ ##load-constant f 1 B{ 55 0 0 0 55 0 0 0 55 0 0 0 55 0 0 0 } } + T{ ##copy f 2 1 any-rep } + } +] [ + { + T{ ##load-constant f 0 $[ 55 tag-fixnum ] } + T{ ##scalar>vector f 1 0 int-4-rep } + T{ ##shuffle-vector f 2 1 { 0 0 0 0 } float-4-rep } + } value-numbering-step +] unit-test + [ { T{ ##load-constant f 0 1.25 } diff --git a/basis/math/vectors/simd/simd-tests.factor b/basis/math/vectors/simd/simd-tests.factor index a66265e488..78c9389591 100644 --- a/basis/math/vectors/simd/simd-tests.factor +++ b/basis/math/vectors/simd/simd-tests.factor @@ -129,6 +129,8 @@ CONSTANT: simd-classes [ HEX: ffffffff ] [ HEX: ffffffff [ uint-4-with ] compile-call first ] unit-test +[ HEX: ffffffff ] [ [ HEX: ffffffff uint-4-with ] compile-call first ] unit-test + "== Checking -boa constructors" print [ { } ] [ diff --git a/core/layouts/layouts.factor b/core/layouts/layouts.factor index 4aa806c81f..be6276a684 100644 --- a/core/layouts/layouts.factor +++ b/core/layouts/layouts.factor @@ -27,6 +27,9 @@ SYMBOL: mega-cache-size : tag-fixnum ( n -- tagged ) tag-bits get shift ; +: untag-fixnum ( n -- tagged ) + tag-bits get neg shift ; + ! We do this in its own compilation unit so that they can be ! folded below <<