Selection statements, If statement – Altera Nios II C2H Compiler User Manual
Page 46

3–6
9.1
Altera Corporation
Nios II C2H Compiler User Guide
November 2009
One-to-One C-to-Hardware Mapping
The fundamental iteration statement for the C2H Compiler is the
do
loop,
which evaluates its condition at the end of each iteration. See section
“Loop Pipelining” on page 3–42
for information about loop state
machines and scheduling.
Selection Statements
A selection statement (
if-else
,
case
,
switch
, and
?:
) translates to a
multiplexer in hardware. The structure of the hardware depends on the
type of statement, as described in the following sections.
if Statement
An
if-else
statement translates to three elements in hardware:
■
Logic to perform all operations in the
then
block
■
Logic to perform all operations in the
else
block
■
Selection logic that determines which result to use
The results of each element are registered, and the registered signals feed
a multiplexer.
If the
if
statement has both a
then
and an
else
block, the operations for
both blocks execute in parallel. When all operations have completed, the
multiplexer selects which value propagates to subsequent statements,
based on the value of the control expression.
shows the circuit that results from the code in
Example 3–2. If-else Logic
if (foo > bar)
foo += bar;
else
foo *= bar;