]> gitweb.factorcode.org Git - factor.git/commitdiff
fixnum/i overflow
authorSlava Pestov <slava@factorcode.org>
Mon, 5 Sep 2005 21:14:15 +0000 (21:14 +0000)
committerSlava Pestov <slava@factorcode.org>
Mon, 5 Sep 2005 21:14:15 +0000 (21:14 +0000)
TODO.FACTOR.txt
library/compiler/architecture.factor
library/compiler/assembler.factor
library/compiler/ppc/architecture.factor
library/compiler/ppc/fixnum.factor
library/compiler/ppc/generator.factor
library/compiler/x86/architecture.factor
library/test/compiler/intrinsics.factor

index 6f3ae71283ae04a18b61c41b424601b63ecf7e73..d8296ea151b883a92ebbc2cb966b0021c851eb6a 100644 (file)
 + compiler:\r
 \r
 - flushing optimization\r
-- compile-byte/cell: instantiating aliens\r
-- fix fixnum<< and /i overflow on PowerPC\r
-- simplifier:\r
-  - kill replace after a peek\r
-  - merge inc-d's across VOPs that don't touch the stack\r
-- intrinsic char-slot set-char-slot integer-slot set-integer-slot\r
+- fix fixnum/mod overflow on PowerPC\r
+- eliminate simplifier\r
+- intrinsic char-slot set-char-slot\r
 - [ [ dup call ] dup call ] infer hangs\r
 - declarations\r
 - the invalid recursion form case needs to be fixed, for inlines too\r
-- #jump-f #jump-f-label\r
-- re-introduce #target-label => #target optimization\r
 - recursion is iffy; if the stack at the recursive call doesn't match\r
   up, throw an error\r
+- remove %fixnum-</<=/>/>=, always use %jump-* form\r
+- remove %jump-t, use %jump-eq? f instead\r
+- kill dead code after 'throw'\r
+- better type inference\r
 \r
 + kernel:\r
 \r
index cbab88722bbe7b6c62d43c5130013fa20edcb760..a40c03950125af5313d892330e9741a4dfe369e0 100644 (file)
@@ -2,6 +2,9 @@ IN: compiler-frontend
 
 ! A few things the front-end needs to know about the back-end.
 
+DEFER: cell ( -- n )
+#! Word size
+
 DEFER: fixnum-imm? ( -- ? )
 #! Can fixnum operations take immediate operands?
 
index 83a192ccac12f7ef7321c927a896236fb98bfb01..ae016c048a8bdc2da80424367d52a06fc81ddfe4 100644 (file)
@@ -5,7 +5,6 @@ USING: alien math memory kernel hashtables namespaces ;
 
 SYMBOL: interned-literals
 
-: cell 4 ; inline
 : compiled-header HEX: 01c3babe ; inline
 
 : compiled-byte ( a -- n )
index b637a9f96ebf43cd784eff6d2acc9323ed410de7..9276bb9da5b28f90ebff6d43a86143e9d5cbb087 100644 (file)
@@ -1,13 +1,21 @@
 IN: compiler-frontend
 USING: assembler compiler-backend math ;
 
-! Architecture description
+! PowerPC register assignments
+! r3-r10 vregs
+! r14 data stack
+! r15 call stack
+
+: cell
+    #! Word size.
+    4 ; inline
+
 : fixnum-imm? ( -- ? )
     #! Can fixnum operations take immediate operands?
-    f ;
+    f ; inline
 
 : vregs ( -- n )
     #! Number of vregs
-    8 ;
+    8 ; inline
 
 M: vreg v>operand vreg-n 3 + ;
index 23f616a805135842e8001cd512c00b4d9e309983..50354996613d4f204b0cf636918b9862f8b0a2c7 100644 (file)
@@ -56,20 +56,24 @@ M: %fixnum* generate-node ( vop -- )
     "end" get save-xt
     3 6 MR ;
 
+: first-bignum ( -- n )
+    1 cell 8 * tag-bits - 1 - shift ; inline
+
+: most-positive-fixnum ( -- n )
+    first-bignum 1 - >fixnum ; inline
+
 : most-negative-fixnum ( -- n )
-      1 cell 8 * tag-bits - 1 - shift neg ; inline
+    first-bignum neg >fixnum ; inline
 
 M: %fixnum/i generate-node ( vop -- )
     #! This has specific vreg requirements.
-    drop
-    0 MTXER
-    5 3 4 DIVWO.
-    <label> "overflow" set
     <label> "end" set
-    "overflow" get BO
-    3 5 tag-fixnum
-    "end" get B
-    "overflow" get save-xt
+    drop
+    5 3 4 DIVW
+    most-positive-fixnum 4 LOAD
+    5 3 tag-fixnum
+    5 0 4 CMP
+    "end" get BLE
     most-negative-fixnum neg 3 LOAD
     "s48_long_to_bignum" f compile-c-call
     3 3 bignum-tag ORI
@@ -128,7 +132,7 @@ M: %fixnum<< generate-node ( vop -- )
     "end" get B
     ! there is not going to be an overflow
     "no-overflow" get save-xt
-    3 3 rot SLWI
+    3 3 rot SLWI.
     "end" get save-xt ;
 
 M: %fixnum>> generate-node ( vop -- )
index 9e280743396b932187e08264836280f48cba3345..87b99f061779b8ace6a61fc2774bdaad4b954dc0 100644 (file)
@@ -4,13 +4,8 @@ IN: compiler-backend
 USING: alien assembler compiler inference kernel
 kernel-internals lists math memory namespaces words ;
 
-! PowerPC register assignments
-! r14 data stack
-! r15 call stack
-! r16-r30 vregs
-
 : compile-c-call ( symbol dll -- )
-    2dup dlsym  19 LOAD32  0 1 rel-dlsym  19 MTLR  BLRL ;
+    2dup dlsym  3 LOAD32  0 1 rel-dlsym  3 MTLR  BLRL ;
 
 M: %prologue generate-node ( vop -- )
     drop
@@ -82,7 +77,7 @@ M: %untag generate-node ( vop -- )
 M: %untag-fixnum generate-node ( vop -- )
     dest/src tag-bits SRAWI ;
 
-: tag-fixnum ( dest src -- ) tag-bits SLWI ;
+: tag-fixnum ( src dest -- ) tag-bits SLWI ;
 
 M: %retag-fixnum generate-node ( vop -- )
     ! todo: formalize scratch register usage
index 143eddb906b66731fecbf5f3f82ff1ed4174344b..1b0abd7ba4fd3e0b8c67bf5b8fdcebb5f7757457 100644 (file)
@@ -1,13 +1,21 @@
 IN: compiler-frontend
 USING: assembler compiler-backend sequences ;
 
-! Architecture description
+! x86 register assignments
+! EAX, ECX, EDX vregs
+! ESI datastack
+! EBX callstack
+
+: cell
+    #! Word size.
+    4 ; inline
+
 : fixnum-imm? ( -- ? )
     #! Can fixnum operations take immediate operands?
-    t ;
+    t ; inline
 
 : vregs ( -- n )
     #! Number of vregs
-    3 ;
+    3 ; inline
 
 M: vreg v>operand vreg-n { EAX ECX EDX } nth ;
index b0e74681d1550c955455f737fc74d3e732e64526..0b371b8f1721522e68789c3a2cbdcf8e20dff9f3 100644 (file)
@@ -164,4 +164,6 @@ math-internals test words ;
 
 [ 268435456 ] [ -268435456 >fixnum -1 [ fixnum/i ] compile-1 ] unit-test
 
+[ 268435456 0 ] [ -268435456 >fixnum -1 [ fixnum/mod ] compile-1 ] unit-test
+
 [ t ] [ f [ f eq? ] compile-1 ] unit-test