Merge branch 'master' of git://factorcode.org/git/factor

db4
Doug Coleman 2009-10-05 18:34:58 -05:00
commit f800285327
11 changed files with 102 additions and 79 deletions

View File

@ -194,8 +194,8 @@ IN: compiler.cfg.intrinsics
{ math.vectors.simd.intrinsics:(simd-gather-2) [ emit-gather-vector-2 ] } { math.vectors.simd.intrinsics:(simd-gather-2) [ emit-gather-vector-2 ] }
{ math.vectors.simd.intrinsics:(simd-gather-4) [ emit-gather-vector-4 ] } { math.vectors.simd.intrinsics:(simd-gather-4) [ emit-gather-vector-4 ] }
{ math.vectors.simd.intrinsics:(simd-vshuffle) [ emit-shuffle-vector ] } { math.vectors.simd.intrinsics:(simd-vshuffle) [ emit-shuffle-vector ] }
{ math.vectors.simd.intrinsics:(simd-vmerge-head) [ [ ^^merge-vector-head ] emit-binary-vector-op ] } { math.vectors.simd.intrinsics:(simd-(vmerge-head)) [ [ ^^merge-vector-head ] emit-binary-vector-op ] }
{ math.vectors.simd.intrinsics:(simd-vmerge-tail) [ [ ^^merge-vector-tail ] emit-binary-vector-op ] } { math.vectors.simd.intrinsics:(simd-(vmerge-tail)) [ [ ^^merge-vector-tail ] emit-binary-vector-op ] }
{ math.vectors.simd.intrinsics:(simd-select) [ emit-select-vector ] } { math.vectors.simd.intrinsics:(simd-select) [ emit-select-vector ] }
{ math.vectors.simd.intrinsics:(simd-sum) [ [ ^^horizontal-add-vector ] emit-unary-vector-op ] } { math.vectors.simd.intrinsics:(simd-sum) [ [ ^^horizontal-add-vector ] emit-unary-vector-op ] }
{ math.vectors.simd.intrinsics:alien-vector [ emit-alien-vector ] } { math.vectors.simd.intrinsics:alien-vector [ emit-alien-vector ] }

View File

@ -1465,7 +1465,7 @@ V{
[ ] [ { 1 2 3 } test-linear-scan-on-cfg ] unit-test [ ] [ { 1 2 3 } test-linear-scan-on-cfg ] unit-test
[ { 1 } ] [ 1 get instructions>> first tagged-values>> ] unit-test [ { { 0 1 } } ] [ 1 get instructions>> first tagged-values>> ] unit-test
V{ V{
T{ ##peek f 0 D 0 } T{ ##peek f 0 D 0 }
@ -1487,4 +1487,4 @@ V{
[ ] [ { 1 2 3 } test-linear-scan-on-cfg ] unit-test [ ] [ { 1 2 3 } test-linear-scan-on-cfg ] unit-test
[ { 1 } ] [ 1 get instructions>> first tagged-values>> ] unit-test [ { { 0 1 } } ] [ 1 get instructions>> first tagged-values>> ] unit-test

View File

@ -31,8 +31,8 @@ IN: compiler.tree.propagation.simd
(simd-hlshift) (simd-hlshift)
(simd-hrshift) (simd-hrshift)
(simd-vshuffle) (simd-vshuffle)
(simd-vmerge-head) (simd-(vmerge-head))
(simd-vmerge-tail) (simd-(vmerge-tail))
(simd-v<=) (simd-v<=)
(simd-v<) (simd-v<)
(simd-v=) (simd-v=)

View File

@ -424,15 +424,15 @@ INSTANCE: A sequence
: A-vmerge-head-op ( v1 v2 quot -- v ) : A-vmerge-head-op ( v1 v2 quot -- v )
drop drop
[ underlying1>> ] bi@ [ underlying1>> ] bi@
[ A-rep (simd-vmerge-head) ] [ A-rep (simd-(vmerge-head)) ]
[ A-rep (simd-vmerge-tail) ] 2bi [ A-rep (simd-(vmerge-tail)) ] 2bi
\ A boa ; \ A boa ;
: A-vmerge-tail-op ( v1 v2 quot -- v ) : A-vmerge-tail-op ( v1 v2 quot -- v )
drop drop
[ underlying2>> ] bi@ [ underlying2>> ] bi@
[ A-rep (simd-vmerge-head) ] [ A-rep (simd-(vmerge-head)) ]
[ A-rep (simd-vmerge-tail) ] 2bi [ A-rep (simd-(vmerge-tail)) ] 2bi
\ A boa ; \ A boa ;
simd new simd new
@ -445,8 +445,8 @@ simd new
{ vnone? A-vany-op } { vnone? A-vany-op }
{ vany? A-vany-op } { vany? A-vany-op }
{ vall? A-vall-op } { vall? A-vall-op }
{ vmerge-head A-vmerge-head-op } { (vmerge-head) A-vmerge-head-op }
{ vmerge-tail A-vmerge-tail-op } { (vmerge-tail) A-vmerge-tail-op }
} >>special-wrappers } >>special-wrappers
{ {
{ { +vector+ +vector+ -> +vector+ } A-vv->v-op } { { +vector+ +vector+ -> +vector+ } A-vv->v-op }

View File

@ -55,8 +55,8 @@ SIMD-OP: vrshift
SIMD-OP: hlshift SIMD-OP: hlshift
SIMD-OP: hrshift SIMD-OP: hrshift
SIMD-OP: vshuffle SIMD-OP: vshuffle
SIMD-OP: vmerge-head SIMD-OP: (vmerge-head)
SIMD-OP: vmerge-tail SIMD-OP: (vmerge-tail)
SIMD-OP: v<= SIMD-OP: v<=
SIMD-OP: v< SIMD-OP: v<
SIMD-OP: v= SIMD-OP: v=
@ -120,46 +120,46 @@ GENERIC# supported-simd-op? 1 ( rep intrinsic -- ? )
M: vector-rep supported-simd-op? M: vector-rep supported-simd-op?
{ {
{ \ (simd-v+) [ %add-vector-reps ] } { \ (simd-v+) [ %add-vector-reps ] }
{ \ (simd-vs+) [ %saturated-add-vector-reps ] } { \ (simd-vs+) [ %saturated-add-vector-reps ] }
{ \ (simd-v+-) [ %add-sub-vector-reps ] } { \ (simd-v+-) [ %add-sub-vector-reps ] }
{ \ (simd-v-) [ %sub-vector-reps ] } { \ (simd-v-) [ %sub-vector-reps ] }
{ \ (simd-vs-) [ %saturated-sub-vector-reps ] } { \ (simd-vs-) [ %saturated-sub-vector-reps ] }
{ \ (simd-v*) [ %mul-vector-reps ] } { \ (simd-v*) [ %mul-vector-reps ] }
{ \ (simd-vs*) [ %saturated-mul-vector-reps ] } { \ (simd-vs*) [ %saturated-mul-vector-reps ] }
{ \ (simd-v/) [ %div-vector-reps ] } { \ (simd-v/) [ %div-vector-reps ] }
{ \ (simd-vmin) [ %min-vector-reps ] } { \ (simd-vmin) [ %min-vector-reps ] }
{ \ (simd-vmax) [ %max-vector-reps ] } { \ (simd-vmax) [ %max-vector-reps ] }
{ \ (simd-v.) [ %dot-vector-reps ] } { \ (simd-v.) [ %dot-vector-reps ] }
{ \ (simd-vsqrt) [ %sqrt-vector-reps ] } { \ (simd-vsqrt) [ %sqrt-vector-reps ] }
{ \ (simd-sum) [ %horizontal-add-vector-reps ] } { \ (simd-sum) [ %horizontal-add-vector-reps ] }
{ \ (simd-vabs) [ %abs-vector-reps ] } { \ (simd-vabs) [ %abs-vector-reps ] }
{ \ (simd-vbitand) [ %and-vector-reps ] } { \ (simd-vbitand) [ %and-vector-reps ] }
{ \ (simd-vbitandn) [ %andn-vector-reps ] } { \ (simd-vbitandn) [ %andn-vector-reps ] }
{ \ (simd-vbitor) [ %or-vector-reps ] } { \ (simd-vbitor) [ %or-vector-reps ] }
{ \ (simd-vbitxor) [ %xor-vector-reps ] } { \ (simd-vbitxor) [ %xor-vector-reps ] }
{ \ (simd-vbitnot) [ %not-vector-reps ] } { \ (simd-vbitnot) [ %not-vector-reps ] }
{ \ (simd-vand) [ %and-vector-reps ] } { \ (simd-vand) [ %and-vector-reps ] }
{ \ (simd-vandn) [ %andn-vector-reps ] } { \ (simd-vandn) [ %andn-vector-reps ] }
{ \ (simd-vor) [ %or-vector-reps ] } { \ (simd-vor) [ %or-vector-reps ] }
{ \ (simd-vxor) [ %xor-vector-reps ] } { \ (simd-vxor) [ %xor-vector-reps ] }
{ \ (simd-vnot) [ %not-vector-reps ] } { \ (simd-vnot) [ %not-vector-reps ] }
{ \ (simd-vlshift) [ %shl-vector-reps ] } { \ (simd-vlshift) [ %shl-vector-reps ] }
{ \ (simd-vrshift) [ %shr-vector-reps ] } { \ (simd-vrshift) [ %shr-vector-reps ] }
{ \ (simd-hlshift) [ %horizontal-shl-vector-reps ] } { \ (simd-hlshift) [ %horizontal-shl-vector-reps ] }
{ \ (simd-hrshift) [ %horizontal-shr-vector-reps ] } { \ (simd-hrshift) [ %horizontal-shr-vector-reps ] }
{ \ (simd-vshuffle) [ %shuffle-vector-reps ] } { \ (simd-vshuffle) [ %shuffle-vector-reps ] }
{ \ (simd-vmerge-head) [ %merge-vector-reps ] } { \ (simd-(vmerge-head)) [ %merge-vector-reps ] }
{ \ (simd-vmerge-tail) [ %merge-vector-reps ] } { \ (simd-(vmerge-tail)) [ %merge-vector-reps ] }
{ \ (simd-v<=) [ cc<= %compare-vector-reps ] } { \ (simd-v<=) [ cc<= %compare-vector-reps ] }
{ \ (simd-v<) [ cc< %compare-vector-reps ] } { \ (simd-v<) [ cc< %compare-vector-reps ] }
{ \ (simd-v=) [ cc= %compare-vector-reps ] } { \ (simd-v=) [ cc= %compare-vector-reps ] }
{ \ (simd-v>) [ cc> %compare-vector-reps ] } { \ (simd-v>) [ cc> %compare-vector-reps ] }
{ \ (simd-v>=) [ cc>= %compare-vector-reps ] } { \ (simd-v>=) [ cc>= %compare-vector-reps ] }
{ \ (simd-vunordered?) [ cc/<>= %compare-vector-reps ] } { \ (simd-vunordered?) [ cc/<>= %compare-vector-reps ] }
{ \ (simd-gather-2) [ %gather-vector-2-reps ] } { \ (simd-gather-2) [ %gather-vector-2-reps ] }
{ \ (simd-gather-4) [ %gather-vector-4-reps ] } { \ (simd-gather-4) [ %gather-vector-4-reps ] }
{ \ (simd-vany?) [ %test-vector-reps ] } { \ (simd-vany?) [ %test-vector-reps ] }
{ \ (simd-vall?) [ %test-vector-reps ] } { \ (simd-vall?) [ %test-vector-reps ] }
{ \ (simd-vnone?) [ %test-vector-reps ] } { \ (simd-vnone?) [ %test-vector-reps ] }
} case member? ; } case member? ;

View File

@ -98,8 +98,8 @@ H{
{ hrshift { +vector+ +literal+ -> +vector+ } } { hrshift { +vector+ +literal+ -> +vector+ } }
{ vshuffle { +vector+ +literal+ -> +vector+ } } { vshuffle { +vector+ +literal+ -> +vector+ } }
{ vbroadcast { +vector+ +literal+ -> +vector+ } } { vbroadcast { +vector+ +literal+ -> +vector+ } }
{ vmerge-head { +vector+ +vector+ -> +vector+ } } { (vmerge-head) { +vector+ +vector+ -> +vector+ } }
{ vmerge-tail { +vector+ +vector+ -> +vector+ } } { (vmerge-tail) { +vector+ +vector+ -> +vector+ } }
{ v<= { +vector+ +vector+ -> +vector+ } } { v<= { +vector+ +vector+ -> +vector+ } }
{ v< { +vector+ +vector+ -> +vector+ } } { v< { +vector+ +vector+ -> +vector+ } }
{ v= { +vector+ +vector+ -> +vector+ } } { v= { +vector+ +vector+ -> +vector+ } }

View File

@ -59,7 +59,8 @@ $nl
{ $subsection vbroadcast } { $subsection vbroadcast }
{ $subsection hlshift } { $subsection hlshift }
{ $subsection hrshift } { $subsection hrshift }
{ $subsection vmerge } ; { $subsection vmerge }
{ $subsection (vmerge) } ;
ARTICLE: "math-vectors-logic" "Vector component- and bit-wise logic" ARTICLE: "math-vectors-logic" "Vector component- and bit-wise logic"
{ $notes { $notes
@ -357,37 +358,50 @@ HELP: hrshift
{ $description "Shifts the entire SIMD array to the right by " { $snippet "n" } " bytes, filling the vacated left-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ; { $description "Shifts the entire SIMD array to the right by " { $snippet "n" } " bytes, filling the vacated left-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ;
HELP: vmerge HELP: vmerge
{ $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } { "t" "a sequence" } } { $values { "u" "a sequence" } { "v" "a sequence" } { "w" "a sequence" } }
{ $description "Creates two new sequences of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements of " { $snippet "u" } " and " { $snippet "v" } "." } { $description "Creates a new sequence of the same type as and twice the length of " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements of " { $snippet "u" } " and " { $snippet "v" } "." }
{ $examples { $examples
{ $example """USING: kernel math.vectors prettyprint ; { $example """USING: kernel math.vectors prettyprint ;
{ "A" "B" "C" "D" } { "1" "2" "3" "4" } vmerge [ . ] bi@""" { "A" "B" "C" "D" } { "1" "2" "3" "4" } vmerge ."""
"""{ "A" "1" "B" "2" "C" "3" "D" "4" }"""
} } ;
HELP: (vmerge)
{ $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } { "t" "a sequence" } }
{ $description "Creates two new sequences of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements of " { $snippet "u" } " and " { $snippet "v" } "." }
{ $notes "For hardware-supported SIMD vector types this word compiles to a single instruction per output value." }
{ $examples
{ $example """USING: kernel math.vectors prettyprint ;
{ "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge) [ . ] bi@"""
"""{ "A" "1" "B" "2" } """{ "A" "1" "B" "2" }
{ "C" "3" "D" "4" }""" { "C" "3" "D" "4" }"""
} } ; } } ;
HELP: vmerge-head HELP: (vmerge-head)
{ $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } } { $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } }
{ $description "Creates two new sequences of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the first half of " { $snippet "u" } " and " { $snippet "v" } "." } { $description "Creates a new sequence of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the first half of " { $snippet "u" } " and " { $snippet "v" } "." }
{ $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
{ $examples { $examples
{ $example """USING: kernel math.vectors prettyprint ; { $example """USING: kernel math.vectors prettyprint ;
{ "A" "B" "C" "D" } { "1" "2" "3" "4" } vmerge-head .""" { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge-head) ."""
"""{ "A" "1" "B" "2" }""" """{ "A" "1" "B" "2" }"""
} } ; } } ;
HELP: vmerge-tail HELP: (vmerge-tail)
{ $values { "u" "a sequence" } { "v" "a sequence" } { "t" "a sequence" } } { $values { "u" "a sequence" } { "v" "a sequence" } { "t" "a sequence" } }
{ $description "Creates two new sequences of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the tail half of " { $snippet "u" } " and " { $snippet "v" } "." } { $description "Creates a new sequence of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the tail half of " { $snippet "u" } " and " { $snippet "v" } "." }
{ $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
{ $examples { $examples
{ $example """USING: kernel math.vectors prettyprint ; { $example """USING: kernel math.vectors prettyprint ;
{ "A" "B" "C" "D" } { "1" "2" "3" "4" } vmerge-tail .""" { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge-tail) ."""
"""{ "C" "3" "D" "4" }""" """{ "C" "3" "D" "4" }"""
} } ; } } ;
{ vmerge vmerge-head vmerge-tail } related-words { vmerge (vmerge) (vmerge-head) (vmerge-tail) } related-words
HELP: vbroadcast HELP: vbroadcast
{ $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "v" "a SIMD array" } } { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "v" "a SIMD array" } }

View File

@ -91,10 +91,15 @@ PRIVATE>
: hlshift ( u n -- w ) '[ _ <byte-array> prepend 16 head ] change-underlying ; : hlshift ( u n -- w ) '[ _ <byte-array> prepend 16 head ] change-underlying ;
: hrshift ( u n -- w ) '[ _ <byte-array> append 16 tail* ] change-underlying ; : hrshift ( u n -- w ) '[ _ <byte-array> append 16 tail* ] change-underlying ;
: vmerge-head ( u v -- h ) over length 2 / '[ _ head-slice ] bi@ [ zip ] keep concat-as ; : (vmerge-head) ( u v -- h )
: vmerge-tail ( u v -- t ) over length 2 / '[ _ tail-slice ] bi@ [ zip ] keep concat-as ; over length 2 /i '[ _ head-slice ] bi@ [ zip ] keep concat-as ;
: (vmerge-tail) ( u v -- t )
over length 2 /i '[ _ tail-slice ] bi@ [ zip ] keep concat-as ;
: vmerge ( u v -- h t ) [ vmerge-head ] [ vmerge-tail ] 2bi ; inline : (vmerge) ( u v -- h t )
[ (vmerge-head) ] [ (vmerge-tail) ] 2bi ; inline
: vmerge ( u v -- w ) [ zip ] keep concat-as ;
: vand ( u v -- w ) over '[ [ _ element>bool ] bi@ and ] 2map ; : vand ( u v -- w ) over '[ [ _ element>bool ] bi@ and ] 2map ;
: vandn ( u v -- w ) over '[ [ _ element>bool ] bi@ [ not ] dip and ] 2map ; : vandn ( u v -- w ) over '[ [ _ element>bool ] bi@ [ not ] dip and ] 2map ;

View File

@ -120,7 +120,7 @@ TYPED:: m4^n ( m: matrix4 n: fixnum -- m^n: matrix4 )
identity-matrix4 n [ m m4. ] times ; identity-matrix4 n [ m m4. ] times ;
: vmerge-diagonal* ( x y -- h t ) : vmerge-diagonal* ( x y -- h t )
[ vmerge-head ] [ swap vmerge-tail ] 2bi ; inline [ (vmerge-head) ] [ swap (vmerge-tail) ] 2bi ; inline
: vmerge-diagonal ( x -- h t ) : vmerge-diagonal ( x -- h t )
0.0 float-4-with vmerge-diagonal* ; inline 0.0 float-4-with vmerge-diagonal* ; inline
@ -128,7 +128,7 @@ TYPED: diagonal-matrix4 ( diagonal: float-4 -- matrix: matrix4 )
[ vmerge-diagonal [ vmerge-diagonal ] bi@ ] make-matrix4 ; [ vmerge-diagonal [ vmerge-diagonal ] bi@ ] make-matrix4 ;
: vmerge-transpose ( a b c d -- a' b' c' d' ) : vmerge-transpose ( a b c d -- a' b' c' d' )
[ vmerge ] bi-curry@ bi* ; inline [ (vmerge) ] bi-curry@ bi* ; inline
TYPED: transpose-matrix4 ( matrix: matrix4 -- matrix: matrix4 ) TYPED: transpose-matrix4 ( matrix: matrix4 -- matrix: matrix4 )
[ rows vmerge-transpose vmerge-transpose ] make-matrix4 ; [ rows vmerge-transpose vmerge-transpose ] make-matrix4 ;
@ -144,8 +144,8 @@ TYPED:: translation-matrix4 ( offset: float-4 -- matrix: matrix4 )
[ [
float-4{ 1.0 1.0 1.0 1.0 } :> diagonal float-4{ 1.0 1.0 1.0 1.0 } :> diagonal
offset 0 float-4-with vmerge offset 0 float-4-with (vmerge)
[ 0 float-4-with swap vmerge ] bi@ drop :> z :> y :> x [ 0 float-4-with swap (vmerge) ] bi@ drop :> z :> y :> x
diagonal y vmerge-diagonal* diagonal y vmerge-diagonal*
[ x vmerge-diagonal* ] [ x vmerge-diagonal* ]
@ -194,7 +194,7 @@ TYPED:: frustum-matrix4 ( xy: float-4 near: float far: float -- matrix: matrix4
float-4{ t t f f } xy near far - float-4-with v? ! denom float-4{ t t f f } xy near far - float-4-with v? ! denom
v/ :> fov v/ :> fov
fov 0.0 float-4-with vmerge-head vmerge-diagonal fov 0.0 float-4-with (vmerge-head) vmerge-diagonal
fov float-4{ f f t t } vand fov float-4{ f f t t } vand
float-4{ 0.0 0.0 -1.0 0.0 } float-4{ 0.0 0.0 -1.0 0.0 }
] make-matrix4 ; ] make-matrix4 ;

View File

@ -30,6 +30,7 @@ const char *default_image_path()
char *new_path = new char[PATH_MAX + SUFFIX_LEN + 1]; char *new_path = new char[PATH_MAX + SUFFIX_LEN + 1];
memcpy(new_path,path,len + 1); memcpy(new_path,path,len + 1);
memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1); memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1);
free(const_cast<char *>(path));
return new_path; return new_path;
} }

View File

@ -3,7 +3,7 @@
namespace factor namespace factor
{ {
/* Snarfed from SBCL linux-so.c. You must delete[] the result yourself. */ /* Snarfed from SBCL linux-so.c. You must free() the result yourself. */
const char *vm_executable_path() const char *vm_executable_path()
{ {
char *path = new char[PATH_MAX + 1]; char *path = new char[PATH_MAX + 1];
@ -17,7 +17,10 @@ const char *vm_executable_path()
else else
{ {
path[size] = '\0'; path[size] = '\0';
return safe_strdup(path);
const char *ret = safe_strdup(path);
delete[] path;
return ret;
} }
} }