Chapter 6
Vectorized Code Generation
6-2
ni.com
Scalar Gain Block Example
Example 6-1 shows the scalar code generated for a gain block.
Example 6-1
Scalar Code Generated for Gain Block Example
void subsys_1(U, Y)
struct _Sys_ExtIn *U;
struct _Subsys_1_out *Y;
{
static RT_INTEGER iinfo[4];
/******* Initialization. *******/
if (SUBSYS_PREINIT[1]) {
iinfo[0] = 0;
iinfo[1] = 1;
iinfo[2] = 1;
iinfo[3] = 1;
SUBSYS_PREINIT[1] = FALSE;
return;
}
/***** Output Update. *****/
/* ---------------------------- Gain Block */
/* {gain..2} */
Y->gain_2_1 = 1.2*U->gain_1;
Y->gain_2_2 = 2.3*U->gain_2;
Y->gain_2_3 = 3.4*U->gain_3;
Y->gain_2_4 = 4.5*U->gain_4;
Y->gain_2_5 = 5.6*U->gain_5;
Y->gain_2_6 = 6.7*U->gain_6;
Y->gain_2_7 = 7.8*U->gain_7;
Y->gain_2_8 = 8.9*U->gain_8;
Y->gain_2_9 = 9.1*U->gain_9;
Y->gain_2_10 = 10.11*U->gain_10;
The scalar code for the gain block should be familiar. Some characteristics
of the code for later comparison should be mentioned. First, this is the
canonical example of the concept of unrolling. The basic equation for a
gain block is:
Y
(
i
) =
GainParameter
(
i
) *
U
(
i
)