From 7f7b92b4b27fe841d93dd70911f2934a9435d2a1 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 29 Sep 2007 19:56:52 -0400 Subject: [PATCH] Update cpu/x86 for new alien intrinsics (untested) --- core/cpu/x86/architecture/architecture.factor | 26 ++++---- core/cpu/x86/intrinsics/intrinsics.factor | 63 ++++++++++++------- core/cpu/x86/sse2/sse2.factor | 19 +++--- 3 files changed, 57 insertions(+), 51 deletions(-) diff --git a/core/cpu/x86/architecture/architecture.factor b/core/cpu/x86/architecture/architecture.factor index e2232c36bb..36922a84e0 100644 --- a/core/cpu/x86/architecture/architecture.factor +++ b/core/cpu/x86/architecture/architecture.factor @@ -174,29 +174,25 @@ M: x86-backend struct-small-enough? ( size -- ? ) M: x86-backend %return ( -- ) 0 %unwind ; ! Alien intrinsics -M: x86-backend %unbox-byte-array ( quot src -- ) - "alien" operand "offset" operand ADD - "alien" operand byte-array-offset [+] - rot call ; +M: x86-backend %unbox-byte-array ( dst src -- ) + [ v>operand ] 2apply byte-array-offset [+] LEA ; -M: x86-backend %unbox-alien ( quot src -- ) - "alien" operand dup alien-offset [+] MOV - "alien" operand "offset" operand [+] - rot call ; +M: x86-backend %unbox-alien ( dst src -- ) + [ v>operand ] 2apply alien-offset [+] MOV ; -M: x86-backend %unbox-f ( quot src -- ) - "offset" operand rot call ; +M: x86-backend %unbox-f ( dst src -- ) + drop 0 MOV ; -M: x86-backend %complex-alien-accessor ( quot src -- ) +M: x86-backend %complex-alien-accessor ( dst src -- ) { "is-f" "is-alien" "end" } [ define-label ] each - "alien" operand f v>operand CMP + dup f [ v>operand ] 2apply CMP "is-f" get JE - "alien" operand header-offset [+] alien type-number tag-header CMP + dup header-offset [+] alien type-number tag-header CMP "is-alien" get JE - [ %unbox-byte-array ] 2keep + 2dup %unbox-byte-array "end" get JMP "is-alien" resolve-label - [ %unbox-alien ] 2keep + 2dup %unbox-alien "end" get JMP "is-f" resolve-label %unbox-f diff --git a/core/cpu/x86/intrinsics/intrinsics.factor b/core/cpu/x86/intrinsics/intrinsics.factor index 0228848a33..83aa214187 100644 --- a/core/cpu/x86/intrinsics/intrinsics.factor +++ b/core/cpu/x86/intrinsics/intrinsics.factor @@ -74,7 +74,7 @@ IN: cpu.x86.intrinsics : %slot-literal-known-tag "obj" operand "n" get cells - "obj" operand-tag - [+] ; + "obj" get operand-tag - [+] ; : %slot-literal-any-tag "obj" operand %untag @@ -112,7 +112,7 @@ IN: cpu.x86.intrinsics : generate-write-barrier ( -- ) #! Mark the card pointed to by vreg. - "val" operand-immediate? "obj" get fresh-object? or [ + "val" get operand-immediate? "obj" get fresh-object? or [ "obj" operand card-bits SHR "cards_offset" f %alien-global temp-reg v>operand "obj" operand [+] card-mark OR @@ -498,22 +498,26 @@ IN: cpu.x86.intrinsics } define-intrinsic ! Alien intrinsics -: %alien-integer-get ( quot reg -- ) +: %alien-accessor ( quot -- ) small-reg PUSH "offset" operand %untag-fixnum - "alien" operand-class %alien-accessor - "offset" operand small-reg MOV - "offset" operand %tag-fixnum + "offset" operand "alien" operand ADD + "value" operand "offset" operand [] rot call small-reg POP ; inline +: %alien-integer-get ( quot reg -- ) + %alien-accessor + "offset" operand %tag-fixnum ; inline + : alien-integer-get-template H{ { +input+ { - { f "alien" simple-c-ptr } + { unboxed-c-ptr "alien" simple-c-ptr } { f "offset" fixnum } } } - { +output+ { "offset" } } - { +clobber+ { "alien" "offset" } } + { +scratch+ { { f "value" } } } + { +output+ { "value" } } + { +clobber+ { "offset" } } } ; : define-getter @@ -528,20 +532,19 @@ IN: cpu.x86.intrinsics [ [ >r MOV small-reg r> MOVSX ] curry ] keep define-getter ; : %alien-integer-set ( quot reg -- ) - small-reg PUSH - { "offset" "value" } %untag-fixnums - small-reg "value" operand MOV - "alien" operand-class %alien-accessor - small-reg POP ; inline + "offset" get "value" get = [ + "value" operand %untag-fixnum + ] unless + %alien-accessor ; inline : alien-integer-set-template H{ { +input+ { { f "value" fixnum } - { f "alien" simple-c-ptr } + { unboxed-c-ptr "alien" simple-c-ptr } { f "offset" fixnum } } } - { +clobber+ { "value" "alien" "offset" } } + { +clobber+ { "value" "offset" } } } ; : define-setter @@ -563,12 +566,24 @@ IN: cpu.x86.intrinsics \ set-alien-signed-2 small-reg-16 define-setter \ alien-cell [ - "offset" operand %untag-fixnum + [ MOV ] %alien-accessor +] H{ + { +input+ { + { unboxed-c-ptr "alien" simple-c-ptr } + { f "offset" fixnum } + } } + { +scratch+ { { unboxed-alien "value" } } } + { +output+ { "value" } } + { +clobber+ { "offset" } } +} define-intrinsic define-intrinsic - [ MOV ] - "offset" operand - "alien" operand-class - %alien-accessor - - "offset" get %allot-alien -] alien-integer-get-template define-intrinsic +\ set-alien-cell [ + [ swap MOV ] %alien-accessor +] H{ + { +input+ { + { unboxed-c-ptr "value" simple-c-ptr } + { unboxed-c-ptr "alien" simple-c-ptr } + { f "offset" fixnum } + } } + { +clobber+ { "offset" } } +} define-intrinsic define-intrinsic diff --git a/core/cpu/x86/sse2/sse2.factor b/core/cpu/x86/sse2/sse2.factor index 397f9d3d93..308df43f09 100644 --- a/core/cpu/x86/sse2/sse2.factor +++ b/core/cpu/x86/sse2/sse2.factor @@ -62,34 +62,29 @@ IN: cpu.x86.sse2 : alien-float-get-template H{ { +input+ { - { f "alien" simple-c-ptr } + { unboxed-c-ptr "alien" simple-c-ptr } { f "offset" fixnum } } } - { +scratch+ { { float "output" } } } + { +scratch+ { { float "value" } } } { +output+ { "output" } } - { +clobber+ { "alien" "offset" } } + { +clobber+ { "offset" } } } ; -: %alien-float-set ( quot -- ) - "offset" operand %untag-fixnum - "value" operand "alien" operand-class %alien-accessor ; - inline - : alien-float-set-template H{ { +input+ { { float "value" float } - { f "alien" simple-c-ptr } + { unboxed-c-ptr "alien" simple-c-ptr } { f "offset" fixnum } } } - { +clobber+ { "value" "alien" "offset" } } + { +clobber+ { "offset" } } } ; : define-alien-float-intrinsics ( word get-quot word set-quot -- ) - [ %alien-float-set ] curry + [ %alien-accessor ] curry alien-float-set-template define-intrinsic - [ %alien-float-get ] curry + [ %alien-accessor ] curry alien-float-get-template define-intrinsic ;