Scalar variables, Arrays, structures, and unions, Scalar variables –14 – Altera Nios II C2H Compiler User Manual

Page 54

Advertising
background image

3–14

9.1

Altera Corporation

Nios II C2H Compiler User Guide

November 2009

Variable Declarations

Scalar Variables

For local scalar variables, the C2H Compiler creates hardware registers
inside the accelerator. For example, declaring a

char

creates an 8-bit

register; declaring a

short int

creates a 16-bit register, and so forth.

Declaring a pointer allocates only storage for the pointer itself. For
example, declaring a

char*

creates a 32-bit register to store the address

of a

char

. If you use a scalar variable within a pipelined loop, then its

register is replicated for pipelining as needed.

The C2H Compiler considers a variable to be scalar if it is not an array,
structure, or union.

Example 3–5

demonstrates some examples of scalar

variables.

Example 3–5. Scalar Variables

int i;
int *p;
char **c;
struct struct_type *pointer_to_struct;
int (*pointer_to_array)[8];

Example 3–6

demonstrates some examples of nonscalar variables.

Example 3–6. Nonscalar Variables

int data[1024];
struct struct_type tx_rec;
int *array_of_pointers[8];

Arrays, Structures, and Unions

For local arrays, structures, and unions, the C2H Compiler creates
memory elements inside the accelerator. Depending on the size of the
memory required and the target device family, the C2H Compiler can
implement these memory elements either as logic elements or embedded
memory blocks.

The memory elements are single-ported. As a result, a given array, union,
or structure has a maximum bandwidth of one transaction per cycle, even
if the C code could be structured to allow parallel scheduling of accesses.

1

The following constructs are declared in the driver file (and
therefore in the processor's data memory), and passed into the
accelerator by reference:

Advertising