From 07aa2620c610355688aa2e91bffc9c0f06ca0531 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 9 Oct 2009 10:43:37 -0500 Subject: [PATCH] add SIMDS: ... ; and SPECIALIZED-ARRAYS: ... ; syntax --- basis/math/vectors/simd/simd-docs.factor | 12 +++++++++++- basis/math/vectors/simd/simd-tests.factor | 10 +--------- basis/math/vectors/simd/simd.factor | 3 +++ .../specialized-arrays-docs.factor | 16 +++++++++++++--- .../specialized-arrays-tests.factor | 7 +------ .../specialized-arrays/specialized-arrays.factor | 3 +++ 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/basis/math/vectors/simd/simd-docs.factor b/basis/math/vectors/simd/simd-docs.factor index c7adcbdd7d..97ff99cd28 100644 --- a/basis/math/vectors/simd/simd-docs.factor +++ b/basis/math/vectors/simd/simd-docs.factor @@ -37,7 +37,10 @@ ARTICLE: "math.vectors.simd.types" "SIMD vector types" "Each SIMD vector type is named " { $snippet "scalar-count" } ", where " { $snippet "scalar" } " is a scalar C type and " { $snippet "count" } " is a vector dimension." $nl "To use a SIMD vector type, a parsing word is used to generate the relevant code and bring it into the vocabulary search path; this is the same idea as with " { $link "specialized-arrays" } ":" -{ $subsections POSTPONE: SIMD: } +{ $subsections + POSTPONE: SIMD: + POSTPONE: SIMDS: +} "The following vector types are supported:" { $code "char-16" @@ -205,4 +208,11 @@ HELP: SIMD: { $values { "type" "a scalar C type" } } { $description "Defines 128-bit and 256-bit SIMD arrays for holding elements of " { $snippet "type" } " into the vocabulary search path. The possible type/length combinations are listed in " { $link "math.vectors.simd.types" } " and the generated words are documented in " { $link "math.vectors.simd.words" } "." } ; +HELP: SIMDS: +{ $syntax "SIMDS: type type type ... ;" } +{ $values { "type" "a scalar C type" } } +{ $description "Defines 128-bit and 256-bit SIMD arrays for holding elements of each " { $snippet "type" } " into the vocabulary search path. The possible type/length combinations are listed in " { $link "math.vectors.simd.types" } " and the generated words are documented in " { $link "math.vectors.simd.words" } "." } ; + +{ POSTPONE: SIMD: POSTPONE: SIMDS: } related-words + ABOUT: "math.vectors.simd" diff --git a/basis/math/vectors/simd/simd-tests.factor b/basis/math/vectors/simd/simd-tests.factor index 78c9389591..9e999ba9b7 100644 --- a/basis/math/vectors/simd/simd-tests.factor +++ b/basis/math/vectors/simd/simd-tests.factor @@ -11,15 +11,7 @@ quotations math.constants compiler.units ; QUALIFIED-WITH: alien.c-types c SPECIALIZED-ARRAY: c:float SIMD: c:char -SIMD: c:uchar -SIMD: c:short -SIMD: c:ushort -SIMD: c:int -SIMD: c:uint -SIMD: c:longlong -SIMD: c:ulonglong -SIMD: c:float -SIMD: c:double +SIMDS: c:uchar c:short c:ushort c:int c:uint c:longlong c:ulonglong c:float c:double ; IN: math.vectors.simd.tests ! Make sure the functor doesn't generate bogus vocabularies diff --git a/basis/math/vectors/simd/simd.factor b/basis/math/vectors/simd/simd.factor index af04e283f0..ffa6b5ba18 100644 --- a/basis/math/vectors/simd/simd.factor +++ b/basis/math/vectors/simd/simd.factor @@ -37,3 +37,6 @@ PRIVATE> SYNTAX: SIMD: scan-word define-simd-vocab use-vocab ; +SYNTAX: SIMDS: + \ ; parse-until [ define-simd-vocab use-vocab ] each ; + diff --git a/basis/specialized-arrays/specialized-arrays-docs.factor b/basis/specialized-arrays/specialized-arrays-docs.factor index 6c05324ec5..50e94b65e9 100755 --- a/basis/specialized-arrays/specialized-arrays-docs.factor +++ b/basis/specialized-arrays/specialized-arrays-docs.factor @@ -6,8 +6,15 @@ HELP: SPECIALIZED-ARRAY: { $values { "type" "a C type" } } { $description "Brings a specialized array for holding values of " { $snippet "type" } " into the vocabulary search path. The generated words are documented in " { $link "specialized-array-words" } "." } ; +HELP: SPECIALIZED-ARRAYS: +{ $syntax "SPECIALIZED-ARRAYS: type type type ... ;" } +{ $values { "type" "a C type" } } +{ $description "Brings a set of specialized arrays for holding values of each " { $snippet "type" } " into the vocabulary search path. The generated words are documented in " { $link "specialized-array-words" } "." } ; + +{ POSTPONE: SPECIALIZED-ARRAY: POSTPONE: SPECIALIZED-ARRAYS: } related-words + ARTICLE: "specialized-array-words" "Specialized array words" -"The " { $link POSTPONE: SPECIALIZED-ARRAY: } " parsing word generates the specialized array type if it hasn't been generated already, and adds the following words to the vocabulary search path, where " { $snippet "T" } " is the C type in question:" +"The " { $link POSTPONE: SPECIALIZED-ARRAY: } " and " { $link POSTPONE: SPECIALIZED-ARRAYS: } " parsing words generate specialized array types if they haven't been generated already and add the following words to the vocabulary search path, where " { $snippet "T" } " is the C type in question:" { $table { { $snippet "T-array" } { "The class of arrays with elements of type " { $snippet "T" } } } { { $snippet "" } { "Constructor for arrays with elements of type " { $snippet "T" } "; stack effect " { $snippet "( len -- array )" } } } @@ -18,7 +25,7 @@ ARTICLE: "specialized-array-words" "Specialized array words" { { $snippet ">T-array" } { "Converts a sequence into a specialized array of type " { $snippet "T" } "; stack effect " { $snippet "( seq -- array )" } } } { { $snippet "T-array{" } { "Literal syntax, consists of a series of values terminated by " { $snippet "}" } } } } -"Behind the scenes, these words are placed in a vocabulary named " { $snippet "specialized-arrays.instances.T" } ", however this vocabulary should not be placed in a " { $link POSTPONE: USING: } " form directly. Instead, always use " { $link POSTPONE: SPECIALIZED-ARRAY: } ". This ensures that the vocabulary can get generated the first time it is needed." ; +"Behind the scenes, these words are placed in a vocabulary named " { $snippet "specialized-arrays.instances.T" } ", however this vocabulary should not be placed in a " { $link POSTPONE: USING: } " form directly. Instead, always use " { $link POSTPONE: SPECIALIZED-ARRAY: } " or " { $link POSTPONE: SPECIALIZED-ARRAYS: } ". This ensures that the vocabulary can get generated the first time it is needed." ; ARTICLE: "specialized-array-c" "Passing specialized arrays to C functions" "If a C function is declared as taking a parameter with a pointer or an array type (for example, " { $snippet "float*" } " or " { $snippet "int[3]" } "), instances of the relevant specialized array can be passed in." @@ -80,7 +87,10 @@ ARTICLE: "specialized-arrays" "Specialized arrays" "The " { $vocab-link "specialized-arrays" } " vocabulary implements fixed-length sequence types for storing machine values in a space-efficient manner without boxing." $nl "A specialized array type needs to be generated for each element type. This is done with a parsing word:" -{ $subsections POSTPONE: SPECIALIZED-ARRAY: } +{ $subsections + POSTPONE: SPECIALIZED-ARRAY: + POSTPONE: SPECIALIZED-ARRAYS: +} "This parsing word adds new words to the search path, documented in the next section." { $subsections "specialized-array-words" diff --git a/basis/specialized-arrays/specialized-arrays-tests.factor b/basis/specialized-arrays/specialized-arrays-tests.factor index b7d3371f45..07a457db5c 100755 --- a/basis/specialized-arrays/specialized-arrays-tests.factor +++ b/basis/specialized-arrays/specialized-arrays-tests.factor @@ -8,12 +8,7 @@ assocs prettyprint alien.data math.vectors ; FROM: alien.c-types => float ; SPECIALIZED-ARRAY: int -SPECIALIZED-ARRAY: bool -SPECIALIZED-ARRAY: ushort -SPECIALIZED-ARRAY: char -SPECIALIZED-ARRAY: uint -SPECIALIZED-ARRAY: float -SPECIALIZED-ARRAY: ulonglong +SPECIALIZED-ARRAYS: bool ushort char uint float ulonglong ; [ ulonglong ] [ ulonglong-array{ } element-type ] unit-test diff --git a/basis/specialized-arrays/specialized-arrays.factor b/basis/specialized-arrays/specialized-arrays.factor index b8a3332600..a3d24c10c2 100755 --- a/basis/specialized-arrays/specialized-arrays.factor +++ b/basis/specialized-arrays/specialized-arrays.factor @@ -154,6 +154,9 @@ M: c-type-name c-direct-array-constructor dup [ "" surround ] [ specialized-array-vocab ] bi lookup [ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable +SYNTAX: SPECIALIZED-ARRAYS: + ";" parse-tokens [ parse-c-type define-array-vocab use-vocab ] each ; + SYNTAX: SPECIALIZED-ARRAY: scan-c-type define-array-vocab use-vocab ;