Clean up x86 backend: move cpu.x86.architecture to cpu.x86, use branchless arithmetic in some intrinsics
parent
10d3b4a55d
commit
8b7c47a68b
|
@ -3,7 +3,7 @@
|
||||||
USING: locals alien.c-types alien.syntax arrays kernel
|
USING: locals alien.c-types alien.syntax arrays kernel
|
||||||
math namespaces sequences system layouts io vocabs.loader
|
math namespaces sequences system layouts io vocabs.loader
|
||||||
accessors init combinators command-line cpu.x86.assembler
|
accessors init combinators command-line cpu.x86.assembler
|
||||||
cpu.x86.architecture cpu.architecture compiler compiler.units
|
cpu.x86 cpu.architecture compiler compiler.units
|
||||||
compiler.constants compiler.alien compiler.codegen
|
compiler.constants compiler.alien compiler.codegen
|
||||||
compiler.codegen.fixup compiler.cfg.instructions
|
compiler.codegen.fixup compiler.cfg.instructions
|
||||||
compiler.cfg.builder compiler.cfg.intrinsics ;
|
compiler.cfg.builder compiler.cfg.intrinsics ;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: accessors arrays kernel math namespaces make sequences
|
USING: accessors arrays kernel math namespaces make sequences
|
||||||
system layouts alien alien.c-types alien.accessors alien.structs
|
system layouts alien alien.c-types alien.accessors alien.structs
|
||||||
slots splitting assocs combinators cpu.x86.assembler
|
slots splitting assocs combinators cpu.x86.assembler
|
||||||
cpu.x86.architecture cpu.architecture compiler.constants
|
cpu.x86 cpu.architecture compiler.constants
|
||||||
compiler.codegen compiler.codegen.fixup
|
compiler.codegen compiler.codegen.fixup
|
||||||
compiler.cfg.instructions compiler.cfg.builder
|
compiler.cfg.instructions compiler.cfg.builder
|
||||||
compiler.cfg.intrinsics ;
|
compiler.cfg.intrinsics ;
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Slava Pestov
|
|
|
@ -1 +0,0 @@
|
||||||
unportable
|
|
|
@ -271,9 +271,7 @@ big-endian off
|
||||||
: jit-math ( insn -- )
|
: jit-math ( insn -- )
|
||||||
arg0 ds-reg [] MOV ! load second input
|
arg0 ds-reg [] MOV ! load second input
|
||||||
ds-reg bootstrap-cell SUB ! pop stack
|
ds-reg bootstrap-cell SUB ! pop stack
|
||||||
arg1 ds-reg [] MOV ! load first input
|
[ ds-reg [] arg0 ] dip execute ! compute result
|
||||||
[ arg1 arg0 ] dip execute ! compute result
|
|
||||||
ds-reg [] arg1 MOV ! push result
|
|
||||||
;
|
;
|
||||||
|
|
||||||
[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive
|
[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive
|
||||||
|
@ -296,10 +294,8 @@ big-endian off
|
||||||
[ \ XOR jit-math ] f f f \ fixnum-bitxor define-sub-primitive
|
[ \ XOR jit-math ] f f f \ fixnum-bitxor define-sub-primitive
|
||||||
|
|
||||||
[
|
[
|
||||||
arg0 ds-reg [] MOV ! load input input
|
ds-reg [] NOT ! complement
|
||||||
arg0 NOT ! complement
|
ds-reg [] tag-mask get XOR ! clear tag bits
|
||||||
arg0 tag-mask get XOR ! clear tag bits
|
|
||||||
ds-reg [] arg0 MOV ! save
|
|
||||||
] f f f \ fixnum-bitnot define-sub-primitive
|
] f f f \ fixnum-bitnot define-sub-primitive
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -7,7 +7,7 @@ words system layouts combinators math.order fry locals
|
||||||
compiler.constants compiler.cfg.registers
|
compiler.constants compiler.cfg.registers
|
||||||
compiler.cfg.instructions compiler.codegen
|
compiler.cfg.instructions compiler.codegen
|
||||||
compiler.codegen.fixup ;
|
compiler.codegen.fixup ;
|
||||||
IN: cpu.x86.architecture
|
IN: cpu.x86
|
||||||
|
|
||||||
M: x86 two-operand? t ;
|
M: x86 two-operand? t ;
|
||||||
|
|
||||||
|
@ -111,49 +111,54 @@ M:: x86 %integer>bignum ( dst src temp -- )
|
||||||
#! 1 cell header, 1 cell length, 1 cell sign, + digits
|
#! 1 cell header, 1 cell length, 1 cell sign, + digits
|
||||||
#! length is the # of digits + sign
|
#! length is the # of digits + sign
|
||||||
[
|
[
|
||||||
{ "end" "nonzero" "positive" } [ define-label ] each
|
"end" define-label
|
||||||
src 0 CMP ! is it zero?
|
! Load cached zero value
|
||||||
"nonzero" get JNE
|
|
||||||
! Use cached zero value
|
|
||||||
dst 0 >bignum %load-indirect
|
dst 0 >bignum %load-indirect
|
||||||
"end" get JMP
|
src 0 CMP
|
||||||
"nonzero" resolve-label
|
! Is it zero? Then just go to the end and return this zero
|
||||||
|
"end" get JE
|
||||||
! Allocate a bignum
|
! Allocate a bignum
|
||||||
dst 4 cells bignum temp %allot
|
dst 4 cells bignum temp %allot
|
||||||
! Write length
|
! Write length
|
||||||
dst 1 bignum@ 2 tag-fixnum MOV
|
dst 1 bignum@ 2 tag-fixnum MOV
|
||||||
! Test sign
|
! Store value
|
||||||
src 0 CMP
|
|
||||||
"positive" get JGE
|
|
||||||
dst 2 bignum@ 1 MOV ! negative sign
|
|
||||||
src NEG
|
|
||||||
dst 3 bignum@ src MOV
|
|
||||||
src NEG ! we don't want to clobber src
|
|
||||||
"end" get JMP
|
|
||||||
"positive" resolve-label
|
|
||||||
dst 2 bignum@ 0 MOV ! positive sign
|
|
||||||
dst 3 bignum@ src MOV
|
dst 3 bignum@ src MOV
|
||||||
|
! Compute sign
|
||||||
|
temp src MOV
|
||||||
|
temp cell-bits 1- SAR
|
||||||
|
temp 1 AND
|
||||||
|
! Store sign
|
||||||
|
dst 2 bignum@ temp MOV
|
||||||
|
! Make negative value positive
|
||||||
|
temp temp ADD
|
||||||
|
temp NEG
|
||||||
|
temp 1 ADD
|
||||||
|
src temp IMUL2
|
||||||
|
! Store the bignum
|
||||||
|
dst 3 bignum@ temp MOV
|
||||||
"end" resolve-label
|
"end" resolve-label
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
M:: x86 %bignum>integer ( dst src -- )
|
M:: x86 %bignum>integer ( dst src temp -- )
|
||||||
[
|
[
|
||||||
"nonzero" define-label
|
|
||||||
"end" define-label
|
"end" define-label
|
||||||
dst src 1 bignum@ MOV
|
! load length
|
||||||
|
temp src 1 bignum@ MOV
|
||||||
! if the length is 1, its just the sign and nothing else,
|
! if the length is 1, its just the sign and nothing else,
|
||||||
! so output 0
|
! so output 0
|
||||||
dst 1 tag-fixnum CMP
|
|
||||||
"nonzero" get JNE
|
|
||||||
dst 0 MOV
|
dst 0 MOV
|
||||||
"end" get JMP
|
temp 1 tag-fixnum CMP
|
||||||
"nonzero" resolve-label
|
"end" get JE
|
||||||
! load the value
|
! load the value
|
||||||
dst src 3 bignum@ MOV
|
dst src 3 bignum@ MOV
|
||||||
! is the sign negative?
|
! load the sign
|
||||||
src 2 bignum@ 0 CMP
|
temp src 2 bignum@ MOV
|
||||||
"end" get JE
|
! convert it into -1 or 1
|
||||||
dst NEG
|
temp temp ADD
|
||||||
|
temp NEG
|
||||||
|
temp 1 ADD
|
||||||
|
! make dst signed
|
||||||
|
temp dst IMUL2
|
||||||
"end" resolve-label
|
"end" resolve-label
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
|
@ -206,21 +211,19 @@ M:: x86 %box-float ( dst src temp -- )
|
||||||
dst 16 float temp %allot
|
dst 16 float temp %allot
|
||||||
dst float-offset [+] src MOVSD ;
|
dst float-offset [+] src MOVSD ;
|
||||||
|
|
||||||
: alien@ ( reg n -- op ) cells object tag-number - [+] ;
|
: alien@ ( reg n -- op ) cells alien tag-number - [+] ;
|
||||||
|
|
||||||
M:: x86 %box-alien ( dst src temp -- )
|
M:: x86 %box-alien ( dst src temp -- )
|
||||||
[
|
[
|
||||||
{ "end" "f" } [ define-label ] each
|
"end" define-label
|
||||||
|
dst \ f tag-number MOV
|
||||||
src 0 CMP
|
src 0 CMP
|
||||||
"f" get JE
|
"end" get JE
|
||||||
dst 4 cells alien temp %allot
|
dst 4 cells alien temp %allot
|
||||||
dst 1 alien@ \ f tag-number MOV
|
dst 1 alien@ \ f tag-number MOV
|
||||||
dst 2 alien@ \ f tag-number MOV
|
dst 2 alien@ \ f tag-number MOV
|
||||||
! Store src in alien-offset slot
|
! Store src in alien-offset slot
|
||||||
dst 3 alien@ src MOV
|
dst 3 alien@ src MOV
|
||||||
"end" get JMP
|
|
||||||
"f" resolve-label
|
|
||||||
dst \ f tag-number MOV
|
|
||||||
"end" resolve-label
|
"end" resolve-label
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
|
@ -339,7 +342,7 @@ M: x86 %set-alien-double [ [] ] dip MOVSD ;
|
||||||
: inc-allot-ptr ( nursery-ptr n -- )
|
: inc-allot-ptr ( nursery-ptr n -- )
|
||||||
[ cell [+] ] dip 8 align ADD ;
|
[ cell [+] ] dip 8 align ADD ;
|
||||||
|
|
||||||
: store-header ( temp type -- )
|
: store-header ( temp class -- )
|
||||||
[ [] ] [ type-number tag-fixnum ] bi* MOV ;
|
[ [] ] [ type-number tag-fixnum ] bi* MOV ;
|
||||||
|
|
||||||
: store-tagged ( dst tag -- )
|
: store-tagged ( dst tag -- )
|
||||||
|
@ -463,11 +466,10 @@ M: x86 %compare-float-branch ( label cc src1 src2 -- )
|
||||||
M: x86 %spill-integer ( src n -- ) spill-integer@ swap MOV ;
|
M: x86 %spill-integer ( src n -- ) spill-integer@ swap MOV ;
|
||||||
M: x86 %reload-integer ( dst n -- ) spill-integer@ MOV ;
|
M: x86 %reload-integer ( dst n -- ) spill-integer@ MOV ;
|
||||||
|
|
||||||
M: x86 %spill-float spill-float@ swap MOVSD ;
|
M: x86 %spill-float ( src n -- ) spill-float@ swap MOVSD ;
|
||||||
M: x86 %reload-float spill-float@ MOVSD ;
|
M: x86 %reload-float ( dst n -- ) spill-float@ MOVSD ;
|
||||||
|
|
||||||
M: x86 %loop-entry
|
M: x86 %loop-entry 16 code-alignment [ NOP ] times ;
|
||||||
16 code-alignment [ NOP ] times ;
|
|
||||||
|
|
||||||
M: int-regs %save-param-reg drop >r stack@ r> MOV ;
|
M: int-regs %save-param-reg drop >r stack@ r> MOV ;
|
||||||
M: int-regs %load-param-reg drop swap stack@ MOV ;
|
M: int-regs %load-param-reg drop swap stack@ MOV ;
|
Loading…
Reference in New Issue