cpu.x86: remove use of with-scope in favor of locals.

db4
John Benediktsson 2015-06-15 09:10:52 -07:00
parent aeaed40d9c
commit 255b60ef8d
1 changed files with 71 additions and 85 deletions

View File

@ -193,12 +193,11 @@ M: x86 %unbox-alien ( dst src -- )
alien-offset [+] MOV ; alien-offset [+] MOV ;
M:: x86 %unbox-any-c-ptr ( dst src -- ) M:: x86 %unbox-any-c-ptr ( dst src -- )
[ <label> :> end
"end" define-label
dst dst XOR dst dst XOR
! Is the object f? ! Is the object f?
src \ f type-number CMP src \ f type-number CMP
"end" get JE end JE
! Compute tag in dst register ! Compute tag in dst register
dst src MOV dst src MOV
dst tag-mask get AND dst tag-mask get AND
@ -206,27 +205,24 @@ M:: x86 %unbox-any-c-ptr ( dst src -- )
dst alien type-number CMP dst alien type-number CMP
! Add an offset to start of byte array's data ! Add an offset to start of byte array's data
dst src byte-array-offset [+] LEA dst src byte-array-offset [+] LEA
"end" get JNE end JNE
! If so, load the offset and add it to the address ! If so, load the offset and add it to the address
dst src alien-offset [+] MOV dst src alien-offset [+] MOV
"end" resolve-label end resolve-label ;
] with-scope ;
: alien@ ( reg n -- op ) cells alien type-number - [+] ; : alien@ ( reg n -- op ) cells alien type-number - [+] ;
M:: x86 %box-alien ( dst src temp -- ) M:: x86 %box-alien ( dst src temp -- )
[ <label> :> end
"end" define-label
dst \ f type-number MOV dst \ f type-number MOV
src src TEST src src TEST
"end" get JE end JE
dst 5 cells alien temp %allot dst 5 cells alien temp %allot
dst 1 alien@ \ f type-number MOV ! base dst 1 alien@ \ f type-number MOV ! base
dst 2 alien@ \ f type-number MOV ! expired dst 2 alien@ \ f type-number MOV ! expired
dst 3 alien@ src MOV ! displacement dst 3 alien@ src MOV ! displacement
dst 4 alien@ src MOV ! address dst 4 alien@ src MOV ! address
"end" resolve-label end resolve-label ;
] with-scope ;
:: %box-displaced-alien/f ( dst displacement -- ) :: %box-displaced-alien/f ( dst displacement -- )
dst 1 alien@ \ f type-number MOV dst 1 alien@ \ f type-number MOV
@ -254,9 +250,9 @@ M:: x86 %box-alien ( dst src temp -- )
temp base displacement byte-array-offset [++] LEA temp base displacement byte-array-offset [++] LEA
dst 4 alien@ temp MOV ; dst 4 alien@ temp MOV ;
:: %box-displaced-alien/dynamic ( dst displacement base temp -- ) :: %box-displaced-alien/dynamic ( dst displacement base temp end -- )
"not-f" define-label <label> :> not-f
"not-alien" define-label <label> :> not-alien
! Check base type ! Check base type
temp base MOV temp base MOV
@ -264,37 +260,36 @@ M:: x86 %box-alien ( dst src temp -- )
! Is base f? ! Is base f?
temp \ f type-number CMP temp \ f type-number CMP
"not-f" get JNE not-f JNE
! Yes, it is f. Fill in new object ! Yes, it is f. Fill in new object
dst displacement %box-displaced-alien/f dst displacement %box-displaced-alien/f
"end" get JMP end JMP
"not-f" resolve-label not-f resolve-label
! Is base an alien? ! Is base an alien?
temp alien type-number CMP temp alien type-number CMP
"not-alien" get JNE not-alien JNE
dst displacement base temp %box-displaced-alien/alien dst displacement base temp %box-displaced-alien/alien
! We are done ! We are done
"end" get JMP end JMP
! Is base a byte array? It has to be, by now... ! Is base a byte array? It has to be, by now...
"not-alien" resolve-label not-alien resolve-label
dst displacement base temp %box-displaced-alien/byte-array ; dst displacement base temp %box-displaced-alien/byte-array ;
M:: x86 %box-displaced-alien ( dst displacement base temp base-class -- ) M:: x86 %box-displaced-alien ( dst displacement base temp base-class -- )
[ <label> :> end
"end" define-label
! If displacement is zero, return the base ! If displacement is zero, return the base
dst base MOV dst base MOV
displacement displacement TEST displacement displacement TEST
"end" get JE end JE
! Displacement is non-zero, we're going to be allocating a new ! Displacement is non-zero, we're going to be allocating a new
! object ! object
@ -308,11 +303,10 @@ M:: x86 %box-displaced-alien ( dst displacement base temp base-class -- )
{ [ base-class \ f class<= ] [ 2drop %box-displaced-alien/f ] } { [ base-class \ f class<= ] [ 2drop %box-displaced-alien/f ] }
{ [ base-class \ alien class<= ] [ %box-displaced-alien/alien ] } { [ base-class \ alien class<= ] [ %box-displaced-alien/alien ] }
{ [ base-class \ byte-array class<= ] [ %box-displaced-alien/byte-array ] } { [ base-class \ byte-array class<= ] [ %box-displaced-alien/byte-array ] }
[ %box-displaced-alien/dynamic ] [ end %box-displaced-alien/dynamic ]
} cond } cond
"end" resolve-label end resolve-label ;
] with-scope ;
! The 'small-reg' mess is pretty crappy, but its only used on x86-32. ! The 'small-reg' mess is pretty crappy, but its only used on x86-32.
! On x86-64, all registers have 8-bit versions. However, a similar ! On x86-64, all registers have 8-bit versions. However, a similar
@ -707,26 +701,20 @@ M: x86 immediate-arithmetic? ( n -- ? )
M: x86 immediate-bitwise? ( n -- ? ) M: x86 immediate-bitwise? ( n -- ? )
-0x80000000 0x7fffffff between? ; -0x80000000 0x7fffffff between? ;
: %cmov-float= ( dst src -- ) :: %cmov-float= ( dst src -- )
[ <label> :> no-move
"no-move" define-label no-move [ JNE ] [ JP ] bi
dst src MOV
no-move resolve-label ;
"no-move" get [ JNE ] [ JP ] bi :: %cmov-float/= ( dst src -- )
MOV <label> :> no-move
"no-move" resolve-label <label> :> move
] with-scope ; move JP
no-move JE
: %cmov-float/= ( dst src -- ) move resolve-label
[ dst src MOV
"no-move" define-label no-move resolve-label ;
"move" define-label
"move" get JP
"no-move" get JE
"move" resolve-label
MOV
"no-move" resolve-label
] with-scope ;
:: (%compare-float) ( dst src1 src2 cc temp compare -- ) :: (%compare-float) ( dst src1 src2 cc temp compare -- )
cc { cc {
@ -746,13 +734,11 @@ M: x86 immediate-bitwise? ( n -- ? )
{ cc/<>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVP (%boolean) ] } { cc/<>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVP (%boolean) ] }
} case ; inline } case ; inline
: %jump-float= ( label -- ) :: %jump-float= ( label -- )
[ <label> :> no-jump
"no-jump" define-label no-jump JP
"no-jump" get JP label JE
JE no-jump resolve-label ;
"no-jump" resolve-label
] with-scope ;
: %jump-float/= ( label -- ) : %jump-float/= ( label -- )
[ JNE ] [ JP ] bi ; [ JNE ] [ JP ] bi ;