]> gitweb.factorcode.org Git - factor.git/commitdiff
removed fixnum<< vop since it was buggy and afforded no performance gain, and also...
authorSlava Pestov <slava@factorcode.org>
Sun, 22 Jan 2006 21:40:18 +0000 (21:40 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 22 Jan 2006 21:40:18 +0000 (21:40 +0000)
18 files changed:
library/collections/namespaces.factor
library/compiler/intrinsics.factor
library/compiler/ppc/fixnum.factor
library/compiler/stack.factor
library/compiler/vops.factor
library/compiler/x86/fixnum.factor
library/inference/branches.factor
library/inference/call-optimizers.factor
library/inference/class-infer.factor
library/inference/dataflow.factor
library/inference/inference.factor
library/inference/kill-literals.factor
library/inference/known-words.factor
library/inference/optimizer.factor
library/inference/print-dataflow.factor
library/inference/words.factor
library/test/compiler/optimizer.factor
library/tools/annotations.factor

index c6f5ecb9fbe4fa9dcc0dad2249e12fa5288ccead..3997289df61d5cb4188cd1199d52435867d0758a 100644 (file)
@@ -23,15 +23,16 @@ sequences strings vectors words ;
 : change ( var quot -- quot: old -- new )
     >r dup get r> rot slip set ; inline
 
-: inc ( var -- ) [ 1+ ] change ; inline
+: +@ ( n var -- ) [ [ 0 ] unless* + ] change ;
 
-: counter ( var -- n )
-    global [ [ [ 0 ] unless* dup 1+ >fixnum ] change ] bind ;
+: inc ( var -- ) 1 swap +@ ; inline
 
-: dec ( var -- ) [ 1- ] change ; inline
+: dec ( var -- ) -1 swap +@ ; inline
 
 : bind ( namespace quot -- ) swap >n call n> drop ; inline
 
+: counter ( var -- n ) global [ dup inc get ] bind ;
+
 : make-hash ( quot -- hash ) H{ } clone >n call n> ; inline
 
 : with-scope ( quot -- ) make-hash drop ; inline
index 6225d319e9a111a8950b1faba477676df5ffff2c..d896923674c591789f48cdc73404761f8999127e 100644 (file)
@@ -22,8 +22,8 @@ namespaces sequences words ;
 
 : slot@ ( node -- n/f )
     #! Compute slot offset.
-    dup node-in-d reverse-slice dup first dup literal? [
-        literal-value cells swap second
+    dup node-in-d reverse-slice dup first dup value? [
+        value-literal cells swap second
         rot value-tag dup [ - ] [ 2drop f ] if
     ] [
         3drop f
@@ -90,7 +90,7 @@ namespaces sequences words ;
 
 \ getenv [
     -1 %inc-d ,
-    node-peek literal-value 0 <vreg> swap %getenv ,
+    node-peek value-literal 0 <vreg> swap %getenv ,
     1 %inc-d ,
     out-1
 ] "intrinsic" set-word-prop
@@ -98,7 +98,7 @@ namespaces sequences words ;
 \ setenv [
     -1 %inc-d ,
     in-1
-    node-peek literal-value 0 <vreg> swap %setenv ,
+    node-peek value-literal 0 <vreg> swap %setenv ,
     -1 %inc-d ,
 ] "intrinsic" set-word-prop
 
@@ -118,13 +118,13 @@ namespaces sequences words ;
     >r binary-inputs dup -1 %inc-d , r> execute , out-1 ; inline
 
 : binary-imm ( node -- in1 in2 )
-    -1 %inc-d , in-1 node-peek literal-value 0 <vreg> ;
+    -1 %inc-d , in-1 node-peek value-literal 0 <vreg> ;
 
 : binary-op-imm ( node op -- )
     >r binary-imm dup r> execute , out-1 ; inline
 
 : literal-immediate? ( value -- ? )
-    dup literal? [ literal-value immediate? ] [ drop f ] if ;
+    dup value? [ value-literal immediate? ] [ drop f ] if ;
 
 : binary-op-imm? ( node -- ? )
     fixnum-imm? >r node-peek literal-immediate? r> and ;
@@ -197,25 +197,8 @@ namespaces sequences words ;
     out-1
 ] "intrinsic" set-word-prop
 
-: fast-fixnum* ( n -- )
-    -1 %inc-d ,
-    in-1
-    log2 0 <vreg> 0 <vreg> %fixnum<< ,
-    out-1 ;
-
-: slow-fixnum* ( node -- ) \ %fixnum* binary-op-reg ;
-
 \ fixnum* [
-    ! Turn multiplication by a power of two into a left shift.
-    dup node-peek dup literal-immediate? [
-        literal-value dup power-of-2? [
-            nip fast-fixnum*
-        ] [
-            drop slow-fixnum*
-        ] if
-    ] [
-        drop slow-fixnum*
-    ] if
+    \ %fixnum* binary-op-reg
 ] "intrinsic" set-word-prop
 
 : slow-shift ( -- ) \ fixnum-shift %call , ;
@@ -231,16 +214,6 @@ namespaces sequences words ;
         out-1
     ] if ;
 
-: positive-shift ( n -- )
-    dup cell-bits tag-bits - <= [
-        -1 %inc-d ,
-        in-1
-        0 <vreg> 0 <vreg> %fixnum<< ,
-        out-1
-    ] [
-        drop slow-shift
-    ] if ;
-
 : fast-shift ( n -- )
     dup 0 = [
         -1 %inc-d ,
@@ -249,13 +222,13 @@ namespaces sequences words ;
         dup 0 < [
             negative-shift
         ] [
-            positive-shift
+            drop slow-shift
         ] if
     ] if ;
 
 \ fixnum-shift [
-    node-peek dup literal? [
-        literal-value fast-shift
+    node-peek dup value? [
+        value-literal fast-shift
     ] [
         drop slow-shift
     ] if
index dee016ed7dc729b12b8352da1f0c544256cb6eed..0aeadb66baccc7df198679c92b21c5c35e21ea3d 100644 (file)
@@ -111,31 +111,6 @@ M: %fixnum-bitnot generate-node ( vop -- )
     drop dest/src NOT
     0 output-operand dup untag ;
 
-M: %fixnum<< generate-node ( vop -- )
-    ! This has specific register requirements.
-    drop
-    <label> "no-overflow" set
-    <label> "end" set
-    ! check for potential overflow
-    0 input shift-add dup 1 scratch LOAD
-    0 scratch 1 input-operand 1 scratch ADD
-    2 * 1- 1 scratch LOAD
-    1 scratch 0 0 scratch CMPL
-    ! is there going to be an overflow?
-    "no-overflow" get BGE
-    ! there is going to be an overflow, make a bignum
-    1 input-operand dup untag-fixnum
-    "s48_long_to_bignum" f compile-c-call
-    0 input 0 scratch LI
-    "s48_bignum_arithmetic_shift" f compile-c-call
-    ! tag the result
-    1 input-operand dup bignum-tag ORI
-    "end" get B
-    ! there is not going to be an overflow
-    "no-overflow" get save-xt
-    1 input-operand dup 0 input SLWI.
-    "end" get save-xt ;
-
 M: %fixnum>> generate-node ( vop -- )
     drop
     1 input-operand 0 output-operand 0 input SRAWI
index f9690a2e6be63c3d06669a7d955c1ab3cb0ea4d1..82fddad1d26cd951809ef37b001210dbb9ae9665 100644 (file)
@@ -18,15 +18,15 @@ M: object load-value ( vreg n value -- )
 : load-literal ( vreg obj -- )
     dup immediate? [ %immediate ] [ %indirect ] if , ;
 
-M: literal load-value ( vreg n value -- )
-    nip literal-value load-literal ;
+M: value load-value ( vreg n value -- )
+    nip value-literal load-literal ;
 
 SYMBOL: vreg-allocator
 SYMBOL: live-d
 SYMBOL: live-r
 
 : value-dropped? ( value -- ? )
-    dup literal?
+    dup value?
     over live-d get member? not
     rot live-r get member? not and
     or ;
@@ -50,7 +50,7 @@ SYMBOL: live-r
     dup node-out-r length swap node-in-r length - %inc-r , ;
 
 : literal>stack ( stack-pos value storer -- )
-    >r literal-value r> fixnum-imm? pick immediate? and [
+    >r value-literal r> fixnum-imm? pick immediate? and [
         >r 0 swap load-literal 0 <vreg> r>
     ] unless swapd execute , ; inline
 
@@ -59,7 +59,7 @@ SYMBOL: live-r
 : vreg>stack ( stack-pos value storer -- )
     {
         { [ over not ] [ 3drop ] }
-        { [ over literal? ] [ literal>stack ] }
+        { [ over value? ] [ literal>stack ] }
         { [ t ] [ computed>stack ] }
     } cond ; inline
 
@@ -71,8 +71,8 @@ SYMBOL: live-r
     \ %replace-r (vregs>stack) \ %replace-d (vregs>stack) ;
 
 : literals/computed ( stack -- literals computed )
-    dup [ dup literal? [ drop f ] unless ] map
-    swap [ dup literal? [ drop f ] when ] map ;
+    dup [ dup value? [ drop f ] unless ] map
+    swap [ dup value? [ drop f ] when ] map ;
 
 : vregs>stacks ( -- )
     live-d get literals/computed
index c66a9f7f1e7ba140662c775c22979fd4b1f716c8..baf4a06202e093fc356b0cb4f20cfb9153baa47c 100644 (file)
@@ -281,17 +281,13 @@ TUPLE: %fixnum-bitnot ;
 C: %fixnum-bitnot make-vop ; : %fixnum-bitnot 2-vop <%fixnum-bitnot> ;
 M: %fixnum-bitnot basic-block? drop t ;
 
-! At the VOP level, the 'shift' operation is split into five
+! At the VOP level, the 'shift' operation is split into four
 ! distinct operations:
-! - shifts with a large positive count: calls runtime to make
+! - shifts with a positive count: calls runtime to make
 !   a bignum
-! - shifts with a small positive count: %fixnum<<
 ! - shifts with a small negative count: %fixnum>>
 ! - shifts with a small negative count: %fixnum>>
 ! - shifts with a large negative count: %fixnum-sgn
-TUPLE: %fixnum<< ;
-C: %fixnum<< make-vop ;   : %fixnum<<   3-vop <%fixnum<<> ;
-
 TUPLE: %fixnum>> ;
 C: %fixnum>> make-vop ;   : %fixnum>>   3-vop <%fixnum>>> ;
 M: %fixnum>> basic-block? drop t ;
index f2927bf6811bfbea023f959f69b36314e0918809..5a617aa58044f0babe3cd8c0199da1662f9a0a4d 100644 (file)
@@ -103,31 +103,6 @@ M: %fixnum-bitnot generate-node ( vop -- )
     ! Mask off the low 3 bits to give a fixnum tag
     0 output-operand tag-mask XOR ;
 
-M: %fixnum<< generate-node
-    #! This has specific register requirements.
-    drop
-    <label> "no-overflow" set
-    <label> "end" set
-    ! make a copy
-    0 scratch 1 input-operand MOV
-    ! check for potential overflow
-    0 scratch 0 input shift-add 2dup ADD 2 * 1- CMP
-    ! is there going to be an overflow?
-    "no-overflow" get JBE
-    ! there is going to be an overflow, make a bignum
-    1 input-operand tag-bits SAR
-    "s48_long_to_bignum" f
-    1 input-operand 1array compile-c-call*
-    "s48_bignum_arithmetic_shift" f
-    1 input-operand 0 input 2array compile-c-call*
-    ! tag the result
-    1 input-operand bignum-tag OR
-    "end" get JMP
-    ! there is not going to be an overflow
-    "no-overflow" get save-xt
-    1 input-operand 0 input SHL
-    "end" get save-xt ;
-
 M: %fixnum>> generate-node
     drop
     ! shift register
index 744f598c04e42a7ae10bf948342206e2fbcaff14..94535a898d2d23de79e8384d294a42ab5f4684fe 100644 (file)
@@ -12,7 +12,7 @@ namespaces parser prettyprint sequences strings vectors words ;
 : unify-values ( seq -- value )
     #! If all values in list are equal, return the value.
     #! Otherwise, unify.
-    dup all-eq? [ first ] [ drop <value> ] if ;
+    dup all-eq? [ first ] [ drop <computed> ] if ;
 
 : unify-stacks ( seq -- stack )
     #! Replace differing literals in stacks with unknown
@@ -81,7 +81,7 @@ namespaces parser prettyprint sequences strings vectors words ;
             base-case-continuation set
             copy-inference
             dup value-recursion recursive-state set
-            dup literal-value infer-quot
+            dup value-literal infer-quot
             terminated? get [ #values node, ] unless
             f
         ] callcc1 [ terminate ] when drop
index a5f29cc038a698d5c62e3dd07de04136c7325aba..fd2a784c938fdb32fc9ba8cfb5ead4b975d323f7 100644 (file)
@@ -18,7 +18,7 @@ math math-internals sequences words ;
 : partial-eval? ( #call -- ? )
     dup node-param "foldable" word-prop [
         dup node-in-d [
-            dup literal?
+            dup value?
             [ 2drop t ] [ swap node-literals ?hash* nip ] if
         ] all-with?
     ] [
@@ -27,8 +27,8 @@ math math-internals sequences words ;
 
 : literal-in-d ( #call -- inputs )
     dup node-in-d [
-        dup literal?
-        [ nip literal-value ] [ swap node-literals ?hash ] if
+        dup value?
+        [ nip value-literal ] [ swap node-literals ?hash ] if
     ] map-with ;
 
 : partial-eval ( #call -- node )
@@ -70,7 +70,7 @@ SYMBOL: @
 
 : literals-match? ( values template -- ? )
     [
-        over literal? [ >r literal-value r> ] [ nip @ ] if =
+        over value? [ >r value-literal r> ] [ nip @ ] if =
     ] 2map [ ] all? ;
 
 : values-match? ( values template -- ? )
index 8c17980a03ff40b9b408bae1c8d6f5d51f79f1d8..fa561e8af695a75c5c18e6f1a6b6dfcf3e44715e 100644 (file)
@@ -23,24 +23,24 @@ M: f apply-tie ( f -- ) drop ;
 
 TUPLE: class-tie value class ;
 
-: set-value-class ( class value -- )
+: annotate-value-class ( class value -- )
     2dup swap <class-tie> ties get hash [ apply-tie ] when*
     value-classes get set-hash ;
 
 M: class-tie apply-tie ( tie -- )
     dup class-tie-class swap class-tie-value
-    set-value-class ;
+    annotate-value-class ;
 
 TUPLE: literal-tie value literal ;
 
-: set-value-literal ( literal value -- )
-    over class over set-value-class
+: annotate-value-literal ( literal value -- )
+    over class over annotate-value-class
     2dup swap <literal-tie> ties get hash [ apply-tie ] when*
     value-literals get set-hash ;
 
 M: literal-tie apply-tie ( tie -- )
     dup literal-tie-literal swap literal-tie-value
-    set-value-literal ;
+    annotate-value-literal ;
 
 GENERIC: infer-classes* ( node -- )
 
@@ -65,7 +65,9 @@ M: node child-ties ( node -- seq )
     [ dup value-class ] map>hash swap set-node-classes ;
 
 : intersect-classes ( classes values -- )
-    [ [ value-class class-and ] keep set-value-class ] 2each ;
+    [
+        [ value-class class-and ] keep annotate-value-class
+    ] 2each ;
 
 : type/tag-ties ( node n -- )
     over node-out-d first over [ <literal-tie> ] map-with
@@ -77,8 +79,8 @@ M: node child-ties ( node -- seq )
 \ tag [ num-tags type/tag-ties ] "create-ties" set-word-prop
 
 \ eq? [
-    dup node-in-d second literal? [
-        dup node-in-d first2 literal-value <literal-tie>
+    dup node-in-d second value? [
+        dup node-in-d first2 value-literal <literal-tie>
         over node-out-d first general-t <class-tie>
         ties get set-hash
     ] when drop
@@ -100,7 +102,7 @@ M: node child-ties ( node -- seq )
     ] if ;
 
 \ make-tuple [
-    dup node-in-d first literal-value 1array
+    dup node-in-d first value-literal 1array
 ] "output-classes" set-word-prop
 
 : output-classes ( node -- seq )
@@ -119,8 +121,8 @@ M: #call infer-classes* ( node -- )
     ] when drop ;
 
 M: #shuffle infer-classes* ( node -- )
-    node-out-d [ literal? ] subset
-    [ [ literal-value ] keep set-value-literal ] each ;
+    node-out-d [ value? ] subset
+    [ [ value-literal ] keep annotate-value-literal ] each ;
 
 M: #if child-ties ( node -- seq )
     node-in-d first dup general-t <class-tie>
index 6790175332057493aedfdf5561d7f1d2246a6ede..d27db1d11d5d607175b3bfa156b5c518d3065a6f 100644 (file)
@@ -7,23 +7,22 @@ namespaces parser sequences words ;
 ! Recursive state. An alist, mapping words to labels.
 SYMBOL: recursive-state
 
-TUPLE: value recursion uid ;
+: <computed> \ <computed> counter ;
 
-C: value ( -- value )
-    \ value counter over set-value-uid
-    recursive-state get over set-value-recursion ;
+TUPLE: value uid literal recursion ;
 
-M: value = eq? ;
+C: value ( obj -- value )
+    <computed> over set-value-uid
+    recursive-state get over set-value-recursion
+    [ set-value-literal ] keep ;
 
 M: value hashcode value-uid ;
 
-TUPLE: literal value ;
+M: value = eq? ;
 
-C: literal ( obj -- value )
-    <value> over set-delegate
-    [ set-literal-value ] keep ;
+M: integer value-uid ;
 
-M: literal hashcode delegate hashcode ;
+M: integer value-recursion drop f ;
 
 ! The dataflow IR is the first of the two intermediate
 ! representations used by Factor. It annotates concatenative
index 808265bb9ec8bdd4578f06288f3a2c41d151fa3f..5f222a7a3d854c2d56b970c6386c1204cd657b2e 100644 (file)
@@ -24,7 +24,7 @@ M: inference-error error. ( error -- )
     "Recursive state:" print
     inference-error-rstate describe ;
 
-M: value literal-value ( value -- )
+M: integer value-literal ( value -- )
     {
         "A literal value was expected where a computed value was found.\n"
         "This means the word you are inferring applies 'call' or 'execute'\n"
@@ -43,9 +43,10 @@ M: value literal-value ( value -- )
 SYMBOL: d-in
 
 : pop-literal ( -- rstate obj )
-    1 #drop node, pop-d dup value-recursion swap literal-value ;
+    1 #drop node,
+    pop-d dup value-recursion swap value-literal ;
 
-: value-vector ( n -- vector ) [ drop <value> ] map >vector ;
+: value-vector ( n -- vector ) [ drop <computed> ] map >vector ;
 
 : required-inputs ( n stack -- n ) length - 0 max ;
 
@@ -77,7 +78,7 @@ GENERIC: apply-object
 : apply-literal ( obj -- )
     #! Literals are annotated with the current recursive
     #! state.
-    <literal> push-d  1 #push node, ;
+    <value> push-d  1 #push node, ;
 
 M: object apply-object apply-literal ;
 
index f68d6efc7abc23f7df649a10fc0e173bd51504d4..a3ffe4b188dae792788f9a93a4d1857370742912 100644 (file)
@@ -53,7 +53,7 @@ M: node returns* ( node -- seq ) node-successor returns* ;
 ! #shuffle
 M: #shuffle literals* ( node -- seq )
     dup node-out-d swap node-out-r
-    [ [ literal? ] subset ] 2apply append ;
+    [ [ value? ] subset ] 2apply append ;
 
 ! #return
 M: #return returns* , ;
index 558b1e30269790cade81c169dd73d1827a77ac26..dc582cc43b8af709634fc8db593857c1277d8741 100644 (file)
@@ -66,7 +66,7 @@ sequences strings vectors words prettyprint ;
 \ dispatch [ [ fixnum array ] [ ] ] "infer-effect" set-word-prop
 
 \ dispatch [
-    pop-literal nip [ <literal> ] map
+    pop-literal nip [ <value> ] map
     #dispatch pop-d drop infer-branches
 ] "infer" set-word-prop
 
index ea13497fab340bad3fa815897fda739203f38db5..e4d0875fe3dc2c4faebf30a9739d0a4f788616fd 100644 (file)
@@ -73,7 +73,7 @@ M: #shuffle optimize-node*  ( node -- node/t )
 
 ! #if
 : static-branch? ( node -- lit ? )
-    node-in-d first dup literal? ;
+    node-in-d first dup value? ;
 
 : static-branch ( conditional n -- node )
     over drop-inputs
@@ -81,7 +81,7 @@ M: #shuffle optimize-node*  ( node -- node/t )
 
 M: #if optimize-node* ( node -- node )
     dup static-branch?
-    [ literal-value 0 1 ? static-branch ] [ 2drop t ] if ;
+    [ value-literal 0 1 ? static-branch ] [ 2drop t ] if ;
 
 ! #values
 : optimize-fold ( node -- node/t )
index 9f381c84113b7d3ed0855639af7156c7fcb801b1..7e683e8ae81ae6571e5b7e01d986a87c19244504 100644 (file)
@@ -19,10 +19,10 @@ M: comment pprint* ( ann -- )
 : values% ( prefix values -- )
     [
         swap %
-        dup literal? [
-            literal-value unparse %
+        dup value? [
+            value-literal unparse %
         ] [
-            "@" % value-uid #
+            "@" % #
         ] if
     ] each-with ;
 
index 67fb2b5064fe628e248db659a039db09c84accc5..b1af1156e99a09f60e3772e20384874a92b4da23 100644 (file)
@@ -10,7 +10,7 @@ strings vectors words ;
     over 0 rot node-inputs [ pop-d 2drop ] each ;
 
 : produce-values ( n node -- )
-    over [ drop <value> push-d ] each 0 swap node-outputs ;
+    over [ drop <computed> push-d ] each 0 swap node-outputs ;
 
 : consume/produce ( word effect -- )
     #! Add a node to the dataflow graph that consumes and
index 5671f71165b18c783e8e071f77162154a01bf774..18f7c7eaad0c0bb06c73bbaaeb6102e60f2fa2e7 100644 (file)
@@ -40,7 +40,7 @@ IN: temporary
 
 : kill-set=
     dataflow dup split-node
-    kill-set hash-keys [ literal-value ] map set= ;
+    kill-set hash-keys [ value-literal ] map set= ;
 
 : foo 1 2 3 ;
 
@@ -106,7 +106,7 @@ IN: temporary
 
 [ t ] [
     [ [ ] swap literal-kill-test-8 ] dataflow
-    dup split-node live-values hash-values [ literal? ] subset empty?
+    dup split-node live-values hash-values [ value? ] subset empty?
 ] unit-test
 
 ! Test method inlining
index e93445096c03a399b7437c5bca6e74d487c99c84..df3492d804f806108c9d3ec044881505a4c9b9b3 100644 (file)
@@ -30,8 +30,6 @@ sequences strings walker ;
     #! Cause the word to start the code walker when executed.
     [ nip [ walk ] cons ] annotate ;
 
-: +@ ( n var -- ) dup get [ swap >r + r> ] when* set ;
-
 : with-profile ( quot word -- )
     millis >r >r call r> millis r> - swap global [ +@ ] bind ;
     inline