fixnum/i overflow
parent
7f7a0a057e
commit
d35b6d39e3
|
@ -51,19 +51,18 @@
|
|||
+ compiler:
|
||||
|
||||
- flushing optimization
|
||||
- compile-byte/cell: instantiating aliens
|
||||
- fix fixnum<< and /i overflow on PowerPC
|
||||
- simplifier:
|
||||
- kill replace after a peek
|
||||
- merge inc-d's across VOPs that don't touch the stack
|
||||
- intrinsic char-slot set-char-slot integer-slot set-integer-slot
|
||||
- fix fixnum/mod overflow on PowerPC
|
||||
- eliminate simplifier
|
||||
- intrinsic char-slot set-char-slot
|
||||
- [ [ dup call ] dup call ] infer hangs
|
||||
- declarations
|
||||
- the invalid recursion form case needs to be fixed, for inlines too
|
||||
- #jump-f #jump-f-label
|
||||
- re-introduce #target-label => #target optimization
|
||||
- recursion is iffy; if the stack at the recursive call doesn't match
|
||||
up, throw an error
|
||||
- remove %fixnum-</<=/>/>=, always use %jump-* form
|
||||
- remove %jump-t, use %jump-eq? f instead
|
||||
- kill dead code after 'throw'
|
||||
- better type inference
|
||||
|
||||
+ kernel:
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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 + ;
|
||||
|
|
|
@ -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 -- )
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue