Change how we do if-intrinsics

slava 2006-11-09 02:04:46 +00:00
parent 75ee6ac549
commit f0231bac6e
6 changed files with 62 additions and 44 deletions

View File

@ -15,6 +15,7 @@
- fdasfsdfsa :help -- weird
- %allot-bignum-signed-2 still has issues on ppc
- fix %allot-bignum-signed-1/2 on x86
- see if 0 0 >= is optimized
+ ui:

View File

@ -56,14 +56,16 @@ UNION: #terminal
relocation-table get
literal-table get
word-table get
] V{ } make
code-format add-compiled-block save-xt ;
!
] V{ } make code-format add-compiled-block save-xt ;
GENERIC: generate-node ( node -- )
: generate-nodes ( node -- )
[ node@ generate-node ] iterate-nodes end-basic-block ;
: generate-branch ( node -- )
[ generate-nodes ] keep-templates ;
: generate ( word node -- )
[ [ generate-nodes ] with-node-iterator ] generate-1 ;
@ -85,44 +87,57 @@ M: #label generate-node
: generate-if ( node label -- next )
<label> [
>r >r node-children first2 generate-nodes
r> r> end-false-branch resolve-label generate-nodes
>r >r node-children first2 generate-branch
r> r> end-false-branch resolve-label
generate-branch
init-templates
] keep resolve-label iterate-next ;
M: #if generate-node
[
end-basic-block
<label> dup %jump-t
] H{
{ +input+ { { f "flag" } } }
} with-template generate-if ;
[ <label> dup %jump-t ]
H{ { +input+ { { f "flag" } } } }
with-template
generate-if ;
! #call
: [with-template] ( quot template -- quot )
2array >quotation [ with-template ] append ;
\ with-template 3array >quotation ;
: define-intrinsic ( word quot template -- )
[with-template] "intrinsic" set-word-prop ;
: define-if-intrinsic ( word quot template -- )
: define-if>branch-intrinsic ( word quot inputs -- )
+input+ associate
[with-template] "if-intrinsic" set-word-prop ;
: if>boolean-intrinsic ( label -- )
: if>boolean-intrinsic ( quot -- )
"true" define-label
"end" define-label
f 0 <int-vreg> load-literal
"true" get swap call
f "if-scratch" get load-literal
"end" get %jump-label
resolve-label
t 0 <int-vreg> load-literal
"true" resolve-label
t "if-scratch" get load-literal
"end" resolve-label
0 <int-vreg> phantom-d get phantom-push
compute-free-vregs ;
"if-scratch" get phantom-d get phantom-push
compute-free-vregs ; inline
: define-if>boolean-intrinsic ( word quot inputs -- )
+input+ associate
{ { f "if-scratch" } } +scratch+ associate
hash-union
>r [ if>boolean-intrinsic ] curry r>
[with-template] "intrinsic" set-word-prop ;
: define-if-intrinsic ( word quot inputs -- )
3dup define-if>branch-intrinsic define-if>boolean-intrinsic ;
: do-if-intrinsic ( node -- next )
[ <label> dup ] keep if-intrinsic call
>r node-successor dup #if? [
r> generate-if node-successor
dup node-successor dup #if? [
<label> [ rot if-intrinsic call ] keep
generate-if node-successor
] [
drop r> if>boolean-intrinsic iterate-next
drop intrinsic call iterate-next
] if ;
M: #call generate-node
@ -148,7 +163,7 @@ M: #call-label generate-node
: dispatch-body ( label/node -- )
<label> swap [
first2 resolve-label generate-nodes end-basic-block
first2 resolve-label generate-nodes
dup %jump-label
] each resolve-label ;

View File

@ -95,10 +95,6 @@ SYMBOL: phantom-r
: phantoms ( -- phantom phantom ) phantom-d get phantom-r get ;
: init-templates ( -- )
<phantom-datastack> phantom-d set
<phantom-callstack> phantom-r set ;
: finalize-heights ( -- )
phantoms [ finalize-height ] 2apply ;
@ -149,6 +145,19 @@ SYMBOL: phantom-r
[ 2dup (compute-free-vregs) ] map>hash \ free-vregs set
drop ;
: init-templates ( -- )
<phantom-datastack> phantom-d set
<phantom-callstack> phantom-r set
compute-free-vregs ;
: keep-templates ( quot -- )
[
phantom-d [ clone ] change
phantom-r [ clone ] change
compute-free-vregs
call
] with-scope ; inline
: additional-vregs ( seq seq -- n )
2array phantoms 2array [ [ length ] map ] 2apply v-
[ 0 max ] map sum ;

View File

@ -13,7 +13,7 @@ M: float-regs (%replace) drop swap %allot-float ;
! Floats
: define-float-op ( word op -- )
[ [ "x" operand "y" operand ] % , ] [ ] make H{
[ "x" operand "y" operand ] swap add H{
{ +input+ { { float "x" } { float "y" } } }
{ +output+ { "x" } }
} define-intrinsic ;
@ -28,11 +28,8 @@ M: float-regs (%replace) drop swap %allot-float ;
] each
: define-float-jump ( word op -- )
[
[ end-basic-block "x" operand "y" operand UCOMISD ] % ,
] [ ] make H{
{ +input+ { { float "x" } { float "y" } } }
} define-if-intrinsic ;
[ "x" operand "y" operand UCOMISD ] swap add
{ { float "x" } { float "y" } } define-if-intrinsic ;
{
{ float< JB }

View File

@ -106,10 +106,8 @@ math-internals namespaces sequences words ;
} define-intrinsic
: define-fixnum-jump ( word op -- )
[
[ end-basic-block "x" operand 0 "y" operand CMP ] % ,
] [ ] make H{ { +input+ { { f "x" } { f "y" } } } }
define-if-intrinsic ;
[ "x" operand 0 "y" operand CMP ] swap add
{ { f "x" } { f "y" } } define-if-intrinsic ;
{
{ fixnum< BLT }
@ -270,10 +268,8 @@ math-internals namespaces sequences words ;
] each
: define-float-jump ( word op -- )
[
[ end-basic-block "x" operand 0 "y" operand FCMPU ] % ,
] [ ] make H{ { +input+ { { float "x" } { float "y" } } } }
define-if-intrinsic ;
[ "x" operand 0 "y" operand FCMPU ] swap add
{ { float "x" } { float "y" } } define-if-intrinsic ;
{
{ float< BLT }

View File

@ -233,8 +233,8 @@ IN: compiler
} define-intrinsic
: define-fixnum-jump ( word op -- )
[ end-basic-block "x" operand "y" operand CMP ] swap add
H{ { +input+ { { f "x" } { f "y" } } } } define-if-intrinsic ;
[ "x" operand "y" operand CMP ] swap add
{ { f "x" } { f "y" } } define-if-intrinsic ;
{
{ fixnum< JL }