diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index dc45b012f3..3ca88c2bcf 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -51,7 +51,6 @@ - remove dead code after a 'throw' - when doing comparison with one arg being a float, inline method - investigate overzealous math inlining -- literals on either side of a shuffle can be more efficient - shuffles: eliminate dead loads - floating point intrinsics - flushing optimization diff --git a/library/inference/shuffle.factor b/library/inference/shuffle.factor index b578b9d0c1..0f66f5452a 100644 --- a/library/inference/shuffle.factor +++ b/library/inference/shuffle.factor @@ -1,5 +1,5 @@ IN: inference -USING: kernel math namespaces sequences ; +USING: hashtables kernel math namespaces sequences ; TUPLE: shuffle in-d in-r out-d out-r ; @@ -11,7 +11,7 @@ TUPLE: shuffle in-d in-r out-d out-r ; tuck shuffle-in-r [ set ] 2each shuffle-in-d [ set ] 2each ; : shuffled-values ( values -- values ) - [ dup literal? [ get ] unless ] map ; + [ [ namespace hash dup ] keep ? ] map ; : store-shuffle ( shuffle -- d r ) dup shuffle-out-d shuffled-values diff --git a/library/test/compiler/optimizer.factor b/library/test/compiler/optimizer.factor index 91bb1780fe..49dcd55634 100644 --- a/library/test/compiler/optimizer.factor +++ b/library/test/compiler/optimizer.factor @@ -3,20 +3,36 @@ USING: assembler compiler compiler-backend generic inference kernel kernel-internals lists math prettyprint sequences strings test vectors words ; -! Some dataflow tests -! [ 3 ] [ 1 2 3 (subst-value) ] unit-test -! [ 1 ] [ 1 2 2 (subst-value) ] unit-test -! -! [ { "one" "one" "three" "three" } ] -! [ -! { "one" "two" "three" } { 1 2 3 } { 1 1 3 3 } -! clone [ (subst-values) ] keep -! ] unit-test -! -! [ << meet f { "one" 2 3 } >> ] -! [ "one" 1 << meet f { 1 2 3 } >> clone (subst-value) ] unit-test +: kill-1 + [ 1 2 3 ] [ + ] over drop drop ; compiled + +[ [ 1 2 3 ] ] [ kill-1 ] unit-test + +: kill-2 + [ + ] [ 1 2 3 ] over drop nip ; compiled + +[ [ 1 2 3 ] ] [ kill-2 ] unit-test + +: kill-3 + [ + ] dup over 3drop ; + +[ ] [ kill-3 ] unit-test + +: kill-4 + [ 1 2 3 ] [ + ] [ - ] pick >r 2drop r> ; compiled + +[ [ 1 2 3 ] [ 1 2 3 ] ] [ kill-4 ] unit-test + +: kill-5 + [ + ] [ - ] [ 1 2 3 ] pick pick 2drop >r 2drop r> ; compiled + +[ [ 1 2 3 ] ] [ kill-5 ] unit-test + +: kill-6 + [ 1 2 3 ] [ 4 5 6 ] [ + ] pick >r drop r> ; compiled + +[ [ 1 2 3 ] [ 4 5 6 ] [ 1 2 3 ] ] [ kill-6 ] unit-test -! Literal kill tests : kill-set* dataflow kill-set [ literal-value ] map ; diff --git a/library/test/compiler/stack.factor b/library/test/compiler/stack.factor index b253461405..463515b022 100644 --- a/library/test/compiler/stack.factor +++ b/library/test/compiler/stack.factor @@ -1,10 +1,5 @@ IN: temporary -USE: compiler -USE: test -USE: words -USE: lists -USE: math -USE: kernel +USING: compiler kernel math-internals test ; ! Test shuffle intrinsics [ ] [ 1 [ drop ] compile-1 ] unit-test @@ -24,34 +19,5 @@ USE: kernel [ 1 2 3 1 ] [ 1 2 3 [ pick ] compile-1 ] unit-test [ 2 1 ] [ 1 2 [ swap ] compile-1 ] unit-test -! Test various kill combinations - -: kill-1 - [ 1 2 3 ] [ + ] over drop drop ; compiled - -[ [ 1 2 3 ] ] [ kill-1 ] unit-test - -: kill-2 - [ + ] [ 1 2 3 ] over drop nip ; compiled - -[ [ 1 2 3 ] ] [ kill-2 ] unit-test - -: kill-3 - [ + ] dup over 3drop ; - -[ ] [ kill-3 ] unit-test - -: kill-4 - [ 1 2 3 ] [ + ] [ - ] pick >r 2drop r> ; compiled - -[ [ 1 2 3 ] [ 1 2 3 ] ] [ kill-4 ] unit-test - -: kill-5 - [ + ] [ - ] [ 1 2 3 ] pick pick 2drop >r 2drop r> ; compiled - -[ [ 1 2 3 ] ] [ kill-5 ] unit-test - -: kill-6 - [ 1 2 3 ] [ 4 5 6 ] [ + ] pick >r drop r> ; compiled - -[ [ 1 2 3 ] [ 4 5 6 ] [ 1 2 3 ] ] [ kill-6 ] unit-test +! Test literals in either side of a shuffle +[ 4 1 ] [ 1 [ [ 3 fixnum+ ] keep ] compile-1 ] unit-test