Vector Operations

In this section, we'll discuss vector operations, which involve operations between arrays.

- Table of Contents -

Vector Operations

VCSSL supports vector operations, enabling the same operation to be applied uniformly across all elements of operand arrays.

To perform vector operations, excluding the plain assignment operation "=", it's generally required that the dimensions and sizes of all array variables in the expression are the same. Additionally, non-array variables can be included in expressions, and in such cases, they are treated as if they were arrays storing the same value for all elements.

Operators Supporting Vector Operations

Vector operations are supported by most operators, including:

These operators automatically engage in vector operations whenever the operands (*) are arrays.

* Values or variables involved in the operation, e.g: a and b in "a + b".
Size Restrictions for Assignment and Compound Assignment Operators

There is difference between size restrictions of assignment operations and compound assignment operations.

Performing Addition with Vector Operations

Let's actually perform addition using vector operations:

SIMDAddition.vcssl

- Execution Result -

30

When executed, it displays 30. Let's break down the process since it's a bit lengthy.

First, arrays "a" and "b" with 11 elements each are initialized. a is assigned the square of integers from 0 to 10, and b is assigned integers from 0 to 10 directly. Then, an array c with 11 elements is created.

Next, the line "c = a + b" executes vector addition. This operation assigns the following values to c:

c[0] = a[0] + b[0] ;
c[1] = a[1] + b[1] ;

c[10] = a[10] + b[10] ;

という内容が代入されます。

Finally, the function to print c[5] is called, and the program ends.

For c[5], it contains a[5] + b[5], which is 25 + 5, hence the output value of 30 as expected. This confirms that vector addition was successfully performed.

Acknowledgement: We greatly appreciate the cooperation of two ChatGPT AIs in translating this page.
» How we translated this page