<commit_before>! Copyright (C) 2005, 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays kernel math namespaces make sequences
system layouts alien alien.c-types alien.accessors alien.libraries
slots splitting assocs combinators fry locals compiler.constants
classes.struct compiler.codegen compiler.codegen.fixup
compiler.cfg.instructions compiler.cfg.builder
compiler.cfg.intrinsics compiler.cfg.stack-frame
cpu.x86.assembler cpu.x86.assembler.operands cpu.x86
cpu.architecture vm ;
FROM: layouts => cell cells ;
IN: cpu.x86.64

: param-reg ( n -- reg ) int-regs cdecl param-regs at nth ;

: param-reg-0 ( -- reg ) 0 param-reg ; inline
: param-reg-1 ( -- reg ) 1 param-reg ; inline
: param-reg-2 ( -- reg ) 2 param-reg ; inline
: param-reg-3 ( -- reg ) 3 param-reg ; inline

M: x86.64 pic-tail-reg RBX ;

M: x86.64 return-regs
    {
        { int-regs { RAX EDX } }
        { float-regs { XMM0 XMM1 } }
    } ;

M: x86.64 ds-reg R14 ;
M: x86.64 rs-reg R15 ;
M: x86.64 stack-reg RSP ;
M: x86.64 frame-reg RBP ;

M: x86.64 machine-registers
    {
        { int-regs { RAX RCX RDX RBX RBP RSI RDI R8 R9 R10 R11 R12 } }
        { float-regs {
            XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7
            XMM8 XMM9 XMM10 XMM11 XMM12 XMM13 XMM14 XMM15
        } }
    } ;

: vm-reg ( -- reg ) R13 ; inline
: nv-reg ( -- reg ) RBX ; inline

M: x86.64 %mov-vm-ptr ( reg -- )
    vm-reg MOV ;

M: x86.64 %vm-field ( dst offset -- )
    [ vm-reg ] dip [+] MOV ;

M:: x86.64 %load-vector ( dst val rep -- )
    dst 0 [RIP+] rep copy-memory* val rc-relative rel-binary-literal ;

M: x86.64 %set-vm-field ( src offset -- )
    [ vm-reg ] dip [+] swap MOV ;

M: x86.64 %vm-field-ptr ( dst offset -- )
    [ vm-reg ] dip [+] LEA ;

M: x86.64 %prologue ( n -- )
    R11 -7 [RIP+] LEA
    dup PUSH
    R11 PUSH
    stack-reg swap 3 cells - SUB ;

M: x86.64 %prepare-jump
    pic-tail-reg xt-tail-pic-offset [RIP+] LEA ;

: load-cards-offset ( dst -- )
    0 MOV rc-absolute-cell rel-cards-offset ;

M: x86.64 %mark-card
    dup load-cards-offset
    [+] card-mark <byte> MOV ;

: load-decks-offset ( dst -- )
    0 MOV rc-absolute-cell rel-decks-offset ;

M: x86.64 %mark-deck
    dup load-decks-offset
    [+] card-mark <byte> MOV ;

M:: x86.64 %load-stack-param ( vreg rep n -- )
    rep return-reg n next-stack@ rep %copy
    dst rep return-reg rep %copy ;

M:: x86.64 %store-stack-param ( vreg rep n -- )
    rep return-reg src rep %copy
    n reserved-stack-space + stack@ rep return-reg rep %copy ;

M:: x86.64 %load-reg-param ( vreg rep reg -- )
    vreg reg rep %copy ;

M:: x86.64 %store-reg-param ( vreg rep reg -- )
    reg vreg rep %copy ;

M:: x86.64 %unbox ( dst src func rep -- )
    param-reg-0 src tagged-rep %copy
    param-reg-1 %mov-vm-ptr
    func f f %c-invoke
    dst rep %load-return ;

M:: x86.64 %box ( dst src func rep gc-map -- )
    0 rep reg-class-of cdecl param-regs at nth src rep %copy
    rep int-rep? os windows? or param-reg-1 param-reg-0 ? %mov-vm-ptr
    func f gc-map %c-invoke
    dst int-rep %load-return ;

M:: x86.64 %allot-byte-array ( dst size gc-map -- )
    param-reg-0 size MOV
    param-reg-1 %mov-vm-ptr
    "allot_byte_array" f gc-map %c-invoke<commit_msg>cpu.x86.64: fix typos<commit_after>! Copyright (C) 2005, 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays kernel math namespaces make sequences
system layouts alien alien.c-types alien.accessors alien.libraries
slots splitting assocs combinators fry locals compiler.constants
classes.struct compiler.codegen compiler.codegen.fixup
compiler.cfg.instructions compiler.cfg.builder
compiler.cfg.intrinsics compiler.cfg.stack-frame
cpu.x86.assembler cpu.x86.assembler.operands cpu.x86
cpu.architecture vm ;
FROM: layouts => cell cells ;
IN: cpu.x86.64

: param-reg ( n -- reg ) int-regs cdecl param-regs at nth ;

: param-reg-0 ( -- reg ) 0 param-reg ; inline
: param-reg-1 ( -- reg ) 1 param-reg ; inline
: param-reg-2 ( -- reg ) 2 param-reg ; inline
: param-reg-3 ( -- reg ) 3 param-reg ; inline

M: x86.64 pic-tail-reg RBX ;

M: x86.64 return-regs
    {
        { int-regs { RAX EDX } }
        { float-regs { XMM0 XMM1 } }
    } ;

M: x86.64 ds-reg R14 ;
M: x86.64 rs-reg R15 ;
M: x86.64 stack-reg RSP ;
M: x86.64 frame-reg RBP ;

M: x86.64 machine-registers
    {
        { int-regs { RAX RCX RDX RBX RBP RSI RDI R8 R9 R10 R11 R12 } }
        { float-regs {
            XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7
            XMM8 XMM9 XMM10 XMM11 XMM12 XMM13 XMM14 XMM15
        } }
    } ;

: vm-reg ( -- reg ) R13 ; inline
: nv-reg ( -- reg ) RBX ; inline

M: x86.64 %mov-vm-ptr ( reg -- )
    vm-reg MOV ;

M: x86.64 %vm-field ( dst offset -- )
    [ vm-reg ] dip [+] MOV ;

M:: x86.64 %load-vector ( dst val rep -- )
    dst 0 [RIP+] rep copy-memory* val rc-relative rel-binary-literal ;

M: x86.64 %set-vm-field ( src offset -- )
    [ vm-reg ] dip [+] swap MOV ;

M: x86.64 %vm-field-ptr ( dst offset -- )
    [ vm-reg ] dip [+] LEA ;

M: x86.64 %prologue ( n -- )
    R11 -7 [RIP+] LEA
    dup PUSH
    R11 PUSH
    stack-reg swap 3 cells - SUB ;

M: x86.64 %prepare-jump
    pic-tail-reg xt-tail-pic-offset [RIP+] LEA ;

: load-cards-offset ( dst -- )
    0 MOV rc-absolute-cell rel-cards-offset ;

M: x86.64 %mark-card
    dup load-cards-offset
    [+] card-mark <byte> MOV ;

: load-decks-offset ( dst -- )
    0 MOV rc-absolute-cell rel-decks-offset ;

M: x86.64 %mark-deck
    dup load-decks-offset
    [+] card-mark <byte> MOV ;

M:: x86.64 %load-stack-param ( vreg rep n -- )
    rep return-reg n next-stack@ rep %copy
    vreg rep return-reg rep %copy ;

M:: x86.64 %store-stack-param ( vreg rep n -- )
    rep return-reg vreg rep %copy
    n reserved-stack-space + stack@ rep return-reg rep %copy ;

M:: x86.64 %load-reg-param ( vreg rep reg -- )
    vreg reg rep %copy ;

M:: x86.64 %store-reg-param ( vreg rep reg -- )
    reg vreg rep %copy ;

M:: x86.64 %unbox ( dst src func rep -- )
    param-reg-0 src tagged-rep %copy
    param-reg-1 %mov-vm-ptr
    func f f %c-invoke
    dst rep %load-return ;

M:: x86.64 %box ( dst src func rep gc-map -- )
    0 rep reg-class-of cdecl param-regs at nth src rep %copy
    rep int-rep? os windows? or param-reg-1 param-reg-0 ? %mov-vm-ptr
    func f gc-map %c-invoke
    dst int-rep %load-return ;

M:: x86.64 %allot-byte-array ( dst size gc-map -- )
    param-reg-0 size MOV
    param-reg-1 %mov-vm-ptr
    "allot_byte_array" f gc-map %c-invoke
{'fraction_non_alphanumeric': 0.14019123997532387, 'fraction_numerical': 0.05367057371992597, 'mean_word_length': 2.3239364428498206, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4708023', 'n_tokens_mistral': 2730, 'n_tokens_neox': 2563, 'n_words': 737}