add SIMDS: ... ; and SPECIALIZED-ARRAYS: ... ; syntax
							parent
							
								
									18b3c120a7
								
							
						
					
					
						commit
						07aa2620c6
					
				| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,3 +37,6 @@ PRIVATE>
 | 
			
		|||
SYNTAX: SIMD:
 | 
			
		||||
    scan-word define-simd-vocab use-vocab ;
 | 
			
		||||
 | 
			
		||||
SYNTAX: SIMDS:
 | 
			
		||||
    \ ; parse-until [ define-simd-vocab use-vocab ] each ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 "<T-array>" } { "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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -154,6 +154,9 @@ M: c-type-name c-direct-array-constructor
 | 
			
		|||
    dup [ "<direct-" "-array>" 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 ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue