<commit_before>! Copyright (C) 2007, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private kernel kernel.private namespaces
system cpu.ppc.assembler compiler.codegen.fixup compiler.units
compiler.constants math math.private layouts words words.private
vocabs slots.private locals.backend ;
IN: bootstrap.ppc

4 \ cell set
big-endian on

4 jit-code-format set

: ds-reg 29 ;
: rs-reg 30 ;

: factor-area-size ( -- n ) 4 bootstrap-cells ;

: stack-frame ( -- n )
    factor-area-size c-area-size + 4 bootstrap-cells align ;

: next-save ( -- n ) stack-frame bootstrap-cell - ;
: xt-save ( -- n ) stack-frame 2 bootstrap-cells - ;

[
    0 6 LOAD32
    6 dup 0 LWZ
    11 6 profile-count-offset LWZ
    11 11 1 tag-fixnum ADDI
    11 6 profile-count-offset STW
    11 6 word-code-offset LWZ
    11 11 compiled-header-size ADDI
    11 MTCTR
    BCTR
] rc-absolute-ppc-2/2 rt-literal 1 jit-profiling jit-define

[
    0 6 LOAD32
    0 MFLR
    1 1 stack-frame SUBI
    6 1 xt-save STW
    stack-frame 6 LI
    6 1 next-save STW
    0 1 lr-save stack-frame + STW
] rc-absolute-ppc-2/2 rt-label 1 jit-prolog jit-define

[
    0 6 LOAD32
    6 dup 0 LWZ
    6 ds-reg 4 STWU
] rc-absolute-ppc-2/2 rt-literal 1 jit-push-literal jit-define

[
    0 6 LOAD32
    6 ds-reg 4 STWU
] rc-absolute-ppc-2/2 rt-immediate 1 jit-push-immediate jit-define

[
    0 6 LOAD32
    7 6 0 LWZ
    1 7 0 STW
] rc-absolute-ppc-2/2 rt-stack-chain 1 jit-save-stack jit-define

[
    0 6 LOAD32
    6 MTCTR
    BCTR
] rc-absolute-ppc-2/2 rt-primitive 1 jit-primitive jit-define

[ 0 BL ] rc-relative-ppc-3 rt-xt 0 jit-word-call jit-define

[ 0 B ] rc-relative-ppc-3 rt-xt 0 jit-word-jump jit-define

: jit-jump-quot ( -- )
    4 3 quot-xt-offset LWZ
    4 MTCTR
    BCTR ;

: jit-call-quot ( -- )
    4 3 quot-xt-offset LWZ
    4 MTLR
    BLRL ;

[
    3 ds-reg 0 LWZ
    ds-reg dup 4 SUBI
    0 3 \ f tag-number CMPI
    2 BNE
    0 B
] rc-relative-ppc-3 rt-xt 3 jit-if-1 jit-define

[
    0 B
] rc-relative-ppc-3 rt-xt 0 jit-if-2 jit-define

[
    0 3 LOAD32
    3 3 0 LWZ
    6 ds-reg 0 LWZ
    6 6 1 SRAWI
    3 3 6 ADD
    3 3 array-start-offset LWZ
    ds-reg dup 4 SUBI
    jit-jump-quot
] rc-absolute-ppc-2/2 rt-literal 1 jit-dispatch jit-define

: jit->r ( -- )
    4 ds-reg 0 LWZ
    ds-reg dup 4 SUBI
    4 rs-reg 4 STWU ;

: jit-2>r ( -- )
    4 ds-reg 0 LWZ
    5 ds-reg -4 LWZ
    ds-reg dup 8 SUBI
    rs-reg dup 8 ADDI
    4 rs-reg 0 STW
    5 rs-reg -4 STW ;

: jit-3>r ( -- )
    4 ds-reg 0 LWZ
    5 ds-reg -4 LWZ
    6 ds-reg -8 LWZ
    ds-reg dup 12 SUBI
    rs-reg dup 12 ADDI
    4 rs-reg 0 STW
    5 rs-reg -4 STW
    6 rs-reg -8 STW ;

: jit-r> ( -- )
    4 ds-reg 0 LWZ
    ds-reg dup 4 SUBI
    4 rs-reg 4 STWU ;

: jit-2r> ( -- )
    4 rs-reg 0 LWZ
    5 rs-reg -4 LWZ
    rs-reg dup 8 SUBI
    ds-reg dup 8 ADDI
    4 ds-reg 0 STW
    5 ds-reg -4 STW ;
<commit_msg>Fix PowerPC bootstrap<commit_after>! Copyright (C) 2007, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private kernel kernel.private namespaces
system cpu.ppc.assembler compiler.codegen.fixup compiler.units
compiler.constants math math.private layouts words words.private
vocabs slots.private locals.backend ;
IN: bootstrap.ppc

4 \ cell set
big-endian on

4 jit-code-format set

: ds-reg 29 ;
: rs-reg 30 ;

: factor-area-size ( -- n ) 4 bootstrap-cells ;

: stack-frame ( -- n )
    factor-area-size c-area-size + 4 bootstrap-cells align ;

: next-save ( -- n ) stack-frame bootstrap-cell - ;
: xt-save ( -- n ) stack-frame 2 bootstrap-cells - ;

[
    0 6 LOAD32
    6 dup 0 LWZ
    11 6 profile-count-offset LWZ
    11 11 1 tag-fixnum ADDI
    11 6 profile-count-offset STW
    11 6 word-code-offset LWZ
    11 11 compiled-header-size ADDI
    11 MTCTR
    BCTR
] rc-absolute-ppc-2/2 rt-literal 1 jit-profiling jit-define

[
    0 6 LOAD32
    0 MFLR
    1 1 stack-frame SUBI
    6 1 xt-save STW
    stack-frame 6 LI
    6 1 next-save STW
    0 1 lr-save stack-frame + STW
] rc-absolute-ppc-2/2 rt-label 1 jit-prolog jit-define

[
    0 6 LOAD32
    6 dup 0 LWZ
    6 ds-reg 4 STWU
] rc-absolute-ppc-2/2 rt-literal 1 jit-push-literal jit-define

[
    0 6 LOAD32
    6 ds-reg 4 STWU
] rc-absolute-ppc-2/2 rt-immediate 1 jit-push-immediate jit-define

[
    0 6 LOAD32
    7 6 0 LWZ
    1 7 0 STW
] rc-absolute-ppc-2/2 rt-stack-chain 1 jit-save-stack jit-define

[
    0 6 LOAD32
    6 MTCTR
    BCTR
] rc-absolute-ppc-2/2 rt-primitive 1 jit-primitive jit-define

[ 0 BL ] rc-relative-ppc-3 rt-xt 0 jit-word-call jit-define

[ 0 B ] rc-relative-ppc-3 rt-xt 0 jit-word-jump jit-define

[
    3 ds-reg 0 LWZ
    ds-reg dup 4 SUBI
    0 3 \ f tag-number CMPI
    2 BEQ
    0 B
] rc-relative-ppc-3 rt-xt 4 jit-if-1 jit-define

[
    0 B
] rc-relative-ppc-3 rt-xt 0 jit-if-2 jit-define

: jit-jump-quot ( -- )
    4 3 quot-xt-offset LWZ
    4 MTCTR
    BCTR ;

[
    0 3 LOAD32
    3 3 0 LWZ
    6 ds-reg 0 LWZ
    6 6 1 SRAWI
    3 3 6 ADD
    3 3 array-start-offset LWZ
    ds-reg dup 4 SUBI
    jit-jump-quot
] rc-absolute-ppc-2/2 rt-literal 1 jit-dispatch jit-define

: jit->r ( -- )
    4 ds-reg 0 LWZ
    ds-reg dup 4 SUBI
    4 rs-reg 4 STWU ;

: jit-2>r ( -- )
    4 ds-reg 0 LWZ
    5 ds-reg -4 LWZ
    ds-reg dup 8 SUBI
    rs-reg dup 8 ADDI
    4 rs-reg 0 STW
    5 rs-reg -4 STW ;

: jit-3>r ( -- )
    4 ds-reg 0 LWZ
    5 ds-reg -4 LWZ
    6 ds-reg -8 LWZ
    ds-reg dup 12 SUBI
    rs-reg dup 12 ADDI
    4 rs-reg 0 STW
    5 rs-reg -4 STW
    6 rs-reg -8 STW ;

: jit-r> ( -- )
    4 rs-reg 0 LWZ
    rs-reg dup 4 SUBI
    4 ds-reg 4 STWU ;

: jit-2r> ( -- )
    4 rs-reg 0 LWZ
    5 rs-reg -4 LWZ
    rs-reg dup 8 SUBI
    ds-reg dup 8 ADDI
    4 ds-reg 0 STW
    5 ds-reg -4 STW ;

{'fraction_non_alphanumeric': 0.10672692508256562, 'fraction_numerical': 0.06900747436120284, 'mean_word_length': 1.8755622188905547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3687873', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2452, 'n_words': 764}