2010-04-21 03:08:52 -04:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
|
2008-10-20 21:40:15 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-17 00:50:48 -04:00
|
|
|
USING: sequences accessors layouts kernel math math.intervals
|
|
|
|
namespaces combinators fry arrays
|
2009-09-02 07:22:37 -04:00
|
|
|
cpu.architecture
|
2008-10-20 21:40:15 -04:00
|
|
|
compiler.tree.propagation.info
|
2010-04-27 10:51:00 -04:00
|
|
|
compiler.cfg
|
2008-11-28 07:36:30 -05:00
|
|
|
compiler.cfg.hats
|
|
|
|
compiler.cfg.stacks
|
|
|
|
compiler.cfg.instructions
|
2008-11-28 09:35:02 -05:00
|
|
|
compiler.cfg.utilities
|
2009-07-23 21:54:38 -04:00
|
|
|
compiler.cfg.builder.blocks
|
2009-07-13 15:42:52 -04:00
|
|
|
compiler.cfg.registers
|
|
|
|
compiler.cfg.comparisons ;
|
2008-10-20 21:40:15 -04:00
|
|
|
IN: compiler.cfg.intrinsics.fixnum
|
|
|
|
|
2008-11-28 09:35:02 -05:00
|
|
|
: emit-both-fixnums? ( -- )
|
2010-04-22 04:21:23 -04:00
|
|
|
[
|
|
|
|
[ ^^tagged>integer ] bi@
|
|
|
|
^^or tag-mask get ^^and-imm
|
|
|
|
0 cc= ^^compare-integer-imm
|
|
|
|
] binary-op ;
|
2010-04-21 03:08:52 -04:00
|
|
|
|
2009-07-17 00:50:48 -04:00
|
|
|
: emit-fixnum-left-shift ( -- )
|
2010-04-22 04:21:23 -04:00
|
|
|
[ ^^shl ] binary-op ;
|
2009-07-17 00:50:48 -04:00
|
|
|
|
|
|
|
: emit-fixnum-right-shift ( -- )
|
2010-04-22 04:21:23 -04:00
|
|
|
[
|
|
|
|
[ tag-bits get ^^shl-imm ] dip
|
|
|
|
^^neg ^^sar
|
|
|
|
tag-bits get ^^sar-imm
|
|
|
|
] binary-op ;
|
2009-07-17 00:50:48 -04:00
|
|
|
|
|
|
|
: emit-fixnum-shift-general ( -- )
|
2010-04-22 04:21:23 -04:00
|
|
|
ds-peek 0 cc> ##compare-integer-imm-branch
|
2009-07-17 00:50:48 -04:00
|
|
|
[ emit-fixnum-left-shift ] with-branch
|
|
|
|
[ emit-fixnum-right-shift ] with-branch
|
|
|
|
2array emit-conditional ;
|
|
|
|
|
2008-10-20 21:40:15 -04:00
|
|
|
: emit-fixnum-shift-fast ( node -- )
|
2009-07-17 00:50:48 -04:00
|
|
|
node-input-infos second interval>> {
|
|
|
|
{ [ dup 0 [a,inf] interval-subset? ] [ drop emit-fixnum-left-shift ] }
|
|
|
|
{ [ dup 0 [-inf,a] interval-subset? ] [ drop emit-fixnum-right-shift ] }
|
|
|
|
[ drop emit-fixnum-shift-general ]
|
|
|
|
} cond ;
|
2010-04-18 16:26:31 -04:00
|
|
|
|
2009-07-14 20:18:57 -04:00
|
|
|
: emit-fixnum-comparison ( cc -- )
|
2010-04-22 04:21:23 -04:00
|
|
|
'[ _ ^^compare-integer ] binary-op ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
2009-07-16 19:29:40 -04:00
|
|
|
: emit-no-overflow-case ( dst -- final-bb )
|
2009-07-23 21:54:38 -04:00
|
|
|
[ ds-drop ds-drop ds-push ] with-branch ;
|
2009-07-16 19:29:40 -04:00
|
|
|
|
|
|
|
: emit-overflow-case ( word -- final-bb )
|
2010-05-09 21:36:52 -04:00
|
|
|
[
|
|
|
|
##call
|
|
|
|
-1 adjust-d
|
|
|
|
make-kill-block
|
|
|
|
] with-branch ;
|
2009-07-16 19:29:40 -04:00
|
|
|
|
|
|
|
: emit-fixnum-overflow-op ( quot word -- )
|
2009-07-24 04:37:18 -04:00
|
|
|
! Inputs to the final instruction need to be copied because
|
|
|
|
! of loc>vreg sync
|
2010-04-27 10:51:00 -04:00
|
|
|
[ [ (2inputs) [ any-rep ^^copy ] bi@ cc/o ] dip call ] dip
|
2009-07-16 19:29:40 -04:00
|
|
|
[ emit-no-overflow-case ] [ emit-overflow-case ] bi* 2array
|
|
|
|
emit-conditional ; inline
|
|
|
|
|
|
|
|
: fixnum+overflow ( x y -- z ) [ >bignum ] bi@ + ;
|
|
|
|
|
|
|
|
: fixnum-overflow ( x y -- z ) [ >bignum ] bi@ - ;
|
|
|
|
|
|
|
|
: fixnum*overflow ( x y -- z ) [ >bignum ] bi@ * ;
|
|
|
|
|
|
|
|
: emit-fixnum+ ( -- )
|
|
|
|
[ ^^fixnum-add ] \ fixnum+overflow emit-fixnum-overflow-op ;
|
|
|
|
|
|
|
|
: emit-fixnum- ( -- )
|
|
|
|
[ ^^fixnum-sub ] \ fixnum-overflow emit-fixnum-overflow-op ;
|
|
|
|
|
|
|
|
: emit-fixnum* ( -- )
|
2010-04-21 03:08:52 -04:00
|
|
|
[ ^^fixnum-mul ] \ fixnum*overflow emit-fixnum-overflow-op ;
|