2009-04-28 04:48:37 -04:00
|
|
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
2007-09-21 23:29:38 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-07-11 18:25:46 -04:00
|
|
|
USING: bootstrap.image.private kernel kernel.private namespaces
|
2008-08-12 04:31:48 -04:00
|
|
|
system cpu.x86.assembler layouts compiler.units math
|
2008-10-23 06:49:32 -04:00
|
|
|
math.private compiler.constants vocabs slots.private words
|
2009-04-28 04:48:37 -04:00
|
|
|
locals.backend make sequences combinators ;
|
2007-09-21 23:29:38 -04:00
|
|
|
IN: bootstrap.x86
|
|
|
|
|
|
|
|
big-endian off
|
|
|
|
|
|
|
|
1 jit-code-format set
|
|
|
|
|
|
|
|
[
|
2008-01-02 19:36:36 -05:00
|
|
|
! Load word
|
2009-04-25 23:35:19 -04:00
|
|
|
temp0 0 MOV rc-absolute-cell rt-immediate jit-rel
|
2008-01-02 19:36:36 -05:00
|
|
|
! Bump profiling counter
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 profile-count-offset [+] 1 tag-fixnum ADD
|
2008-01-02 19:36:36 -05:00
|
|
|
! Load word->code
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 temp0 word-code-offset [+] MOV
|
2008-01-02 19:36:36 -05:00
|
|
|
! Compute word XT
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 compiled-header-size ADD
|
2008-01-02 19:36:36 -05:00
|
|
|
! Jump to XT
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 JMP
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-profiling jit-define
|
2008-01-02 19:36:36 -05:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load XT
|
2009-04-25 23:35:19 -04:00
|
|
|
temp0 0 MOV rc-absolute-cell rt-this jit-rel
|
2008-12-09 18:14:17 -05:00
|
|
|
! save stack frame size
|
|
|
|
stack-frame-size PUSH
|
|
|
|
! push XT
|
|
|
|
temp0 PUSH
|
|
|
|
! alignment
|
|
|
|
stack-reg stack-frame-size 3 bootstrap-cells - SUB
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-prolog jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
2008-07-12 23:27:28 -04:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load literal
|
2009-04-25 23:35:19 -04:00
|
|
|
temp0 0 MOV rc-absolute-cell rt-immediate jit-rel
|
2008-12-09 18:14:17 -05:00
|
|
|
! increment datastack pointer
|
|
|
|
ds-reg bootstrap-cell ADD
|
|
|
|
! store literal on datastack
|
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-push-immediate jit-define
|
2008-07-12 23:27:28 -04:00
|
|
|
|
2007-12-25 23:40:36 -05:00
|
|
|
[
|
2009-04-25 23:35:19 -04:00
|
|
|
f JMP rc-relative rt-xt jit-rel
|
|
|
|
] jit-word-jump jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
|
|
|
[
|
2009-04-25 23:35:19 -04:00
|
|
|
f CALL rc-relative rt-xt jit-rel
|
|
|
|
] jit-word-call jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
2007-12-26 01:45:16 -05:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load boolean
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! pop boolean
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! compare boolean with f
|
|
|
|
temp0 \ f tag-number CMP
|
|
|
|
! jump to true branch if not equal
|
2009-04-25 23:35:19 -04:00
|
|
|
f JNE rc-relative rt-xt jit-rel
|
|
|
|
] jit-if-1 jit-define
|
2008-11-24 01:23:17 -05:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! jump to false branch if equal
|
2009-04-25 23:35:19 -04:00
|
|
|
f JMP rc-relative rt-xt jit-rel
|
|
|
|
] jit-if-2 jit-define
|
2007-09-21 23:29:38 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load dispatch table
|
2009-04-25 23:35:19 -04:00
|
|
|
temp1 0 MOV rc-absolute-cell rt-immediate jit-rel
|
2008-12-09 18:14:17 -05:00
|
|
|
! load index
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! turn it into an array offset
|
|
|
|
fixnum>slot@
|
|
|
|
! pop index
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! compute quotation location
|
|
|
|
temp0 temp1 ADD
|
|
|
|
! load quotation
|
2008-12-15 21:55:24 -05:00
|
|
|
arg temp0 array-start-offset [+] MOV
|
|
|
|
! execute branch. the quot must be in arg, since it might
|
|
|
|
! not be compiled yet
|
|
|
|
arg quot-xt-offset [+] JMP
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-dispatch jit-define
|
2007-09-21 23:29:38 -04:00
|
|
|
|
2008-11-23 03:44:56 -05:00
|
|
|
: jit->r ( -- )
|
|
|
|
rs-reg bootstrap-cell ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
2008-11-23 03:44:56 -05:00
|
|
|
ds-reg bootstrap-cell SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
rs-reg [] temp0 MOV ;
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
: jit-2>r ( -- )
|
|
|
|
rs-reg 2 bootstrap-cells ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg -1 bootstrap-cells [+] MOV
|
2008-11-23 03:44:56 -05:00
|
|
|
ds-reg 2 bootstrap-cells SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
rs-reg [] temp0 MOV
|
|
|
|
rs-reg -1 bootstrap-cells [+] temp1 MOV ;
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
: jit-3>r ( -- )
|
|
|
|
rs-reg 3 bootstrap-cells ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg -1 bootstrap-cells [+] MOV
|
|
|
|
temp2 ds-reg -2 bootstrap-cells [+] MOV
|
2008-11-23 03:44:56 -05:00
|
|
|
ds-reg 3 bootstrap-cells SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
rs-reg [] temp0 MOV
|
|
|
|
rs-reg -1 bootstrap-cells [+] temp1 MOV
|
|
|
|
rs-reg -2 bootstrap-cells [+] temp2 MOV ;
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
: jit-r> ( -- )
|
|
|
|
ds-reg bootstrap-cell ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 rs-reg [] MOV
|
2008-11-23 03:44:56 -05:00
|
|
|
rs-reg bootstrap-cell SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV ;
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
: jit-2r> ( -- )
|
|
|
|
ds-reg 2 bootstrap-cells ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 rs-reg [] MOV
|
|
|
|
temp1 rs-reg -1 bootstrap-cells [+] MOV
|
2008-11-23 03:44:56 -05:00
|
|
|
rs-reg 2 bootstrap-cells SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
|
|
|
ds-reg -1 bootstrap-cells [+] temp1 MOV ;
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
: jit-3r> ( -- )
|
|
|
|
ds-reg 3 bootstrap-cells ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 rs-reg [] MOV
|
|
|
|
temp1 rs-reg -1 bootstrap-cells [+] MOV
|
|
|
|
temp2 rs-reg -2 bootstrap-cells [+] MOV
|
2008-11-23 03:44:56 -05:00
|
|
|
rs-reg 3 bootstrap-cells SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
|
|
|
ds-reg -1 bootstrap-cells [+] temp1 MOV
|
|
|
|
ds-reg -2 bootstrap-cells [+] temp2 MOV ;
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
jit->r
|
2009-04-25 23:35:19 -04:00
|
|
|
f CALL rc-relative rt-xt jit-rel
|
2008-11-23 03:44:56 -05:00
|
|
|
jit-r>
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-dip jit-define
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
jit-2>r
|
2009-04-25 23:35:19 -04:00
|
|
|
f CALL rc-relative rt-xt jit-rel
|
2008-11-23 03:44:56 -05:00
|
|
|
jit-2r>
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-2dip jit-define
|
2008-11-23 03:44:56 -05:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
jit-3>r
|
2009-04-25 23:35:19 -04:00
|
|
|
f CALL rc-relative rt-xt jit-rel
|
2008-11-23 03:44:56 -05:00
|
|
|
jit-3r>
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-3dip jit-define
|
2008-11-23 03:44:56 -05:00
|
|
|
|
2009-04-25 22:14:59 -04:00
|
|
|
: prepare-(execute) ( -- operand )
|
|
|
|
! load from stack
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! pop stack
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! execute word
|
|
|
|
temp0 word-xt-offset [+] ;
|
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ prepare-(execute) JMP ] jit-execute-jump jit-define
|
2009-04-25 22:14:59 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ prepare-(execute) CALL ] jit-execute-call jit-define
|
2009-04-25 22:14:59 -04:00
|
|
|
|
2008-07-11 18:25:46 -04:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! unwind stack frame
|
|
|
|
stack-reg stack-frame-size bootstrap-cell - ADD
|
2009-04-25 23:35:19 -04:00
|
|
|
] jit-epilog jit-define
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ 0 RET ] jit-return jit-define
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2009-04-28 04:48:37 -04:00
|
|
|
! ! ! Polymorphic inline caches
|
|
|
|
|
|
|
|
! The 'make' trick lets us compute the jump distance for the conditional branches there
|
|
|
|
|
|
|
|
! Tag
|
|
|
|
[
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
temp0 tag-bits get AND
|
|
|
|
] pic-tag jit-define
|
|
|
|
|
|
|
|
! Hi-tag
|
|
|
|
[
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
temp0 object tag-number TEST
|
|
|
|
[ temp0 temp0 object tag-number neg [+] MOV ] { } make
|
|
|
|
[ length JNE ] [ % ] bi
|
|
|
|
] pic-hi-tag jit-define
|
|
|
|
|
|
|
|
! Tuple
|
|
|
|
[
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
temp0 tuple tag-number TEST
|
|
|
|
[ temp0 temp0 tuple tag-number neg bootstrap-cell + [+] MOV ] { } make
|
|
|
|
[ length JNE ] [ % ] bi
|
|
|
|
] pic-tuple jit-define
|
|
|
|
|
|
|
|
! Hi-tag and tuple
|
|
|
|
[
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! If bits 2 and 3 are set, the tag is either 6 (object) or 7 (tuple)
|
|
|
|
temp0 6 TEST
|
|
|
|
[
|
|
|
|
temp1 temp0 MOV
|
|
|
|
! Make temp0 untagged
|
|
|
|
temp0 tag-mask get bitnot AND
|
|
|
|
! Set temp1 to 0 for objects, and 4 or 8 for tuples
|
|
|
|
temp1 1 AND
|
|
|
|
bootstrap-cell {
|
|
|
|
{ 4 [ temp1 2 SHL ] }
|
|
|
|
{ 8 [ temp1 3 SHL ] }
|
|
|
|
} case
|
|
|
|
! Load header cell or tuple layout cell
|
|
|
|
temp0 temp0 temp1 [+] MOV
|
|
|
|
] [ ] make [ length JNE ] [ % ] bi
|
|
|
|
] pic-hi-tag-tuple jit-define
|
|
|
|
|
|
|
|
[ temp0 HEX: ffffffff CMP ] pic-check jit-define
|
|
|
|
|
|
|
|
[ f JE rc-relative rt-xt jit-rel ] pic-hit jit-define
|
|
|
|
|
|
|
|
! ! ! Sub-primitives
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
! Quotations and words
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load from stack
|
2008-12-10 02:19:22 -05:00
|
|
|
arg ds-reg [] MOV
|
2008-12-09 18:14:17 -05:00
|
|
|
! pop stack
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! call quotation
|
2008-12-10 02:19:22 -05:00
|
|
|
arg quot-xt-offset [+] JMP
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ (call) define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
! Objects
|
2008-07-07 11:39:04 -04:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load from stack
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! compute tag
|
|
|
|
temp0 tag-mask get AND
|
|
|
|
! tag the tag
|
|
|
|
temp0 tag-bits get SHL
|
|
|
|
! push to stack
|
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ tag define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load slot number
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! adjust stack pointer
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! load object
|
|
|
|
temp1 ds-reg [] MOV
|
|
|
|
! turn slot number into offset
|
|
|
|
fixnum>slot@
|
|
|
|
! mask off tag
|
|
|
|
temp1 tag-bits get SHR
|
|
|
|
temp1 tag-bits get SHL
|
|
|
|
! load slot value
|
|
|
|
temp0 temp1 temp0 [+] MOV
|
|
|
|
! push to stack
|
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ slot define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
2008-07-11 18:25:46 -04:00
|
|
|
! Shufflers
|
2008-07-07 11:39:04 -04:00
|
|
|
[
|
|
|
|
ds-reg bootstrap-cell SUB
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ drop define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
|
|
|
ds-reg 2 bootstrap-cells SUB
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ 2drop define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
|
|
|
ds-reg 3 bootstrap-cells SUB
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ 3drop define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
2008-07-07 11:39:04 -04:00
|
|
|
ds-reg bootstrap-cell ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ dup define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg bootstrap-cell neg [+] MOV
|
2008-07-11 18:25:46 -04:00
|
|
|
ds-reg 2 bootstrap-cells ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
|
|
|
ds-reg bootstrap-cell neg [+] temp1 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ 2dup define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg -1 bootstrap-cells [+] MOV
|
|
|
|
temp3 ds-reg -2 bootstrap-cells [+] MOV
|
2008-07-11 18:25:46 -04:00
|
|
|
ds-reg 3 bootstrap-cells ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
|
|
|
ds-reg -1 bootstrap-cells [+] temp1 MOV
|
|
|
|
ds-reg -2 bootstrap-cells [+] temp3 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ 3dup define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
2008-07-07 11:39:04 -04:00
|
|
|
ds-reg bootstrap-cell SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ nip define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
2008-07-11 18:25:46 -04:00
|
|
|
ds-reg 2 bootstrap-cells SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ 2nip define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg -1 bootstrap-cells [+] MOV
|
2008-07-11 18:25:46 -04:00
|
|
|
ds-reg bootstrap-cell ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ over define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg -2 bootstrap-cells [+] MOV
|
2008-07-07 11:39:04 -04:00
|
|
|
ds-reg bootstrap-cell ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ pick define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg -1 bootstrap-cells [+] MOV
|
|
|
|
ds-reg [] temp1 MOV
|
2008-07-11 18:25:46 -04:00
|
|
|
ds-reg bootstrap-cell ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ dupd define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg -1 bootstrap-cells [+] MOV
|
2008-07-07 11:39:04 -04:00
|
|
|
ds-reg bootstrap-cell ADD
|
2008-12-09 18:14:17 -05:00
|
|
|
ds-reg [] temp0 MOV
|
|
|
|
ds-reg -1 bootstrap-cells [+] temp1 MOV
|
|
|
|
ds-reg -2 bootstrap-cells [+] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ tuck define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg bootstrap-cell neg [+] MOV
|
|
|
|
ds-reg bootstrap-cell neg [+] temp0 MOV
|
|
|
|
ds-reg [] temp1 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ swap define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg -1 bootstrap-cells [+] MOV
|
|
|
|
temp1 ds-reg -2 bootstrap-cells [+] MOV
|
|
|
|
ds-reg -2 bootstrap-cells [+] temp0 MOV
|
|
|
|
ds-reg -1 bootstrap-cells [+] temp1 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ swapd define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg -1 bootstrap-cells [+] MOV
|
|
|
|
temp3 ds-reg -2 bootstrap-cells [+] MOV
|
|
|
|
ds-reg -2 bootstrap-cells [+] temp1 MOV
|
|
|
|
ds-reg -1 bootstrap-cells [+] temp0 MOV
|
|
|
|
ds-reg [] temp3 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ rot define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
temp1 ds-reg -1 bootstrap-cells [+] MOV
|
|
|
|
temp3 ds-reg -2 bootstrap-cells [+] MOV
|
|
|
|
ds-reg -2 bootstrap-cells [+] temp0 MOV
|
|
|
|
ds-reg -1 bootstrap-cells [+] temp3 MOV
|
|
|
|
ds-reg [] temp1 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ -rot define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ jit->r ] \ load-local define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
! Comparisons
|
|
|
|
: jit-compare ( insn -- )
|
2008-12-09 18:14:17 -05:00
|
|
|
! load t
|
2009-04-25 23:35:19 -04:00
|
|
|
temp3 0 MOV rc-absolute-cell rt-immediate jit-rel
|
2008-12-09 18:14:17 -05:00
|
|
|
! load f
|
|
|
|
temp1 \ f tag-number MOV
|
|
|
|
! load first value
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! adjust stack pointer
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! compare with second value
|
|
|
|
ds-reg [] temp0 CMP
|
|
|
|
! move t if true
|
2009-04-17 18:53:26 -04:00
|
|
|
[ temp1 temp3 ] dip execute( dst src -- )
|
2008-12-09 18:14:17 -05:00
|
|
|
! store
|
|
|
|
ds-reg [] temp1 MOV ;
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
: define-jit-compare ( insn word -- )
|
2009-04-25 23:35:19 -04:00
|
|
|
[ [ jit-compare ] curry ] dip define-sub-primitive ;
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2008-11-24 09:16:14 -05:00
|
|
|
\ CMOVE \ eq? define-jit-compare
|
|
|
|
\ CMOVGE \ fixnum>= define-jit-compare
|
|
|
|
\ CMOVLE \ fixnum<= define-jit-compare
|
|
|
|
\ CMOVG \ fixnum> define-jit-compare
|
|
|
|
\ CMOVL \ fixnum< define-jit-compare
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
! Math
|
|
|
|
: jit-math ( insn -- )
|
2008-12-09 18:14:17 -05:00
|
|
|
! load second input
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! pop stack
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! compute result
|
2009-04-17 18:53:26 -04:00
|
|
|
[ ds-reg [] temp0 ] dip execute( dst src -- ) ;
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ \ ADD jit-math ] \ fixnum+fast define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ \ SUB jit-math ] \ fixnum-fast define-sub-primitive
|
2008-07-07 11:39:04 -04:00
|
|
|
|
2007-09-21 23:29:38 -04:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load second input
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! pop stack
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! load first input
|
|
|
|
temp1 ds-reg [] MOV
|
|
|
|
! untag second input
|
|
|
|
temp0 tag-bits get SAR
|
|
|
|
! multiply
|
|
|
|
temp0 temp1 IMUL2
|
|
|
|
! push result
|
|
|
|
ds-reg [] temp1 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ fixnum*fast define-sub-primitive
|
2007-09-21 23:29:38 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ \ AND jit-math ] \ fixnum-bitand define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ \ OR jit-math ] \ fixnum-bitor define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
2009-04-25 23:35:19 -04:00
|
|
|
[ \ XOR jit-math ] \ fixnum-bitxor define-sub-primitive
|
2008-07-11 18:25:46 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! complement
|
|
|
|
ds-reg [] NOT
|
|
|
|
! clear tag bits
|
|
|
|
ds-reg [] tag-mask get XOR
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ fixnum-bitnot define-sub-primitive
|
2007-09-21 23:29:38 -04:00
|
|
|
|
2008-11-03 01:03:39 -05:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load shift count
|
|
|
|
shift-arg ds-reg [] MOV
|
|
|
|
! untag shift count
|
|
|
|
shift-arg tag-bits get SAR
|
|
|
|
! adjust stack pointer
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! load value
|
|
|
|
temp3 ds-reg [] MOV
|
|
|
|
! make a copy
|
|
|
|
temp1 temp3 MOV
|
|
|
|
! compute positive shift value in temp1
|
|
|
|
temp1 CL SHL
|
|
|
|
shift-arg NEG
|
|
|
|
! compute negative shift value in temp3
|
|
|
|
temp3 CL SAR
|
|
|
|
temp3 tag-mask get bitnot AND
|
|
|
|
shift-arg 0 CMP
|
|
|
|
! if shift count was negative, move temp0 to temp1
|
|
|
|
temp1 temp3 CMOVGE
|
|
|
|
! push to stack
|
|
|
|
ds-reg [] temp1 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ fixnum-shift-fast define-sub-primitive
|
2008-11-03 01:03:39 -05:00
|
|
|
|
2008-11-23 01:09:23 -05:00
|
|
|
: jit-fixnum-/mod ( -- )
|
2008-12-09 18:14:17 -05:00
|
|
|
! load second parameter
|
|
|
|
temp3 ds-reg [] MOV
|
|
|
|
! load first parameter
|
|
|
|
div-arg ds-reg bootstrap-cell neg [+] MOV
|
|
|
|
! make a copy
|
|
|
|
mod-arg div-arg MOV
|
|
|
|
! sign-extend
|
|
|
|
mod-arg bootstrap-cell-bits 1- SAR
|
|
|
|
! divide
|
|
|
|
temp3 IDIV ;
|
2008-11-21 03:11:36 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
jit-fixnum-/mod
|
2008-12-09 18:14:17 -05:00
|
|
|
! adjust stack pointer
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! push to stack
|
|
|
|
ds-reg [] mod-arg MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ fixnum-mod define-sub-primitive
|
2008-11-03 02:18:35 -05:00
|
|
|
|
2008-11-21 03:11:36 -05:00
|
|
|
[
|
|
|
|
jit-fixnum-/mod
|
2008-12-09 18:14:17 -05:00
|
|
|
! adjust stack pointer
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! tag it
|
|
|
|
div-arg tag-bits get SHL
|
|
|
|
! push to stack
|
|
|
|
ds-reg [] div-arg MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ fixnum/i-fast define-sub-primitive
|
2008-11-21 03:11:36 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
jit-fixnum-/mod
|
2008-12-09 18:14:17 -05:00
|
|
|
! tag it
|
|
|
|
div-arg tag-bits get SHL
|
|
|
|
! push to stack
|
|
|
|
ds-reg [] mod-arg MOV
|
2008-11-21 03:11:36 -05:00
|
|
|
ds-reg bootstrap-cell neg [+] div-arg MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ fixnum/mod-fast define-sub-primitive
|
2008-11-21 03:11:36 -05:00
|
|
|
|
2008-11-28 09:35:02 -05:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] MOV
|
2008-12-06 10:16:29 -05:00
|
|
|
ds-reg bootstrap-cell SUB
|
2008-12-09 18:14:17 -05:00
|
|
|
temp0 ds-reg [] OR
|
|
|
|
temp0 tag-mask get AND
|
|
|
|
temp0 \ f tag-number MOV
|
|
|
|
temp1 1 tag-fixnum MOV
|
|
|
|
temp0 temp1 CMOVE
|
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ both-fixnums? define-sub-primitive
|
2008-11-28 09:35:02 -05:00
|
|
|
|
2008-10-23 06:49:32 -04:00
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load local number
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! turn local number into offset
|
|
|
|
fixnum>slot@
|
|
|
|
! load local value
|
|
|
|
temp0 rs-reg temp0 [+] MOV
|
|
|
|
! push to stack
|
|
|
|
ds-reg [] temp0 MOV
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ get-local define-sub-primitive
|
2008-10-23 06:49:32 -04:00
|
|
|
|
|
|
|
[
|
2008-12-09 18:14:17 -05:00
|
|
|
! load local count
|
|
|
|
temp0 ds-reg [] MOV
|
|
|
|
! adjust stack pointer
|
|
|
|
ds-reg bootstrap-cell SUB
|
|
|
|
! turn local number into offset
|
|
|
|
fixnum>slot@
|
|
|
|
! decrement retain stack pointer
|
|
|
|
rs-reg temp0 SUB
|
2009-04-25 23:35:19 -04:00
|
|
|
] \ drop-locals define-sub-primitive
|
2008-10-23 06:49:32 -04:00
|
|
|
|
2008-01-09 04:52:08 -05:00
|
|
|
[ "bootstrap.x86" forget-vocab ] with-compilation-unit
|