fixnum/i overflow
parent
7f7a0a057e
commit
d35b6d39e3
|
@ -51,19 +51,18 @@
|
||||||
+ compiler:
|
+ compiler:
|
||||||
|
|
||||||
- flushing optimization
|
- flushing optimization
|
||||||
- compile-byte/cell: instantiating aliens
|
- fix fixnum/mod overflow on PowerPC
|
||||||
- fix fixnum<< and /i overflow on PowerPC
|
- eliminate simplifier
|
||||||
- simplifier:
|
- intrinsic char-slot set-char-slot
|
||||||
- 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
|
|
||||||
- [ [ dup call ] dup call ] infer hangs
|
- [ [ dup call ] dup call ] infer hangs
|
||||||
- declarations
|
- declarations
|
||||||
- the invalid recursion form case needs to be fixed, for inlines too
|
- 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
|
- recursion is iffy; if the stack at the recursive call doesn't match
|
||||||
up, throw an error
|
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:
|
+ kernel:
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ IN: compiler-frontend
|
||||||
|
|
||||||
! A few things the front-end needs to know about the back-end.
|
! A few things the front-end needs to know about the back-end.
|
||||||
|
|
||||||
|
DEFER: cell ( -- n )
|
||||||
|
#! Word size
|
||||||
|
|
||||||
DEFER: fixnum-imm? ( -- ? )
|
DEFER: fixnum-imm? ( -- ? )
|
||||||
#! Can fixnum operations take immediate operands?
|
#! Can fixnum operations take immediate operands?
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ USING: alien math memory kernel hashtables namespaces ;
|
||||||
|
|
||||||
SYMBOL: interned-literals
|
SYMBOL: interned-literals
|
||||||
|
|
||||||
: cell 4 ; inline
|
|
||||||
: compiled-header HEX: 01c3babe ; inline
|
: compiled-header HEX: 01c3babe ; inline
|
||||||
|
|
||||||
: compiled-byte ( a -- n )
|
: compiled-byte ( a -- n )
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
IN: compiler-frontend
|
IN: compiler-frontend
|
||||||
USING: assembler compiler-backend math ;
|
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? ( -- ? )
|
: fixnum-imm? ( -- ? )
|
||||||
#! Can fixnum operations take immediate operands?
|
#! Can fixnum operations take immediate operands?
|
||||||
f ;
|
f ; inline
|
||||||
|
|
||||||
: vregs ( -- n )
|
: vregs ( -- n )
|
||||||
#! Number of vregs
|
#! Number of vregs
|
||||||
8 ;
|
8 ; inline
|
||||||
|
|
||||||
M: vreg v>operand vreg-n 3 + ;
|
M: vreg v>operand vreg-n 3 + ;
|
||||||
|
|
|
@ -56,20 +56,24 @@ M: %fixnum* generate-node ( vop -- )
|
||||||
"end" get save-xt
|
"end" get save-xt
|
||||||
3 6 MR ;
|
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 )
|
: most-negative-fixnum ( -- n )
|
||||||
1 cell 8 * tag-bits - 1 - shift neg ; inline
|
first-bignum neg >fixnum ; inline
|
||||||
|
|
||||||
M: %fixnum/i generate-node ( vop -- )
|
M: %fixnum/i generate-node ( vop -- )
|
||||||
#! This has specific vreg requirements.
|
#! This has specific vreg requirements.
|
||||||
drop
|
|
||||||
0 MTXER
|
|
||||||
5 3 4 DIVWO.
|
|
||||||
<label> "overflow" set
|
|
||||||
<label> "end" set
|
<label> "end" set
|
||||||
"overflow" get BO
|
drop
|
||||||
3 5 tag-fixnum
|
5 3 4 DIVW
|
||||||
"end" get B
|
most-positive-fixnum 4 LOAD
|
||||||
"overflow" get save-xt
|
5 3 tag-fixnum
|
||||||
|
5 0 4 CMP
|
||||||
|
"end" get BLE
|
||||||
most-negative-fixnum neg 3 LOAD
|
most-negative-fixnum neg 3 LOAD
|
||||||
"s48_long_to_bignum" f compile-c-call
|
"s48_long_to_bignum" f compile-c-call
|
||||||
3 3 bignum-tag ORI
|
3 3 bignum-tag ORI
|
||||||
|
@ -128,7 +132,7 @@ M: %fixnum<< generate-node ( vop -- )
|
||||||
"end" get B
|
"end" get B
|
||||||
! there is not going to be an overflow
|
! there is not going to be an overflow
|
||||||
"no-overflow" get save-xt
|
"no-overflow" get save-xt
|
||||||
3 3 rot SLWI
|
3 3 rot SLWI.
|
||||||
"end" get save-xt ;
|
"end" get save-xt ;
|
||||||
|
|
||||||
M: %fixnum>> generate-node ( vop -- )
|
M: %fixnum>> generate-node ( vop -- )
|
||||||
|
|
|
@ -4,13 +4,8 @@ IN: compiler-backend
|
||||||
USING: alien assembler compiler inference kernel
|
USING: alien assembler compiler inference kernel
|
||||||
kernel-internals lists math memory namespaces words ;
|
kernel-internals lists math memory namespaces words ;
|
||||||
|
|
||||||
! PowerPC register assignments
|
|
||||||
! r14 data stack
|
|
||||||
! r15 call stack
|
|
||||||
! r16-r30 vregs
|
|
||||||
|
|
||||||
: compile-c-call ( symbol dll -- )
|
: 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 -- )
|
M: %prologue generate-node ( vop -- )
|
||||||
drop
|
drop
|
||||||
|
@ -82,7 +77,7 @@ M: %untag generate-node ( vop -- )
|
||||||
M: %untag-fixnum generate-node ( vop -- )
|
M: %untag-fixnum generate-node ( vop -- )
|
||||||
dest/src tag-bits SRAWI ;
|
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 -- )
|
M: %retag-fixnum generate-node ( vop -- )
|
||||||
! todo: formalize scratch register usage
|
! todo: formalize scratch register usage
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
IN: compiler-frontend
|
IN: compiler-frontend
|
||||||
USING: assembler compiler-backend sequences ;
|
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? ( -- ? )
|
: fixnum-imm? ( -- ? )
|
||||||
#! Can fixnum operations take immediate operands?
|
#! Can fixnum operations take immediate operands?
|
||||||
t ;
|
t ; inline
|
||||||
|
|
||||||
: vregs ( -- n )
|
: vregs ( -- n )
|
||||||
#! Number of vregs
|
#! Number of vregs
|
||||||
3 ;
|
3 ; inline
|
||||||
|
|
||||||
M: vreg v>operand vreg-n { EAX ECX EDX } nth ;
|
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 ] [ -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
|
[ t ] [ f [ f eq? ] compile-1 ] unit-test
|
||||||
|
|
Loading…
Reference in New Issue