101 Innovation Drive San Jose, CA 95134 www.altera.comNios II C2H Compiler User GuideNios II C2H Compiler Version: 9.1Document Date: November 2009
1–4 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Introductionimplementing entire systems on a chip. As a result, the tools av
4–6 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009ResourcesFigure 4–1. Build Report - ResourcesThe resources section contains
Altera Corporation 9.1 4–7November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H Viewmemory, making it impossible for the accelerator t
4–8 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Resourcesor a write. However, when an Avalon-MM master port is shared among
Altera Corporation 9.1 4–9November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewFigure 4–3. Multiplier Resources1 The resource usa
4–10 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009PerformancePerformanceThe performance section of the C2H build report detai
Altera Corporation 9.1 4–11November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewLoop LatencyAs mentioned in Chapter 3, C-to-Hardw
4–12 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009PerformanceFigure 4–4. CPLI ReportThe report identifies two assignments con
Altera Corporation 9.1 4–13November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewFigure 4–5. CRC Dependency GraphSince the critica
4–14 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Performancesoon as the previous execution is complete. Not surprisingly, th
Altera Corporation 9.1 4–15November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewScheduling Information Per AssignmentTypically th
Altera Corporation 9.1 1–5November 2009 Nios II C2H Compiler User GuideIntroduction to the C2H CompilerThe Nios II C-to-Hardware Acceleration (C2H)
4–16 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009PerformanceFigure 4–8. CRC Assignment Sequence Scheduling Information Per S
Altera Corporation 9.1 4–17November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewThis section shows you the assignments that occur
4–18 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009PerformanceFigure 4–10. Schedule by State(State 0)(State 3)(State 2)(State
Altera Corporation 9.1 4–19November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewIn the case of Example 4–2, a total of 12 states
4–20 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Further Reading
Altera Corporation 9.1 5–1 November 2009 5. Accelerating Code Using the Nios II Software Build Tools Command LineCreating an Accelerator from th
5–2 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009C2H Performance MetricsExample 5–1 shows a typical nios2-c2h-generate-makefi
Altera Corporation 9.1 5–3November 2009 Nios II C2H Compiler User GuideAccelerating Code Using the Nios II Software Build Tools Command LineThe rep
5–4 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009C2H Performance Metrics
Altera Corporation 9.1 6–1 November 2009 6. Pragma ReferenceIntroductionThe C2H Compiler uses pragmas that allow user control of master-slave conn
1–6 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009C2H Compiler ConceptsC2H Support in Nios II Tool FlowsThe Nios II IDE is the
6–2 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Connection PragmaReducing Arbitration LogicExample 6–1 illustrates use of th
Altera Corporation 9.1 6–3November 2009 Nios II C2H Compiler User GuidePragma Referencemaster port when it begins a sequence of transfer requests.
6–4 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Interrupt PragmaInterrupt PragmaTo use a hardware accelerator in interrupt m
Altera Corporation 9.1 6–5November 2009 Nios II C2H Compiler User GuidePragma ReferenceExample 6–4. Interrupt Header File#ifndef ALT_C2H_COPROCESS_
6–6 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Unshare Pointer PragmaExample 6–5. Automatically Shared Master Port#pragma a
Altera Corporation 9.1 7–1 November 2009 7. ANSI C Compliance and RestrictionsIntroductionThe Nios II C-to-Hardware Acceleration (C2H) Compiler s
7–2 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Language Escape character sequences in character constants are supported if
Altera Corporation 9.1 7–3November 2009 Nios II C2H Compiler User GuideANSI C Compliance and RestrictionsArray Initialization (Section 6.7.8, Parag
7–4 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009LanguageThe following example, which passes the address of a as the argument
Altera Corporation 9.1 7–5November 2009 Nios II C2H Compiler User GuideANSI C Compliance and RestrictionsFor example, the following code shows two
Altera Corporation 9.1 1–7November 2009 Nios II C2H Compiler User GuideIntroduction to the C2H CompilerC2H Compiler calls other tools in the backgr
7–6 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009LanguageExample 7–1 defines three sub-functions, sub_plus_one(), sub_plus_tw
Altera Corporation 9.1 7–7November 2009 Nios II C2H Compiler User GuideANSI C Compliance and RestrictionsFunction Prototypes (Section 6.9.1, Paragr
7–8 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009LanguageExample 7–3. Nonrecursive Implementation of Factorial Functionint fa
Altera Corporation 9.1 7–9November 2009 Nios II C2H Compiler User GuideANSI C Compliance and Restrictions{ char *c1 = "??<"; return
7–10 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Other Restrictions
Altera Corporation 9.1 1Nios II C2H CompilerAdditional InformationReferenced DocumentsThis user guide references the following documents: Quartus II
2 9.1 Altera Corporation Nios II C2H Compiler User GuideRevision HistoryRevision HistoryThe table below displays the revision history for the chapte
Altera Corporation 9.1 3Nios II C2H Compiler User GuideAdditional InformationHow to Contact AlteraFor the most up-to-date information about Altera
4 9.1 Altera Corporation Nios II C2H Compiler User GuideTypographic ConventionscA caution calls attention to a condition or possible situation that
1–8 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009C2H Compiler ConceptsThe C2H Compiler Operates at the Function LevelCode you
Altera Corporation 9.1 1–9November 2009 Nios II C2H Compiler User GuideIntroduction to the C2H CompilerSystem ArchitectureFigure 1–1 shows the arch
1–10 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009C2H Compiler ConceptsThe accelerator's connections are managed by the
Altera Corporation 9.1 1–11November 2009 Nios II C2H Compiler User GuideIntroduction to the C2H CompilerThe software wrapper, executing on the Nios
1–12 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009C2H Compiler Concepts Subfunctions called within an accelerated function a
Altera Corporation 9.1 1–13November 2009 Nios II C2H Compiler User GuideIntroduction to the C2H CompilerC Code Appropriate for Hardware Acceleratio
Copyright © 2009 Altera Corporation. All rights reserved. Altera, The Programmable Solutions Company, the stylized Altera logo, specific device des-ig
1–14 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009C Code Appropriate for Hardware AccelerationExample 1–1. Checksum Calculati
Altera Corporation 9.1 1–15November 2009 Nios II C2H Compiler User GuideIntroduction to the C2H Compiler If the code contains C syntax not support
1–16 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Next Stepsextent that you analyze the code and understand it. In either cas
Altera Corporation 9.1 2–1 November 2009 2. Getting Started TutorialIntroductionThis chapter describes the design flow for the Nios® II C-to-Har
2–2 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Typical Design FlowTypical Design FlowA typical design flow using the C2H Co
Altera Corporation 9.1 2–3November 2009 Nios II C2H Compiler User GuideGetting Started TutorialDuring the design process with the C2H Compiler, you
2–4 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009TutorialOpenCore Plus hardware evaluation supports the tethered mode of oper
Altera Corporation 9.1 2–5November 2009 Nios II C2H Compiler User GuideGetting Started Tutorialf You can download dma_c2h_tutorial.c from the Nios
2–6 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Tutorial2. Set up the hardware project directorya. Using a file management t
Altera Corporation 9.1 2–7November 2009 Nios II C2H Compiler User GuideGetting Started Tutorial3. If the Welcome to the Altera Nios II IDE page dis
Altera Corporation 9.1 iii ContentsChapter 1. Introduction to the C2H CompilerUser Guide Overview ...
2–8 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Tutorial2. Observe the execution time in the Console view. Example 2–1 shows
Altera Corporation 9.1 2–9November 2009 Nios II C2H Compiler User GuideGetting Started Tutorialb. Turn on Build software, generate SOPC Builder sys
2–10 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009TutorialRebuild the ProjectTo rebuild the project, perform the following st
Altera Corporation 9.1 2–11November 2009 Nios II C2H Compiler User GuideGetting Started Tutorial1 If you copy or move a C2H project to a different
2–12 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Tutorial4. Expand the Resources section and all subsections, as shown in Fi
Altera Corporation 9.1 2–13November 2009 Nios II C2H Compiler User GuideGetting Started Tutorial5. Expand the Performance section and all subsectio
2–14 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Tutorialf For further information on optimizing C2H Compiler results, refer
Altera Corporation 9.1 2–15November 2009 Nios II C2H Compiler User GuideGetting Started Tutoriala. If the Programmer window is not still open, on t
2–16 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Next Steps2. Rebuild the project in the Nios II IDE. 1 You must rebuild the
Altera Corporation 9.1 2–17November 2009 Nios II C2H Compiler User GuideGetting Started Tutorialmore iterations of optimization to produce better r
iv 9.1 Altera Corporation Nios II C2H Compiler User GuideContentsNext Steps ...
2–18 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Next Steps
Altera Corporation 9.1 3–1 November 2009 3. C-to-Hardware Mapping ReferenceThis chapter describes how the Nios® II C-to-Hardware Acceleration (C
3–2 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009One-to-One C-to-Hardware MappingTable 3–1 lists the equivalent hardware stru
Altera Corporation 9.1 3–3November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceThere are two types of exceptions to this rul
3–4 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009One-to-One C-to-Hardware MappingPipelined Operations and AssignmentsThe C2H
Altera Corporation 9.1 3–5November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–1 shows the hardware that results fr
3–6 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009One-to-One C-to-Hardware MappingThe fundamental iteration statement for the
Altera Corporation 9.1 3–7November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–4. if-else LogicIf the if statement
3–8 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009One-to-One C-to-Hardware MappingFigure 3–5. if Logic Without elseConditional
Altera Corporation 9.1 3–9November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–6 shows the circuit that results fro
Altera Corporation 9.1 vNios II C2H Compiler User GuideContentsConnection Pragma ...
3–10 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009One-to-One C-to-Hardware MappingTable 3–4 shows an example of a switch stat
Altera Corporation 9.1 3–11November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–7. switch LogicSubfunction CallsA s
3–12 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009One-to-One C-to-Hardware MappingTable 3–5 shows an example of a subfunction
Altera Corporation 9.1 3–13November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceThe Nios II C2H Compiler does not perform an
3–14 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Variable DeclarationsScalar VariablesFor local scalar variables, the C2H Co
Altera Corporation 9.1 3–15November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping Reference• Arrays that are initialized• Global variab
3–16 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Memory Accessesbehavior of a C function accessing memory is the same, regar
Altera Corporation 9.1 3–17November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceBecause the array subscript operation and th
3–18 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Memory AccessesExample 3–10 shows two dereferences that are identical insid
Altera Corporation 9.1 3–19November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceExample 3–12 demonstrates another case of no
vi 9.1 Altera Corporation Nios II C2H Compiler User GuideContents
3–20 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Memory AccessesExample 3–13 demonstrates the use of volatile to guarantee m
Altera Corporation 9.1 3–21November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceEach of these signals is registered at the m
3–22 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Memory Accessesport. After some number of clock cycles determined by the sl
Altera Corporation 9.1 3–23November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceThe write-data signal for the Avalon-MM mast
3–24 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Memory AccessesSpecifying Master-Slave ConnectionsBy default, the C2H Compi
Altera Corporation 9.1 3–25November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceExample 3–15 illustrates usage of the connec
3–26 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Memory AccessesExample 3–17 connects the variable x in function myfunc to t
Altera Corporation 9.1 3–27November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceAlthough an array is considered to be a poin
3–28 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Memory AccessesStructure and Union OperatorsThe structure and union constru
Altera Corporation 9.1 3–29November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceConsider the simple struct declaration shown
Altera Corporation 9.1 1–1 November 2009 1. Introduction to the C2H CompilerThe Nios® II C-to-Hardware Acceleration (C2H) Compiler is a tool tha
3–30 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingConsider the simple struct declaration shown in Example 3–25. Exa
Altera Corporation 9.1 3–31November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping Referencehardware. After the C2H Compiler creates the
3–32 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingFigure 3–12. Dependency GraphThe C2H Compiler uses the dependency
Altera Corporation 9.1 3–33November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping Referenceoperations that come before it. Because arra
3–34 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Schedulingcompile-time due to the possibility of aliasing. This dependency
Altera Corporation 9.1 3–35November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–15. __restrict__ Pointer Type Break
3–36 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingFigure 3–16. Pointers Always Depend on ThemselvesIn this example,
Altera Corporation 9.1 3–37November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–17. Using Another Pointer to Avoid
3–38 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Schedulingand mitigate the effects of memory latency. Through close integra
Altera Corporation 9.1 3–39November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–18. Early Scheduling of Read Operat
1–2 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Target AudienceTarget AudienceThis user guide assumes you have at least a ba
3–40 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingFor the purposes of scheduling, the C2H Compiler treats a loop an
Altera Corporation 9.1 3–41November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceIf multiple loops have no interdependencies,
3–42 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingMemory TransfersAvalon-MM system interconnect fabric manages arbi
Altera Corporation 9.1 3–43November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–20. Dependency Graph for a Loop Blo
3–44 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingFigure 3–21 illustrates how the C2H Compiler schedules successive
Altera Corporation 9.1 3–45November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–22 shows the dependency graph for t
3–46 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingFigure 3–23 illustrates how the C2H Compiler schedules successive
Altera Corporation 9.1 3–47November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping Referencethat performs Avalon-MM pipelined read trans
3–48 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingState 1 in Figure 3–24 remains empty because list has two cycles
Altera Corporation 9.1 3–49November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceLoop Latency and Cycles per Loop Iteration (
Altera Corporation 9.1 1–3November 2009 Nios II C2H Compiler User GuideIntroduction to the C2H Compiler Straightforward C-to-hardware mapping – Th
3–50 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009SchedulingExample 3–38. Pipelined Subfunctionint MAX(int a, int b){ return
Altera Corporation 9.1 3–51November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceResource SharingThe C2H Compiler is capable
3–52 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Resource SharingThe resource sharing technique used for memory accesses dif
Altera Corporation 9.1 3–53November 2009 Nios II C2H Compiler User GuideC-to-Hardware Mapping ReferenceFigure 3–26. Shared And Independent Resource
3–54 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009Resource Sharing
Altera Corporation 9.1 4–1 November 2009 4. Understanding the C2H ViewIntroductionThis chapter discusses the Altera Nios II C-to-Hardware Accele
4–2 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009OverviewTable 4–1 *summarizes the project build configurations.Table 4–1. Pr
Altera Corporation 9.1 4–3November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewFunction Build ConfigurationsThe function build co
4–4 9.1 Altera Corporation Nios II C2H Compiler User Guide November 2009ResourcesTable 4–2. Function Build ConfigurationsConfiguration MeaningUse ha
Altera Corporation 9.1 4–5November 2009 Nios II C2H Compiler User GuideUnderstanding the C2H ViewExample 4–1. Vector Power Calculation#pragma alter
Comments to this Manuals