Chapter 6
Vectorized Code Generation
6-4
ni.com
if (SUBSYS_PREINIT[1]) {
iinfo[0] = 0;
iinfo[1] = 1;
iinfo[2] = 1;
iinfo[3] = 1;
for( cnt=0;cnt<10;cnt++ ) {
R_P[cnt] = _R_P[cnt];
}
SUBSYS_PREINIT[1] = FALSE;
return;
}
/***** Output Update. *****/
/* ---------------------------- Gain Block */
/* {gain..2} */
for (i=1; i<=10; i++) {
Y->gain_2_1[-1+i] = R_P[-1+i]*U->gain_1[-1+i];
}
In summary, Example 6-2 shows some of the requirements for vectorized
code generation:
•
The block’s input and output signals must be arrays.
•
Constant parameter data must be represented in an array.
•
An array must represent signals of the same data type.
As far as the constant parameter data, AutoCode automatically bundles the
data into the
R_P
(or other parameter array) as needed. However, the inputs
and outputs of the block are controlled by the signal connectivity of the
model. AutoCode will never reconnect your model to provide
vectorization.
Array Subscripts
An interesting characteristic of the vectorized code generation is the
way array subscripts are generated. Looking closely, you will see in
Example 6-2 that all subscripts are generated as
-1+i
. C arrays are
0-based, meaning that the first array element is the 0th element.
BlockScript, our internal language to describe block algorithms, defines
arrays as being 1-based.
1
Therefore, when a block is translated into code,
a translation from 1-based access into 0-based access is performed. In
1
BlockScript was previously used to generate FORTRAN code in which arrays are 1-based.