]> gitweb.factorcode.org Git - factor.git/commitdiff
Working on float intrinsics
authorslava <slava@factorcode.org>
Sat, 6 May 2006 00:06:57 +0000 (00:06 +0000)
committerslava <slava@factorcode.org>
Sat, 6 May 2006 00:06:57 +0000 (00:06 +0000)
14 files changed:
TODO.FACTOR.txt
library/bootstrap/boot-stage1.factor
library/bootstrap/image.factor
library/compiler/generator/architecture.factor
library/compiler/generator/generator.factor
library/compiler/generator/templates.factor
library/compiler/x86/architecture.factor
library/compiler/x86/assembler.factor
library/compiler/x86/intrinsics-sse2.factor
library/kernel.factor
library/math/float.factor
library/test/compiler/float.factor [new file with mode: 0644]
library/test/test.factor
native/gc.h

index d7acafcbb43d7b10f3b1b5338358d3cfe446967e..c2a6d560136ead66773d4a7ab40f544a2327aa2d 100644 (file)
@@ -1,21 +1,17 @@
 should fix in 0.82:
 
-- constant branch folding
-- fast-slot stuff
-- 3 >n fep
+- callback segv
+- generate-push should not do anything without sse2
+- get literals working
+- get loads from stack working
+- get boxing working
+- straighten out "fp-scratch"
+- clean up/rewrite register allocation
+
 - amd64 %box-struct
-- get factor running on mac intel
 - when generating a 32-bit image on a 64-bit system, large numbers which should
   be bignums become fixnums
-- clicks sent twice
-- speed up ideas:
-  - only do clipping for certain gadgets
-  - use glRect
-
-+ portability:
-
-- win64 port
-- amd64 %unbox-struct
+- get factor running on mac intel
 
 + io:
 
@@ -23,9 +19,14 @@ should fix in 0.82:
 - better i/o scheduler
 - yield in a loop starves i/o
 - "localhost" 50 <client> won't fail
+- issues with timeouts
 
 + ui/help:
 
+- clicks sent twice
+- speed up ideas:
+  - only do clipping for certain gadgets
+  - use glRect
 - polish OS X menu bar code
 - help search
 - reimplement clicking input
@@ -54,16 +55,16 @@ should fix in 0.82:
 
 + compiler/ffi:
 
+- win64 port
+- amd64 %unbox-struct
+- constant branch folding
 - core foundation should use unicode strings
 - alien>utf16-string, utf16-string>alien words
 - can <void*> only be called with an alien?
 - remove <char*>, <ushort*>, set-char*-nth, set-ushort*-nth since they
   have incorrect semantics
-- improve callback efficiency
-- float intrinsics
 - complex float type
 - complex float intrinsics
-- out of memory from overflow check
 - remove literal table
 - C functions returning structs by value
 - FIELD: char key_vector[32];
@@ -73,10 +74,11 @@ should fix in 0.82:
 - [ [ dup call ] dup call ] infer hangs
 - the invalid recursion form case needs to be fixed, for inlines too
 - code gc
-- compiled gc check slows things down
+- fix compiled gc check
 
 + misc:
 
+- 3 >n fep
 - code walker & exceptions
 - slice: if sequence or seq start is changed, abstraction violation
 - make 3.4 bits>double an error
index bb217acdf689fe62b54c16d00c3a6a6df178a739..041bc8be1e50086b9723f3b26ac319c86681a06a 100644 (file)
@@ -10,7 +10,7 @@ vectors words ;
 "/library/bootstrap/primitives.factor" run-resource
 
 : if-arch ( arch seq -- )
-    architecture rot member?
+    architecture get rot member?
     [ [ parse-resource % ] each ] [ drop ] if ;
 
 ! The [ ] make form creates a boot quotation
index a0ee4204cf652d0e4f63461a728cd5e1b70198b2..5d6f02f2815e41005e2e90aa51b3ac256802eb84 100644 (file)
@@ -62,9 +62,6 @@ SYMBOL: architecture
 : word-type      16 ; inline
 : tuple-type     17 ; inline
 
-: immediate ( x tag -- tagged ) swap tag-bits shift bitor ;
-: >header ( id -- tagged ) object-tag immediate ;
-
 ( Image header )
 
 : base 1024 ;
@@ -106,9 +103,9 @@ GENERIC: ' ( obj -- ptr )
 
 ( Fixnums )
 
-: emit-fixnum ( n -- ) fixnum-tag immediate emit ;
+: emit-fixnum ( n -- ) fixnum-tag tag-address emit ;
 
-M: fixnum ' ( n -- tagged ) fixnum-tag immediate ;
+M: fixnum ' ( n -- tagged ) fixnum-tag tag-address ;
 
 ( Bignums )
 
@@ -136,14 +133,14 @@ M: fixnum ' ( n -- tagged ) fixnum-tag immediate ;
 M: bignum ' ( bignum -- tagged )
     #! This can only emit 0, -1 and 1.
     bignum-tag here-as >r
-    bignum-tag >header emit
+    bignum-tag tag-header emit
     emit-bignum align-here r> ;
 
 ( Floats )
 
 M: float ' ( float -- tagged )
     float-tag here-as >r
-    float-tag >header emit
+    float-tag tag-header emit
     align-here
     double>bits emit-64
     r> ;
@@ -177,7 +174,7 @@ M: f ' ( obj -- ptr )
     dup word-vocabulary ' >r
     dup word-name ' >r
     object-tag here-as over objects get set-hash
-    word-type >header emit
+    word-type tag-header emit
     hashcode emit-fixnum
     r> emit
     r> emit
@@ -209,7 +206,7 @@ M: word ' ( word -- pointer ) ;
 M: wrapper ' ( wrapper -- pointer )
     wrapped '
     object-tag here-as >r
-    wrapper-type >header emit
+    wrapper-type tag-header emit
     emit r> ;
 
 ( Conses )
@@ -234,7 +231,7 @@ M: complex ' ( c -- tagged ) >rect complex-tag emit-cons ;
 
 : emit-string ( string -- ptr )
     object-tag here-as swap
-    string-type >header emit
+    string-type tag-header emit
     dup length emit-fixnum
     dup hashcode emit-fixnum
     pack-string emit-chars
@@ -250,7 +247,7 @@ M: string ' ( string -- pointer )
 : emit-array ( list type -- pointer )
     >r [ ' ] map r>
     object-tag here-as >r
-    >header emit
+    tag-header emit
     dup length emit-fixnum
     ( elements -- ) emit-seq
     align-here r> ;
@@ -270,7 +267,7 @@ M: array ' ( array -- pointer )
 M: vector ' ( vector -- pointer )
     dup underlying ' swap length
     object-tag here-as >r
-    vector-type >header emit
+    vector-type tag-header emit
     emit-fixnum ( length )
     emit ( array ptr )
     align-here r> ;
@@ -278,7 +275,7 @@ M: vector ' ( vector -- pointer )
 M: sbuf ' ( sbuf -- pointer )
     dup underlying ' swap length
     object-tag here-as >r
-    sbuf-type >header emit
+    sbuf-type tag-header emit
     emit-fixnum ( length )
     emit ( array ptr )
     align-here r> ;
@@ -288,7 +285,7 @@ M: sbuf ' ( sbuf -- pointer )
 M: hashtable ' ( hashtable -- pointer )
     [ hash-array ' ] keep
     object-tag here-as >r
-    hashtable-type >header emit
+    hashtable-type tag-header emit
     dup hash-count emit-fixnum
     hash-deleted emit-fixnum
     emit ( array ptr )
index e464b8e44322db70f7b2209fe5b746b2bbcbf48e..3a3f7f364963ac625f6f91922115a9545cfad184 100644 (file)
@@ -27,6 +27,9 @@ GENERIC: fastcall-regs ( register-class -- regs )
 ! Sequence mapping vreg-n to native assembler registers
 GENERIC: vregs ( register-class -- regs )
 
+! Map a sequence of literals to f or float
+DEFER: literal-template ( literals -- template )
+
 ! Load a literal (immediate or indirect)
 G: load-literal ( obj vreg -- ) 1 standard-combination ;
 
index 435dcecb4a8db0d97399047478941d4455d7df51..70e067ced42893161f4ea69ebf06c77c660474bd 100644 (file)
@@ -195,14 +195,10 @@ UNION: immediate fixnum POSTPONE: f ;
 : alloc-literal-reg ( literal -- vreg )
     float? T{ float-regs f 8 } T{ int-regs } ? alloc-reg ;
 
-! : generate-push ( node -- )
-!     >#push< dup [ class ] map requested-vregs ensure-vregs
-!     [ dup alloc-literal-reg [ load-literal ] keep ] map
-!     phantom-d get phantom-append ;
-
 : generate-push ( node -- )
-    >#push< dup length 0 ensure-vregs
-    [ T{ int-regs } alloc-reg [ load-literal ] keep ] map
+    >#push< dup literal-template
+    dup requested-vregs ensure-vregs
+    alloc-vregs [ [ load-literal ] 2each ] keep
     phantom-d get phantom-append ;
 
 M: #push generate-node ( #push -- )
index 1e7982fd170c6f6fce406a024ca10ab137cdb8e3..d089ce1ec55b2c518c94041e5ac644cab7b1d987 100644 (file)
@@ -15,7 +15,7 @@ namespaces prettyprint sequences vectors words ;
 
 : alloc-vregs ( template -- template )
     [
-        first dup
+        dup
         H{ { f T{ int-regs } } { float T{ float-regs f 8 } } }
         hash [ alloc-reg ] [ <int-vreg> dup take-reg ] ?if
     ] map ;
@@ -179,7 +179,7 @@ SYMBOL: phantom-r
 
 : stack>vregs ( phantom template -- values )
     [
-        alloc-vregs dup length rot phantom-locs
+        [ first ] map alloc-vregs dup length rot phantom-locs
         [ dupd %peek ] 2map
     ] 2keep length neg swap adjust-phantom ;
 
@@ -258,10 +258,11 @@ SYMBOL: +clobber
 
 : guess-vregs ( -- int# float# )
     +input get { } additional-vregs#
-    +scratch get requested-vregs >r + r> ;
+    +scratch get [ first ] map requested-vregs >r + r> ;
 
 : alloc-scratch ( -- )
-    +scratch get [ alloc-vregs ] keep phantom-vregs ;
+    +scratch get
+    [ [ first ] map alloc-vregs ] keep phantom-vregs ;
 
 : template-inputs ( -- )
     ! Ensure we have enough to hold any new stack elements we
index 676a6a2801ac68ee0e37313270c9f3c92b2e36ef..1a3c0302249144015b5a23efec076f7afe5fff64 100644 (file)
@@ -46,16 +46,26 @@ M: float-regs vregs drop { XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 } ;
 
 : prepare-division CDQ ; inline
 
+: fp-scratch ( -- vreg )
+    "fp-scratch" get [
+        T{ int-regs } alloc-reg dup "fp-scratch" set
+    ] unless* ;
+
 : unboxify-float ( obj vreg quot -- | quot: obj int-vreg )
     #! The SSE2 code here will never be generated unless SSE2
     #! intrinsics are loaded.
     over [ float-regs? ] is? [
-        swap >r T{ int-regs } alloc-reg [ swap call ] keep
+        swap >r fp-scratch [ swap call ] keep
         r> swap [ v>operand ] 2apply float-offset [+] MOVSD
     ] [
         call
     ] if ; inline
 
+: literal-template
+    #! All literals go into integer registers unless SSE2
+    #! intrinsics are loaded.
+    length f <array> ;
+
 M: immediate load-literal ( literal vreg -- )
     v>operand swap v>operand MOV ;
 
@@ -98,24 +108,16 @@ M: object load-literal ( literal vreg -- )
 
 : %return ( -- ) %epilogue RET ;
 
-: vreg-mov [ v>operand ] 2apply MOV ;
+: vreg-mov swap [ v>operand ] 2apply MOV ;
 
 : %peek ( vreg loc -- )
-    swap [ swap vreg-mov ] unboxify-float ;
+    swap [ vreg-mov ] unboxify-float ;
 
-: %replace ( vreg loc -- )
-    #! The SSE2 code here will never be generated unless SSE2
-    #! intrinsics are loaded.
-    over [ float-regs? ] is? [
-        ! >r
-        ! "fp-scratch" operand "allot.here" f dlsym [] MOV
-        ! "fp-scratch" operand [] float-tag >header MOV
-        ! "fp-scratch" operand 8 [+] r> MOVSD
-        ! "allot.here" f dlsym [] 16 ADD
-        vreg-mov
-    ] [
-        vreg-mov
-    ] if ;
+GENERIC: (%replace) ( vreg loc reg-class -- )
+
+M: int-regs (%replace) drop vreg-mov ;
+
+: %replace ( vreg loc -- ) over (%replace) ;
 
 : (%inc) swap cells dup 0 > [ ADD ] [ neg SUB ] if ;
 
index 51a493ceef03c48f5725d48a526a713e4a9a2cbb..ca56945b845b6674181b163f55f1f52d2f87651f 100644 (file)
@@ -376,7 +376,7 @@ M: operand CMP OCT: 071 2-operand ;
 : 2-operand-sse ( dst src op1 op2 -- )
     #! We swap the operands here to make everything consistent
     #! with the integer instructions.
-    swap assemble-1 swapd
+    swap assemble-1 pick register-128? [ swapd ] [ 1 bitor ] if
     >r 2dup t prefix HEX: 0f assemble-1 r>
     assemble-1 reg-code swap addressing ;
 
index 239d63e456fe8c878ffe4fd13f441c05e690c36d..8e43378169913ac3507799b2de684cbc6e19e648 100644 (file)
@@ -1,9 +1,41 @@
 ! Copyright (C) 2005, 2006 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien arrays assembler kernel kernel-internals lists math
-math-internals namespaces sequences words ;
+USING: alien arrays assembler generic kernel kernel-internals
+lists math math-internals memory namespaces sequences words ;
 IN: compiler
 
+: literal-template
+    #! floats map to 'float' so we put float literals in float
+    #! vregs
+    [ class ] map ;
+
+: load-zone-ptr ( vreg -- )
+    #! Load pointer to start of zone array
+    "generations" f dlsym [] MOV ;
+
+: load-allot-ptr ( vreg -- )
+    dup load-zone-ptr dup cell [+] MOV ;
+
+: inc-allot-ptr ( vreg n -- )
+    >r dup load-zone-ptr cell [+] r> ADD ;
+
+: with-inline-alloc ( vreg spec prequot postquot -- )
+    #! both quotations are called with the vreg
+    rot [
+        >r >r v>operand dup load-allot-ptr
+        dup [] \ tag-header get call tag-header MOV
+        r> over slip dup \ tag get call OR
+        r> over slip \ size get call inc-allot-ptr
+    ] bind ; inline
+
+M: float-regs (%replace) ( vreg loc reg-class -- )
+    drop fp-scratch H{
+        { tag-header [ float-tag ] }
+        { tag [ float-tag ] }
+        { size [ 16 ] }
+    } [ 8 [+] rot v>operand MOVSD ]
+    [ >r v>operand r> MOV ] with-inline-alloc ;
+
 ! Floats
 : define-float-op ( word op -- )
     [ [ "x" operand "y" operand ] % , ] [ ] make H{
index c18ff92ce19dba00a10efac87ddffe43ba6b28b5..8c54939ab372ed6373dec0510e5e563f5fd8b7ae 100644 (file)
@@ -102,6 +102,9 @@ IN: kernel-internals
 
 : cell 17 getenv ; foldable
 
+: tag-address ( x tag -- tagged ) swap tag-bits shift bitor ;
+: tag-header ( id -- tagged ) object-tag tag-address ;
+
 IN: kernel
 
 : win32? windows? cell 4 = and ; inline
index 9af3f3bbf1bf7bd652af4a575bc81182dc85c260..b17fc6c0fdc32d6ff9f1368afcc85f325a5dcdc7 100644 (file)
@@ -1,7 +1,13 @@
 ! Copyright (C) 2004, 2006 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
+IN: math-internals
+USING: math kernel ;
+
+: float= ( n n -- )
+    #! The compiler replaces this with a better intrinsic.
+    [ double>bits ] 2apply number= ;
+
 IN: math
-USING: generic kernel math-internals ;
 
 UNION: real rational float ;
 
@@ -17,12 +23,11 @@ M: real <=> - ;
 M: float zero?
     double>bits HEX: 8000000000000000 [ bitor ] keep number= ;
 
-M: float number= [ double>bits ] 2apply number= ;
-
 M: float < float< ;
 M: float <= float<= ;
 M: float > float> ;
 M: float >= float>= ;
+M: float number= float= ;
 
 M: float + float+ ;
 M: float - float- ;
diff --git a/library/test/compiler/float.factor b/library/test/compiler/float.factor
new file mode 100644 (file)
index 0000000..e23da1f
--- /dev/null
@@ -0,0 +1,25 @@
+IN: temporary
+USING: compiler kernel memory math math-internals test ;
+
+[ 5.0 ] [ [ 5.0 ] compile-1 full-gc full-gc full-gc ] unit-test
+[ 2.0 3.0 ] [ 3.0 [ 2.0 swap ] compile-1 ] unit-test
+
+[ 3.0 ] [ 1.0 [ 2.0 float+ ] compile-1 ] unit-test
+[ 3.0 ] [ 1.0 [ 2.0 swap float+ ] compile-1 ] unit-test
+[ 3.0 ] [ 1.0 2.0 [ float+ ] compile-1 ] unit-test
+[ 3.0 ] [ 1.0 2.0 [ swap float+ ] compile-1 ] unit-test
+
+[ -1.0 ] [ 1.0 [ 2.0 float- ] compile-1 ] unit-test
+[ 1.0 ] [ 1.0 [ 2.0 swap float- ] compile-1 ] unit-test
+[ -1.0 ] [ 1.0 2.0 [ float- ] compile-1 ] unit-test
+[ 1.0 ] [ 1.0 2.0 [ swap float- ] compile-1 ] unit-test
+
+[ 6.0 ] [ 3.0 [ 2.0 float* ] compile-1 ] unit-test
+[ 6.0 ] [ 3.0 [ 2.0 swap float* ] compile-1 ] unit-test
+[ 6.0 ] [ 3.0 2.0 [ float* ] compile-1 ] unit-test
+[ 6.0 ] [ 3.0 2.0 [ swap float* ] compile-1 ] unit-test
+
+[ 0.5 ] [ 1.0 [ 2.0 float/f ] compile-1 ] unit-test
+[ 2.0 ] [ 1.0 [ 2.0 swap float/f ] compile-1 ] unit-test
+[ 0.5 ] [ 1.0 2.0 [ float/f ] compile-1 ] unit-test
+[ 2.0 ] [ 1.0 2.0 [ swap float/f ] compile-1 ] unit-test
index b579bb0e0c9475694381eadb52e8a8651223d7f2..2d6a0389d5287b9d17b1daca3958a440425f6cfd 100644 (file)
@@ -104,7 +104,7 @@ SYMBOL: failures
         "compiler/simple" "compiler/templates"
         "compiler/stack" "compiler/ifte"
         "compiler/generic" "compiler/bail-out"
-        "compiler/intrinsics"
+        "compiler/intrinsics" "compiler/float"
         "compiler/identities" "compiler/optimizer"
         "compiler/alien" "compiler/callbacks"
     } run-tests ;
index 07482fcbdb17ea519377e20f91fc31029b73cbcd..0151aa9b9581b1b11e97416df2ccf50ecec92f71 100644 (file)
@@ -18,7 +18,7 @@ CELL gen_count;
 /* the oldest generation */
 #define TENURED (gen_count-1)
 
-ZONE *generations;
+DLLEXPORT ZONE *generations;
 
 /* used during garbage collection only */
 ZONE *newspace;