. A little bit about optimization, 2d array, 1d array used as 2d, register and volatile.

Slides:



Advertisements
Similar presentations
CS179: GPU Programming Lecture 5: Memory. Today GPU Memory Overview CUDA Memory Syntax Tips and tricks for memory handling.
Advertisements

Instruction Set Design
AU/MITM/1.6 By Mohammed A. Saleh 1. Arguments passed by reference  Until now, in all the functions we have seen, the arguments passed to the functions.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
San Diego Supercomputer Center Performance Modeling and Characterization Lab PMaC Pin: Building Customized Program Analysis Tools with Dynamic Instrumentation.
27-Jun-15 Profiling code, Timing Methods. Optimization Optimization is the process of making a program as fast (or as small) as possible Here’s what the.
30-Jun-15 Profiling. Optimization Optimization is the process of making a program as fast (or as small) as possible Here’s what the experts say about.
1 Arrays & functions Each element of an array acts just like an ordinary variable: Like any ordinary variable, you can pass a single array element to a.
Storage Classes.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Modules and Scope Gabriel Hugh Elkaim Spring 2013.
1 CS/COE0447 Computer Organization & Assembly Language Pre-Chapter 2.
CSCI 130 Scope of Variables Chapter 6. What is scope Parts of program which can access a variable –accessibility –visibility How long variable takes up.
Memory Hierarchy and Cache Memory Jennifer Tsay CS 147 Section 3 October 8, 2009.
CS 2130 Lecture 5 Storage Classes Scope. C Programming C is not just another programming language C was designed for systems programming like writing.
1 Exam / Homework Exam 1 in Class 10 –Open book / open notes HW3 due next class HW4 will be on-line soon. Finishing Chapter 2 of K&R. We will go through.
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);
Survey of Program Compilation and Execution Bangor High School Ali Shareef 2/28/06.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
Compiling “premature optimization is the root of all evil.” -Donald Knuth.
Optimization of C Code The C for Speed
Memory Characteristics Location Capacity Unit of transfer Access method Performance Physical type Physical characteristics Organisation.
Programming Fundamentals Enumerations and Functions.
Building Programs from Existing Information Solutions for programs often can be developed from previously solved problems. Data requirements and solution.
CSE 351 Caches. Before we start… A lot of people confused lea and mov on the midterm Totally understandable, but it’s important to make the distinction.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
A little bit about optimization, 2d array, 1d array used as 2d, register volatile union .
Data representation How do we represent data in a digital system?
“Studying C programming excluding pointers is meaningless.” d0m3z
Arrays Low level collections.
Introduction To Computer Systems
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
Pointers in C.
Help for Lab. 1 Subroutines calling Subroutines
Chapter 1. Introduction to Computers and Programming
Classes & Objects.
Chapter 5 Conclusion CIS 61.
Workshop in Nihzny Novgorod State University Activity Report
Engineering Innovation Center
Stack Data Structure, Reverse Polish Notation, Homework 7
C Passing arrays to a Function
Baremetal C Programming for Embedded Systems
Circular Buffers, Linked Lists
2011/11/10: Lecture 21 CMSC 104, Section 4 Richard Chang
6.12 Default Arguments.
Threads and Memory Models Hal Perkins Autumn 2009
Functions 2: Stupid Function Tricks
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Topics discussed in this section:
Getting serious about “going fast” on the TigerSHARC
CS150 Introduction to Computer Science 1
Explaining issues with DCremoval( )
Data representation How do we represent data in a digital system?
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
Practical Session 8, Memory Management 2
Dynamic Memory A whole heap of fun….
Suggested self-checks: Section 7.11 #1-11
C Data Types and Variable
The Stack.
Data representation How do we represent data in a digital system?
C Language B. DHIVYA 17PCA140 II MCA.
ENERGY 211 / CME 211 Lecture 11 October 15, 2008.
Practical Session 9, Memory Management continues
SPL – PS1 Introduction to C++.
Storage Classes.
A little bit about optimization, 2d array, 1d array used as 2d, register volatile union .
Introduction to Pointers
Introduction to Pointers
Presentation transcript:

. A little bit about optimization, 2d array, 1d array used as 2d, register and volatile

Premature optimization is the root of all evil (or at least most of it) in programming – Donald Knuth Premature optimization What smart people say about Premature optimization…

So, what to do? need  Check if you need to optimize “turn off” debugging  Remember to “turn off” debugging (#define NDEBUG) your compiler your specific hardware  Check what your compiler can do for you on your specific hardware (-O3 -march=pentium4 -mfpmath=sse, inlining of functions,...)  Profilewhere  Profile: check where to optimize common techniques  Use common techniques such as cache,...

1d Array as 2d array int* getElementAddr(int* arr, int r, int c) { return (arr+ r*COLS_NUM + c); } void foo(int* arr) {... *(getElementAddr(arr,r,c)) } 1,21,11,00,20,10,0

1d Array as 2d array int* getElementAddr(int* arr, int r, int c) { return (arr+ r*COLS_NUM + c); } void foo(int* arr) {... *(getElementAddr(arr,r,c)) } What can we do if we use a specific r and c many times and this is the bottleneck section?

1d Array as 2d array void foo(int* arr) { cache_index... size_t cache_index= r*COLS_NUM + c;... cache_index... *(arr + cache_index) } Use cache !

register  Registervery fast memory  Register - a small amount of very fast memory. commonly used values  Provides quick access to commonly used values. if possible.  The register keyword specifies that the variable is to be stored in a machine register, if possible. compiler what and when  Experience has shown that the compiler usually knows much better than humans what should go into registers and when. hierarchy of caches (L1, L2,…)  There is actually an hierarchy of caches (L1, L2,…). We are not going to learn this in this course.

Volatile modified externally  variables that may be modified externally from the declaring object. not be optimized  Variables declared to be volatile will not be optimized by the compiler because their value can change at any time.

Volatile example void foo(void) { int* addr; addr= INPUT_ADDRESS; *addr = 0; while (*addr != 255) ; } Before optimization

Volatile example void foo(void) { int* addr; addr= INPUT_ADDRESS; *addr = 0; while (1) ; } After optimization

Volatile example void foo(void) { volatile volatile int* addr; addr= INPUT_ADDRESS; *addr = 0; while (*addr != 255) ; } After optimization using volatile