Vectorized gain block example, Vectorized gain block example -3 – National Instruments AutoCode NI MATRIX User Manual

Page 166

Advertising
background image

Chapter 6

Vectorized Code Generation

© National Instruments Corporation

6-3

AutoCode Reference

where

Y(i) is the ith output

U(i) is the ith input

GainParameter(i) is the ith gain value

i is the range <1..x>, where x is the number of outputs of the block

As you can see from the code generation, each of the ith elements of the
gain block is represented by a uniquely named variable. Therefore, the
basic equation is considered to be unrolled or code generated with scalars.

The second characteristic is the gain parameters. As you can see, those
values are hard-coded into the generated code instead of being represented
symbolically. With scalar code generation, constants are always
hard-coded.

Vectorized Gain Block Example

Before showing the code for the vectorized gain block, you need to know
what to look for and compare against the scalar code. First, look at the
implementation of the gain block in Example 6-2. Notice that the code is
rolled into a single for-loop. Also notice the use of arrays to access the data
and that gain parameter values are no longer hard-coded. The values appear
in the ubiquitous

R_P

array.

Example 6-2

Vectorized Code Generation for Gain Block Example

void subsys_1(U, Y)

struct _Sys_ExtIn *U;

struct _Subsys_1_out *Y;

{

static RT_INTEGER iinfo[4];

/***** Parameters. *****/

static RT_FLOAT R_P[10];

RT_INTEGER cnt;

static const RT_FLOAT _R_P[10] = {1.2, 2.3, 3.4, 4.5, 5.6, 6.7,

7.8, 8.9, 9.1, 10.11};

/***** Algorithmic Local Variables. *****/

RT_INTEGER i;

/******* Initialization. *******/

Advertising