factor/library/compiler/amd64/architecture.factor

53 lines
1.5 KiB
Factor
Raw Normal View History

2006-01-24 19:56:08 -05:00
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2005-12-02 01:23:09 -05:00
IN: compiler-backend
USING: alien arrays assembler compiler compiler-backend kernel
2005-12-24 16:08:15 -05:00
kernel-internals math sequences ;
2005-12-02 01:23:09 -05:00
! AMD64 register assignments
! RAX RCX RDX RSI RDI R8 R9 R10 R11 vregs
2005-12-04 02:30:19 -05:00
! R14 datastack
! R15 callstack
2005-12-02 01:23:09 -05:00
: fixnum-imm? ( -- ? )
#! Can fixnum operations take immediate operands?
2005-12-04 14:30:28 -05:00
f ; inline
2005-12-02 01:23:09 -05:00
2005-12-07 00:14:24 -05:00
: ds-reg R14 ; inline
: cs-reg R15 ; inline
: remainder-reg RDX ; inline
2005-12-04 22:06:12 -05:00
: vregs { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; inline
2005-12-02 01:23:09 -05:00
2005-12-10 03:03:45 -05:00
: param-regs { RDI RSI RDX RCX R8 R9 } ; inline
2005-12-10 01:02:13 -05:00
2005-12-10 01:27:41 -05:00
: compile-c-call ( symbol dll -- )
2005-12-11 15:14:41 -05:00
2dup dlsym 0 scratch swap MOV
rel-absolute-cell rel-dlsym 0 scratch CALL ;
2005-12-10 01:02:13 -05:00
: compile-c-call* ( symbol dll -- operands )
param-regs swap [ MOV ] 2each compile-c-call ;
2005-12-24 16:08:15 -05:00
M: int-regs return-reg drop RAX ;
2006-01-20 21:37:38 -05:00
M: int-regs fastcall-regs drop param-regs length ;
2005-12-24 16:08:15 -05:00
2005-12-02 01:23:09 -05:00
M: float-regs fastcall-regs drop 0 ;
: dual-fp/int-regs? f ;
2005-12-04 22:55:02 -05:00
: address-operand ( address -- operand )
#! On AMD64, we have to load 64-bit addresses into a
2005-12-07 03:37:05 -05:00
#! scratch register first. The usage of R11 here is a hack.
#! We cannot write '0 scratch' since scratch registers are
#! not permitted inside basic-block VOPs.
R11 [ swap MOV ] keep ; inline
2005-12-04 22:55:02 -05:00
: fixnum>slot@ drop ; inline
2005-12-07 03:37:05 -05:00
: prepare-division CQO ; inline
: load-indirect ( dest literal -- )
#! We use RIP-relative addressing. The '3' is a hardcoded
#! instruction length.
add-literal from 3 - 1array MOV ; inline