19
1 © 2008, Renesas Technology America, Inc., All Rights Reserved Purpose This training module provides an overview of optimization techniques used in the HEW environment to improve program execution and memory size. Objectives Learn the different approaches used by programmers. Understand how to configure the HEW Toolchain to achieve basic optimization. Content 19 pages 3 questions Learning Time 25 minutes Introduction

© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose This training module provides an overview of optimization techniques used in

Embed Size (px)

Citation preview

1© 2008, Renesas Technology America, Inc., All Rights Reserved

Purpose

This training module provides an overview of optimization techniques used in the HEW environment to improve program execution and memory size.

Objectives

Learn the different approaches used by programmers.

Understand how to configure the HEW Toolchain to achieve basic optimization.

Content

19 pages

3 questions

Learning Time

25 minutes

Introduction

2© 2008, Renesas Technology America, Inc., All Rights Reserved

General approaches Choice of compiler Compiler settings Programming algorithms and techniques Rewriting program in assembly

HEW provides tools for easier, more effective optimization

Optimization approaches in HEW H8 Toolchain environment H8 Compiler options Inter-module Optimizer Code and algorithm modification

Optimization Approaches

3© 2008, Renesas Technology America, Inc., All Rights Reserved

Program Speed vs. Size

Faster execution, but bigger code sizeFaster execution,

but bigger code sizeSmaller code size,

but slower executionSmaller code size,

but slower execution

Example: Programs use different coding methods to perform similar task

4© 2008, Renesas Technology America, Inc., All Rights Reserved

Getting Started

Steps to begin optimization Click on Build Select H8S,H8/300 Standard

Toolchain

Optimization can be performed

in three areas C/C++ Files Link Library Standard Library

5© 2008, Renesas Technology America, Inc., All Rights Reserved

C/C++ Optimization

Optimize the following types of files: C files (*.c) C++ files (*.cpp)

Configure the Toolchain for C/C++ optimization Click on C/C++ tab

Select entire project or individual files from “Tutorial”

Select optimization category and type

Inter-module optimization is not selected at this time

6© 2008, Renesas Technology America, Inc., All Rights Reserved

Optimize the following types of files:

• Library (*.lib, *.obj)

Configure items in the Link/Library

• Click on Link/Library tab

• Select the whole project (“Tutorial” in this example)

• Select optimization category and type

Link/Library Optimization

7© 2008, Renesas Technology America, Inc., All Rights Reserved

Optimize items in the

Standard Library Click on Standard

Library tab

Select project from Tutorial

Select optimization category and type

Standard Library Optimization

9© 2008, Renesas Technology America, Inc., All Rights Reserved

Inter-module Optimizer

Compiler generates inter-module supplementary information

Inter-module Optimizer uses supplementary information to optimize each module before linking

LinkageEditor

CompilerInter-module

Optimizer

Source Program

Object Program

Sub Command

Object program

Outputs inter-module

optimizing information

Sub Command

Load Module

Linker executes automatically after optimization is complete

10© 2008, Renesas Technology America, Inc., All Rights Reserved

Size and Speed Improvements

Unifies constants and literal strings

Deletes unreferenced symbols

Does short absolute addressing

Does indirect addressing

Does register save and restore

Unifies same codes

Optimizes branch instructions

Improvements

Size Speed

Improvements

Size SpeedInter-module Optimizer

11© 2008, Renesas Technology America, Inc., All Rights Reserved

Overall Improvement

Conventional Optimization only

With Inter-module Optimizaton

ABCD.abs

A.c

B.c

C.cD.c

A.c

B.c

C.c

D.c

Optimization on compiling

Optimization on compiling

Optimization on compiling

Optimization on compiling

Optimization on linking

When optimization is enabled, code in Debugging window won’t match original source code.

Better ROM Efficiency and Faster Execution

Code

Size

12© 2008, Renesas Technology America, Inc., All Rights Reserved

Quantifying the Improvements

Determine memory size improvements- View Map file

Measure execution speed improvements- Use emulator’s built-in time measurement- Use simulator’s calculated execution cycles- Make physical ∆t measurement via port pin

04000400

1C251C25Sort( )Sort( )

SortSort

timetimeStart End

14© 2008, Renesas Technology America, Inc., All Rights Reserved

Using Mapview to Measure Size

Configure compiler to generate map file (.map)

Select C/C++, Assembly, or Link/Library from Debug configuration directory

Check “Generate file” and click on “Enable all”

Launch Mapview to view map file

Launch Mapview

15© 2008, Renesas Technology America, Inc., All Rights Reserved

Mapview shows

Code size Global variables Variable address

allocation Section address

Selected area (P section) shows

Sizes of functions in selected section

Size of program’s Main function

Viewing Size Improvement

16© 2008, Renesas Technology America, Inc., All Rights Reserved

Oscilloscope: - Manual time measurement

Simulator Status window: - Number of instructions and cycles

Emulator Status window: - Run time

Emulator/Simulator Trace windows

Methods of Determining Speed

Simulator Status window shows number of instructions and cycles executed

Emulator Status window shows the run time in ns (depending on the resolution setting)

17© 2008, Renesas Technology America, Inc., All Rights Reserved

Data in Trace Windows

Emulator Trace window shows cumulative instruction timestamp at a preset resolution of 125ns

Simulator Trace window indicates cumulative cycles

19© 2008, Renesas Technology America, Inc., All Rights Reserved

Course Summary

Optimizing programs for size or speed

Optimization tools in the HEW Toolchain

Inter-module optimization

Techniques for measuring size and speed

Download a free evaluation copy of HEW at: www.renesas.com/hew