cpu.architecture: new docs

char-rename
Björn Lindqvist 2016-08-08 10:37:50 +02:00
parent 1b6e6915ac
commit ceb0f61c2b
2 changed files with 129 additions and 93 deletions

View File

@ -1,4 +1,4 @@
USING: alien assocs classes compiler.cfg.instructions USING: alien assocs byte-arrays classes compiler.cfg.instructions
compiler.cfg.registers compiler.cfg.stack-frame cpu.x86.assembler compiler.cfg.registers compiler.cfg.stack-frame cpu.x86.assembler
cpu.x86.assembler.operands help.markup help.syntax kernel layouts cpu.x86.assembler.operands help.markup help.syntax kernel layouts
literals math multiline sequences strings system vm words ; literals math multiline sequences strings system vm words ;
@ -133,6 +133,10 @@ HELP: %call
{ $values { "word" word } } { $values { "word" word } }
{ $description "Emits code for calling a Factor word." } ; { $description "Emits code for calling a Factor word." } ;
HELP: %c-invoke
{ $values { "symbols" byte-array } { "dll" dll } { "gc-map" gc-map } }
{ $description "Emits code for calling an FFI function." } ;
HELP: %context HELP: %context
{ $values { "dst" "a register symbol" } } { $values { "dst" "a register symbol" } }
{ $description "Emits machine code for putting a pointer to the context field of the " { $link vm } " in a register." } { $description "Emits machine code for putting a pointer to the context field of the " { $link vm } " in a register." }
@ -203,6 +207,10 @@ HELP: %local-allot
{ $description "Emits machine code for stack \"allocating\" a chunk of memory. No memory is really allocated and instead a pointer to it is just put in the destination register." } { $description "Emits machine code for stack \"allocating\" a chunk of memory. No memory is really allocated and instead a pointer to it is just put in the destination register." }
{ $see-also ##local-allot } ; { $see-also ##local-allot } ;
HELP: reg-class-of
{ $values { "rep" representation } { "reg-class" reg-class } }
{ $description "Register class for values of the given representation." } ;
HELP: %replace-imm HELP: %replace-imm
{ $values { $values
{ "src" integer } { "src" integer }
@ -275,6 +283,9 @@ HELP: %test-imm-branch
{ "cc" "comparison symbol" } { "cc" "comparison symbol" }
} { $description "Emits a TEST instruction with a register and an immediate, followed by a branch." } ; } { $description "Emits a TEST instruction with a register and an immediate, followed by a branch." } ;
HELP: %unbox
{ $description "Call a function to convert a tagged pointer into a value that can be passed to a C function, or returned from a callback." } ;
HELP: %vector>scalar HELP: %vector>scalar
{ $values { $values
{ "dst" "destination register" } { "dst" "destination register" }
@ -295,16 +306,29 @@ HELP: %write-barrier
{ $description "Generates code for the " { $link ##write-barrier } " instruction." } { $description "Generates code for the " { $link ##write-barrier } " instruction." }
{ $examples { $unchecked-example $[ ex-%write-barrier ] } } ; { $examples { $unchecked-example $[ ex-%write-barrier ] } } ;
HELP: complex-addressing?
{ $values { "?" boolean } }
{ $description "Specifies if " { $link %slot } ", " { $link %set-slot } " and " { $link %write-barrier } " accept the 'scale' and 'tag' parameters, and if %load-memory and %store-memory work." } ;
HELP: double-2-rep HELP: double-2-rep
{ $var-description "Representation for a pair of doubles." } ; { $var-description "Representation for a pair of doubles." } ;
HELP: signed-rep HELP: dummy-fp-params?
{ $values { "rep" representation } { "rep'" representation } } { $values { "?" boolean } }
{ $description "Maps any representation to its signed counterpart, if it has one." } ; { $description "Whether the architecture's ABI uses dummy floating point parameters. If it does, then the corresponding floating point register is 'dummy allocated' when an integer register is allocated." } { $see-also dummy-int-params? } ;
HELP: rep-size HELP: dummy-int-params?
{ $values { "rep" representation } { "n" integer } } { $values { "?" boolean } }
{ $description "Size in bytes of a representation." } ; { $description "Whether the architecture's ABI uses dummy integer parameters. If it does, then the corresponding integer register is 'dummy allocated' when a floating point register is allocated." } { $see-also dummy-fp-params? } ;
HELP: fused-unboxing?
{ $values { "?" boolean } }
{ $description "Whether this architecture support " { $link %load-float } ", " { $link %load-double } ", and " { $link %load-vector } "." } ;
HELP: gc-root-offset
{ $values { "spill-slot" spill-slot } { "n" integer } }
{ $description "Offset in the " { $link stack-frame } " for the word being constructed where the spill slot is located. The value is given in " { $link cell } " units." }
{ $see-also gc-info } ;
HELP: immediate-arithmetic? HELP: immediate-arithmetic?
{ $values { "n" number } { "?" boolean } } { $values { "n" number } { "?" boolean } }
@ -313,28 +337,29 @@ HELP: immediate-arithmetic?
{ $link %sub-imm } ", or " { $link %mul-imm } "?" { $link %sub-imm } ", or " { $link %mul-imm } "?"
} ; } ;
HELP: immediate-bitwise?
{ $values { "n" number } { "?" boolean } }
{ $description "Can this value be an immediate operand for %and-imm, %or-imm, or %xor-imm?" } ;
HELP: immediate-comparand?
{ $values { "n" number } { "?" boolean } }
{ $description "Can this value be an immediate operand for %compare-imm or %compare-imm-branch?" } ;
HELP: immediate-store?
{ $values { "n" number } { "?" boolean } }
{ $description "Can this value be an immediate operand for %replace-imm?" } ;
HELP: machine-registers HELP: machine-registers
{ $values { "assoc" assoc } } { $values { "assoc" assoc } }
{ $description "Mapping from register class to machine registers. Only registers not reserved by the Factor VM are included." } ; { $description "Mapping from register class to machine registers. Only registers not reserved by the Factor VM are included." } ;
HELP: vm-stack-space
{ $values { "n" number } }
{ $description "Parameter space to reserve in anything making VM calls." } ;
HELP: complex-addressing?
{ $values { "?" boolean } }
{ $description "Specifies if " { $link %slot } ", " { $link %set-slot } " and " { $link %write-barrier } " accept the 'scale' and 'tag' parameters, and if %load-memory and %store-memory work." } ;
HELP: param-regs HELP: param-regs
{ $values { "abi" "a calling convention symbol" } { "regs" assoc } } { $values { "abi" "a calling convention symbol" } { "regs" assoc } }
{ $description "Retrieves the order in which machine registers are used for parameters for the given calling convention." } ; { $description "Retrieves the order in which machine registers are used for parameters for the given calling convention." } ;
HELP: test-instruction?
{ $values { "?" boolean } }
{ $description "Does the current architecture have a test instruction? Used on x86 to rewrite some " { $link CMP } " instructions to less expensive " { $link TEST } "s." } ;
HELP: fused-unboxing? HELP: rep-size
{ $values { "?" boolean } } { $values { "rep" representation } { "n" integer } }
{ $description "Whether this architecture support " { $link %load-float } ", " { $link %load-double } ", and " { $link %load-vector } "." } ; { $description "Size in bytes of a representation." } ;
HELP: return-regs HELP: return-regs
{ $values { "regs" assoc } } { $values { "regs" assoc } }
@ -344,6 +369,10 @@ HELP: return-struct-in-registers?
{ $values { "c-type" class } { "?" boolean } } { $values { "c-type" class } { "?" boolean } }
{ $description "Whether the size of the struct is so small that it will be returned in registers or not." } ; { $description "Whether the size of the struct is so small that it will be returned in registers or not." } ;
HELP: signed-rep
{ $values { "rep" representation } { "rep'" representation } }
{ $description "Maps any representation to its signed counterpart, if it has one." } ;
HELP: stack-cleanup HELP: stack-cleanup
{ $values { $values
{ "stack-size" integer } { "stack-size" integer }
@ -360,10 +389,13 @@ HELP: stack-cleanup
} }
} ; } ;
HELP: gc-root-offset HELP: test-instruction?
{ $values { "spill-slot" spill-slot } { "n" integer } } { $values { "?" boolean } }
{ $description "Offset in the " { $link stack-frame } " for the word being constructed where the spill slot is located. The value is given in " { $link cell } " units." } { $description "Does the current architecture have a test instruction? Used on x86 to rewrite some " { $link CMP } " instructions to less expensive " { $link TEST } "s." } ;
{ $see-also gc-info } ;
HELP: vm-stack-space
{ $values { "n" number } }
{ $description "Parameter space to reserve in anything making VM calls." } ;
ARTICLE: "cpu.architecture" "CPU architecture description model" ARTICLE: "cpu.architecture" "CPU architecture description model"
"The " { $vocab-link "cpu.architecture" } " vocab contains generic words and hooks that serves as an api for the compiler towards the cpu architecture." "The " { $vocab-link "cpu.architecture" } " vocab contains generic words and hooks that serves as an api for the compiler towards the cpu architecture."
@ -371,19 +403,28 @@ $nl
"Architecture support checks:" "Architecture support checks:"
{ $subsections { $subsections
complex-addressing? complex-addressing?
dummy-int-params?
dummy-fp-params?
float-right-align-on-stack? float-right-align-on-stack?
fused-unboxing? fused-unboxing?
test-instruction? test-instruction?
} }
"Control flow code emitters:" "Control flow code emitters:"
{ $subsections %call %jump %jump-label %return } { $subsections %call %jump %jump-label %return }
"Foreign function interface:"
{ $subsections %c-invoke }
"Moving values around:" "Moving values around:"
{ $subsections %replace %replace-imm } { $subsections %replace %replace-imm }
"Register categories:" "Register categories:"
{ $subsections machine-registers param-regs return-regs } { $subsections
machine-registers
param-regs
return-regs
}
"Representation metadata:" "Representation metadata:"
{ $subsections { $subsections
narrow-vector-rep narrow-vector-rep
reg-class-of
rep-component-type rep-component-type
rep-length rep-length
rep-size rep-size
@ -400,6 +441,14 @@ $nl
%write-barrier %write-barrier
} }
"Spilling:" "Spilling:"
{ $subsections gc-root-offset } ; { $subsections gc-root-offset }
"Value as immediate checks:"
{ $subsections
immediate-arithmetic?
immediate-bitwise?
immediate-comparand?
immediate-store?
immediate-shift-count?
} ;
ABOUT: "cpu.architecture" ABOUT: "cpu.architecture"

View File

@ -23,69 +23,69 @@ SINGLETONS: float-rep double-rep ;
! On x86, floating point registers are really vector registers ! On x86, floating point registers are really vector registers
SINGLETONS: SINGLETONS:
char-16-rep char-16-rep
uchar-16-rep uchar-16-rep
short-8-rep short-8-rep
ushort-8-rep ushort-8-rep
int-4-rep int-4-rep
uint-4-rep uint-4-rep
longlong-2-rep longlong-2-rep
ulonglong-2-rep ; ulonglong-2-rep ;
! Scalar values in the high component of a vector register ! Scalar values in the high component of a vector register
SINGLETONS: SINGLETONS:
char-scalar-rep char-scalar-rep
uchar-scalar-rep uchar-scalar-rep
short-scalar-rep short-scalar-rep
ushort-scalar-rep ushort-scalar-rep
int-scalar-rep int-scalar-rep
uint-scalar-rep uint-scalar-rep
longlong-scalar-rep longlong-scalar-rep
ulonglong-scalar-rep ; ulonglong-scalar-rep ;
SINGLETONS: SINGLETONS:
float-4-rep float-4-rep
double-2-rep ; double-2-rep ;
UNION: int-vector-rep UNION: int-vector-rep
char-16-rep char-16-rep
uchar-16-rep uchar-16-rep
short-8-rep short-8-rep
ushort-8-rep ushort-8-rep
int-4-rep int-4-rep
uint-4-rep uint-4-rep
longlong-2-rep longlong-2-rep
ulonglong-2-rep ; ulonglong-2-rep ;
UNION: signed-int-vector-rep UNION: signed-int-vector-rep
char-16-rep char-16-rep
short-8-rep short-8-rep
int-4-rep int-4-rep
longlong-2-rep ; longlong-2-rep ;
UNION: unsigned-int-vector-rep UNION: unsigned-int-vector-rep
uchar-16-rep uchar-16-rep
ushort-8-rep ushort-8-rep
uint-4-rep uint-4-rep
ulonglong-2-rep ; ulonglong-2-rep ;
UNION: scalar-rep UNION: scalar-rep
char-scalar-rep char-scalar-rep
uchar-scalar-rep uchar-scalar-rep
short-scalar-rep short-scalar-rep
ushort-scalar-rep ushort-scalar-rep
int-scalar-rep int-scalar-rep
uint-scalar-rep uint-scalar-rep
longlong-scalar-rep longlong-scalar-rep
ulonglong-scalar-rep ; ulonglong-scalar-rep ;
UNION: float-vector-rep UNION: float-vector-rep
float-4-rep float-4-rep
double-2-rep ; double-2-rep ;
UNION: vector-rep UNION: vector-rep
int-vector-rep int-vector-rep
float-vector-rep ; float-vector-rep ;
CONSTANT: vector-reps CONSTANT: vector-reps
{ {
@ -102,13 +102,13 @@ CONSTANT: vector-reps
} }
UNION: representation UNION: representation
any-rep any-rep
tagged-rep tagged-rep
int-rep int-rep
float-rep float-rep
double-rep double-rep
vector-rep vector-rep
scalar-rep ; scalar-rep ;
: signed-rep ( rep -- rep' ) : signed-rep ( rep -- rep' )
{ {
@ -520,16 +520,8 @@ HOOK: %reload cpu ( dst rep src -- )
HOOK: fused-unboxing? cpu ( -- ? ) HOOK: fused-unboxing? cpu ( -- ? )
HOOK: immediate-arithmetic? cpu ( n -- ? ) HOOK: immediate-arithmetic? cpu ( n -- ? )
! Can this value be an immediate operand for %and-imm, %or-imm,
! or %xor-imm?
HOOK: immediate-bitwise? cpu ( n -- ? ) HOOK: immediate-bitwise? cpu ( n -- ? )
! Can this value be an immediate operand for %compare-imm or
! %compare-imm-branch?
HOOK: immediate-comparand? cpu ( n -- ? ) HOOK: immediate-comparand? cpu ( n -- ? )
! Can this value be an immediate operand for %replace-imm?
HOOK: immediate-store? cpu ( obj -- ? ) HOOK: immediate-store? cpu ( obj -- ? )
M: object immediate-comparand? ( n -- ? ) M: object immediate-comparand? ( n -- ? )
@ -556,10 +548,7 @@ HOOK: value-struct? cpu ( c-type -- ? )
! If t, all parameters are shadowed by dummy stack parameters ! If t, all parameters are shadowed by dummy stack parameters
HOOK: dummy-stack-params? cpu ( -- ? ) HOOK: dummy-stack-params? cpu ( -- ? )
! If t, all FP parameters are shadowed by dummy int parameters
HOOK: dummy-int-params? cpu ( -- ? ) HOOK: dummy-int-params? cpu ( -- ? )
! If t, all int parameters are shadowed by dummy FP parameters
HOOK: dummy-fp-params? cpu ( -- ? ) HOOK: dummy-fp-params? cpu ( -- ? )
! If t, long longs are never passed in param regs ! If t, long longs are never passed in param regs
@ -577,8 +566,6 @@ HOOK: float-right-align-on-stack? cpu ( -- ? )
! If t, the struct return pointer is never passed in a param reg ! If t, the struct return pointer is never passed in a param reg
HOOK: struct-return-on-stack? cpu ( -- ? ) HOOK: struct-return-on-stack? cpu ( -- ? )
! Call a function to convert a tagged pointer into a value that
! can be passed to a C function, or returned from a callback
HOOK: %unbox cpu ( dst src func rep -- ) HOOK: %unbox cpu ( dst src func rep -- )
HOOK: %unbox-long-long cpu ( dst1 dst2 src func -- ) HOOK: %unbox-long-long cpu ( dst1 dst2 src func -- )