Merge pull request #2235 from kusumotonorio/system-v-amd64-abi

Improved System V AMD64 ABI compliance
master
John Benediktsson 2020-01-24 21:52:40 +00:00 committed by GitHub
commit 4e17fb13cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 15 deletions

View File

@ -15,6 +15,8 @@ IN: compiler.cfg.builder.alien
0 stack-params set 0 stack-params set
V{ } clone reg-values set V{ } clone reg-values set
V{ } clone stack-values set V{ } clone stack-values set
0 int-reg-reps set
0 float-reg-reps set
@ @
reg-values get reg-values get
stack-values get stack-values get

View File

@ -10,19 +10,30 @@ IN: compiler.cfg.builder.alien.boxing
SYMBOL: struct-return-area SYMBOL: struct-return-area
SYMBOLS: int-reg-reps float-reg-reps ;
: reg-reps ( reps -- int-reps float-reps )
[ second ] reject [ [ first int-rep? ] count ] [ length over - ] bi ;
: record-reg-reps ( reps -- reps )
dup reg-reps [ int-reg-reps +@ ] [ float-reg-reps +@ ] bi* ;
: unrecord-reg-reps ( reps -- reps )
dup reg-reps [ neg int-reg-reps +@ ] [ neg float-reg-reps +@ ] bi* ;
GENERIC: flatten-c-type ( c-type -- pairs ) GENERIC: flatten-c-type ( c-type -- pairs )
M: c-type flatten-c-type M: c-type flatten-c-type
rep>> f f 3array 1array ; rep>> f f 3array 1array record-reg-reps ;
M: long-long-type flatten-c-type M: long-long-type flatten-c-type
drop 2 [ int-rep long-long-on-stack? f 3array ] replicate ; drop 2 [ int-rep long-long-on-stack? f 3array ] replicate record-reg-reps ;
HOOK: flatten-struct-type cpu ( type -- pairs ) HOOK: flatten-struct-type cpu ( type -- pairs )
HOOK: flatten-struct-type-return cpu ( type -- pairs ) HOOK: flatten-struct-type-return cpu ( type -- pairs )
M: object flatten-struct-type M: object flatten-struct-type
heap-size cell align cell /i { int-rep f f } <array> ; heap-size cell align cell /i { int-rep f f } <array> record-reg-reps ;
M: struct-c-type flatten-c-type M: struct-c-type flatten-c-type
flatten-struct-type ; flatten-struct-type ;
@ -70,12 +81,12 @@ M: c-type unbox
[ swap ^^unbox ] [ swap ^^unbox ]
} case 1array } case 1array
] ]
[ drop f f 3array 1array ] 2bi ; [ drop f f 3array 1array ] 2bi record-reg-reps ;
M: long-long-type unbox M: long-long-type unbox
[ next-vreg next-vreg 2dup ] 2dip unboxer>> ##unbox-long-long, 2array [ next-vreg next-vreg 2dup ] 2dip unboxer>> ##unbox-long-long, 2array
int-rep long-long-on-stack? long-long-odd-register? 3array int-rep long-long-on-stack? long-long-odd-register? 3array
int-rep long-long-on-stack? f 3array 2array ; int-rep long-long-on-stack? f 3array 2array record-reg-reps ;
M: struct-c-type unbox ( src c-type -- vregs reps ) M: struct-c-type unbox ( src c-type -- vregs reps )
[ ^^unbox-any-c-ptr ] dip explode-struct ; [ ^^unbox-any-c-ptr ] dip explode-struct ;

View File

@ -2,8 +2,8 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays assocs USING: accessors alien.c-types arrays assocs
compiler.cfg.builder.alien.boxing cpu.architecture cpu.x86 compiler.cfg.builder.alien.boxing cpu.architecture cpu.x86
cpu.x86.assembler cpu.x86.assembler.operands kernel layouts make math cpu.x86.assembler cpu.x86.assembler.operands kernel layouts locals
math.order sequences splitting system ; make math math.order namespaces sequences splitting system ;
IN: cpu.x86.64.unix IN: cpu.x86.64.unix
M: x86.64 param-regs M: x86.64 param-regs
@ -24,16 +24,26 @@ M: x86.64 reserved-stack-space 0 ;
[ 8 mod zero? [ t , ] when , ] assoc-each [ 8 mod zero? [ t , ] when , ] assoc-each
] { } make { t } split harvest ; ] { } make { t } split harvest ;
: flatten-small-struct ( c-type -- seq ) :: flatten-small-struct ( c-type -- seq )
struct-types&offset split-struct [ c-type struct-types&offset split-struct [
[ lookup-c-type c-type-rep reg-class-of ] map [ lookup-c-type c-type-rep reg-class-of ] map
int-regs swap member? int-rep double-rep ? int-regs swap member? int-rep double-rep ?
f f 3array f f 3array
] map ; ] map :> reps
int-reg-reps get float-reg-reps get and [
reps reg-reps :> ( int-mems float-mems )
int-reg-reps get int-mems + 6 >
float-reg-reps get float-mems + 8 > or [
reps [ first t f 3array ] map
] [ reps ] if
] [ reps ] if ;
M: x86.64 flatten-struct-type ( c-type -- seq ) M: x86.64 flatten-struct-type ( c-type -- seq )
dup heap-size 16 <= dup heap-size 16 <=
[ flatten-small-struct ] [ call-next-method [ first t f 3array ] map ] if ; [ flatten-small-struct record-reg-reps ] [
call-next-method unrecord-reg-reps
[ first t f 3array ] map
] if ;
M: x86.64 return-struct-in-registers? ( c-type -- ? ) M: x86.64 return-struct-in-registers? ( c-type -- ? )
heap-size 2 cells <= ; heap-size 2 cells <= ;

View File

@ -238,16 +238,15 @@ IMPORT: NSAttributedString
] [ underlines ] if ; ] [ underlines ] if ;
:: update-marked-text ( gadget str selectedRange replacementRange -- ) :: update-marked-text ( gadget str selectedRange replacementRange -- )
replacementRange location>> NSNotFound = not ! [ replacementRange location>> NSNotFound = not [
replacementRange length>> NSNotFound = not and [ ! erase this line
gadget editor-caret first gadget editor-caret first
dup gadget editor-line dup gadget editor-line
[ [
replacementRange length>> ! location>> replacementRange location>>
>codepoint-index >codepoint-index
2array gadget set-caret 2array gadget set-caret
] [ ] [
replacementRange length>> 1 + ! [ location>> ] [ length>> ] bi + replacementRange [ location>> ] [ length>> ] bi +
>codepoint-index >codepoint-index
2array gadget set-mark 2array gadget set-mark
] 2bi ] 2bi