Faster generic arithmetic on fiixnums: both-fixnums? sub-primitive performs a check if the top two stack items are both fixnums with a single conditional branch
parent
2863da257b
commit
eb8c621b6f
|
@ -7,9 +7,18 @@ compiler.cfg.hats
|
||||||
compiler.cfg.stacks
|
compiler.cfg.stacks
|
||||||
compiler.cfg.iterator
|
compiler.cfg.iterator
|
||||||
compiler.cfg.instructions
|
compiler.cfg.instructions
|
||||||
compiler.cfg.utilities ;
|
compiler.cfg.utilities
|
||||||
|
compiler.cfg.registers ;
|
||||||
IN: compiler.cfg.intrinsics.fixnum
|
IN: compiler.cfg.intrinsics.fixnum
|
||||||
|
|
||||||
|
: emit-both-fixnums? ( -- )
|
||||||
|
D 0 ^^peek
|
||||||
|
D 1 ^^peek
|
||||||
|
^^or
|
||||||
|
tag-mask get ^^and-imm
|
||||||
|
0 cc= ^^compare-imm
|
||||||
|
ds-push ;
|
||||||
|
|
||||||
: (emit-fixnum-imm-op) ( infos insn -- dst )
|
: (emit-fixnum-imm-op) ( infos insn -- dst )
|
||||||
ds-drop
|
ds-drop
|
||||||
[ ds-pop ]
|
[ ds-pop ]
|
||||||
|
|
|
@ -23,6 +23,7 @@ IN: compiler.cfg.intrinsics
|
||||||
|
|
||||||
{
|
{
|
||||||
kernel.private:tag
|
kernel.private:tag
|
||||||
|
math.private:both-fixnums?
|
||||||
math.private:fixnum+
|
math.private:fixnum+
|
||||||
math.private:fixnum-
|
math.private:fixnum-
|
||||||
math.private:fixnum+fast
|
math.private:fixnum+fast
|
||||||
|
@ -91,6 +92,7 @@ IN: compiler.cfg.intrinsics
|
||||||
: emit-intrinsic ( node word -- node/f )
|
: emit-intrinsic ( node word -- node/f )
|
||||||
{
|
{
|
||||||
{ \ kernel.private:tag [ drop emit-tag iterate-next ] }
|
{ \ kernel.private:tag [ drop emit-tag iterate-next ] }
|
||||||
|
{ \ math.private:both-fixnums? [ drop emit-both-fixnums? iterate-next ] }
|
||||||
{ \ math.private:fixnum+ [ drop [ ##fixnum-add ] [ ##fixnum-add-tail ] emit-fixnum-overflow-op ] }
|
{ \ math.private:fixnum+ [ drop [ ##fixnum-add ] [ ##fixnum-add-tail ] emit-fixnum-overflow-op ] }
|
||||||
{ \ math.private:fixnum- [ drop [ ##fixnum-sub ] [ ##fixnum-sub-tail ] emit-fixnum-overflow-op ] }
|
{ \ math.private:fixnum- [ drop [ ##fixnum-sub ] [ ##fixnum-sub-tail ] emit-fixnum-overflow-op ] }
|
||||||
{ \ math.private:fixnum* [ drop [ ##fixnum-mul ] [ ##fixnum-mul-tail ] emit-fixnum-overflow-op ] }
|
{ \ math.private:fixnum* [ drop [ ##fixnum-mul ] [ ##fixnum-mul-tail ] emit-fixnum-overflow-op ] }
|
||||||
|
|
|
@ -379,6 +379,17 @@ big-endian off
|
||||||
ds-reg bootstrap-cell neg [+] div-arg MOV
|
ds-reg bootstrap-cell neg [+] div-arg MOV
|
||||||
] f f f \ fixnum/mod-fast define-sub-primitive
|
] f f f \ fixnum/mod-fast define-sub-primitive
|
||||||
|
|
||||||
|
[
|
||||||
|
arg0 ds-reg [] MOV
|
||||||
|
arg0 ds-reg bootstrap-cell neg [+] OR
|
||||||
|
ds-reg bootstrap-cell ADD
|
||||||
|
arg0 tag-mask get AND
|
||||||
|
arg0 \ f tag-number MOV
|
||||||
|
arg1 1 tag-fixnum MOV
|
||||||
|
arg0 arg1 CMOVE
|
||||||
|
ds-reg [] arg0 MOV
|
||||||
|
] f f f \ both-fixnums? define-sub-primitive
|
||||||
|
|
||||||
[
|
[
|
||||||
arg0 ds-reg [] MOV ! load local number
|
arg0 ds-reg [] MOV ! load local number
|
||||||
fixnum>slot@ ! turn local number into offset
|
fixnum>slot@ ! turn local number into offset
|
||||||
|
|
|
@ -281,6 +281,8 @@ M: object infer-call*
|
||||||
\ <complex> { real real } { complex } define-primitive
|
\ <complex> { real real } { complex } define-primitive
|
||||||
\ <complex> make-foldable
|
\ <complex> make-foldable
|
||||||
|
|
||||||
|
\ both-fixnums? { object object } { object object object } define-primitive
|
||||||
|
|
||||||
\ fixnum+ { fixnum fixnum } { integer } define-primitive
|
\ fixnum+ { fixnum fixnum } { integer } define-primitive
|
||||||
\ fixnum+ make-foldable
|
\ fixnum+ make-foldable
|
||||||
|
|
||||||
|
|
|
@ -348,6 +348,7 @@ tuple
|
||||||
{
|
{
|
||||||
{ "(execute)" "words.private" }
|
{ "(execute)" "words.private" }
|
||||||
{ "(call)" "kernel.private" }
|
{ "(call)" "kernel.private" }
|
||||||
|
{ "both-fixnums?" "math.private" }
|
||||||
{ "fixnum+fast" "math.private" }
|
{ "fixnum+fast" "math.private" }
|
||||||
{ "fixnum-fast" "math.private" }
|
{ "fixnum-fast" "math.private" }
|
||||||
{ "fixnum*fast" "math.private" }
|
{ "fixnum*fast" "math.private" }
|
||||||
|
|
|
@ -56,9 +56,11 @@ ERROR: no-math-method left right generic ;
|
||||||
|
|
||||||
: math-method ( word class1 class2 -- quot )
|
: math-method ( word class1 class2 -- quot )
|
||||||
2dup and [
|
2dup and [
|
||||||
2dup math-upgrade
|
[
|
||||||
[ math-class-max over order min-class applicable-method ] dip
|
2dup 2array , \ declare ,
|
||||||
prepend
|
2dup math-upgrade %
|
||||||
|
math-class-max over order min-class applicable-method %
|
||||||
|
] [ ] make
|
||||||
] [
|
] [
|
||||||
2drop object-method
|
2drop object-method
|
||||||
] if ;
|
] if ;
|
||||||
|
@ -67,13 +69,9 @@ SYMBOL: picker
|
||||||
|
|
||||||
: math-vtable ( picker quot -- quot )
|
: math-vtable ( picker quot -- quot )
|
||||||
[
|
[
|
||||||
swap picker set
|
[ , \ tag , ]
|
||||||
picker get , [ tag 0 eq? ] %
|
[ num-tags get swap [ bootstrap-type>class ] prepose map , ] bi*
|
||||||
num-tags get swap [ bootstrap-type>class ] prepose map
|
\ dispatch ,
|
||||||
unclip ,
|
|
||||||
[
|
|
||||||
picker get , [ tag 1 fixnum-fast ] % , \ dispatch ,
|
|
||||||
] [ ] make , \ if ,
|
|
||||||
] [ ] make ; inline
|
] [ ] make ; inline
|
||||||
|
|
||||||
TUPLE: math-combination ;
|
TUPLE: math-combination ;
|
||||||
|
@ -84,13 +82,18 @@ M: math-combination make-default-method
|
||||||
M: math-combination perform-combination
|
M: math-combination perform-combination
|
||||||
drop
|
drop
|
||||||
dup
|
dup
|
||||||
\ over [
|
[
|
||||||
dup math-class? [
|
\ both-fixnums? ,
|
||||||
\ dup [ [ 2dup ] dip math-method ] math-vtable
|
dup fixnum bootstrap-word dup math-method ,
|
||||||
] [
|
\ over [
|
||||||
over object-method
|
dup math-class? [
|
||||||
] if nip
|
\ dup [ [ 2dup ] dip math-method ] math-vtable
|
||||||
] math-vtable nip define ;
|
] [
|
||||||
|
over object-method
|
||||||
|
] if nip
|
||||||
|
] math-vtable nip ,
|
||||||
|
\ if ,
|
||||||
|
] [ ] make define ;
|
||||||
|
|
||||||
PREDICATE: math-generic < generic ( word -- ? )
|
PREDICATE: math-generic < generic ( word -- ? )
|
||||||
"combination" word-prop math-combination? ;
|
"combination" word-prop math-combination? ;
|
||||||
|
|
Loading…
Reference in New Issue