Application Specific Signal Processors S

Similar documents
LECTURE 3. Compiler Phases

CA Compiler Construction

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

Working of the Compilers

CST-402(T): Language Processors

Compilers Crash Course

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

CS426 Compiler Construction Fall 2006

Compiler Design (40-414)

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Programming in C++ 4. The lexical basis of C++

Introduction to Compiler Construction

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

MANIPAL INSTITUTE OF TECHNOLOGY (Constituent Institute of MANIPAL University) MANIPAL

Introduction to Compiler Construction

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

ST. XAVIER S COLLEGE

Advanced Systems Programming

Final CSE 131B Spring 2004

Introduction to Compiler Design

A simple syntax-directed

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Lecture 31: Building a Runnable Program

LECTURE NOTES ON COMPILER DESIGN P a g e 2

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CPS 506 Comparative Programming Languages. Syntax Specification

C - Basics, Bitwise Operator. Zhaoguo Wang

Compilers and Interpreters

Principles of Programming Languages. Lecture Outline

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

PROGRAMMING FUNDAMENTALS

Evaluation of Semantic Actions in Predictive Non- Recursive Parsing

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Compilers and Code Optimization EDOARDO FUSELLA

names names identifiers variables subroutines constants

DOID: A Lexical Analyzer for Understanding Mid-Level Compilation Processes

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

Error Recovery during Top-Down Parsing: Acceptable-sets derived from continuation

ATOMS. 3.1 Interface. The Atom interface is simple: atom.h #ifndef ATOM_INCLUDED #define ATOM_INCLUDED

Formal Languages and Compilers Lecture I: Introduction to Compilers

PLAGIARISM. Administrivia. Compilers. CS143 11:00-12:15TT B03 Gates. Text. Staff. Instructor. TAs. Office hours, contact info on 143 web site

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

DSP Mapping, Coding, Optimization

Compiler Construction LECTURE # 1

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

Compiler Design Overview. Compiler Design 1

Tools of the Trade The C Language Laboration 04. Outline. 1 Tools of the Trade. 2 The C Language. 3 Laboration 04

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

COMP 202 Java in one week

CSC 467 Lecture 3: Regular Expressions

These are reserved words of the C language. For example int, float, if, else, for, while etc.

COS 140: Foundations of Computer Science

A Simple Syntax-Directed Translator

1. Lexical Analysis Phase

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Compilers. Lecture 2 Overview. (original slides by Sam

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Lexical analysis. Syntactical analysis. Semantical analysis. Intermediate code generation. Optimization. Code generation. Target specific optimization

Full file at

COSE312: Compilers. Lecture 1 Overview of Compilers

Parallel Execution of Tasks of Lexical Analyzer using OpenMP on Multi-core Machine

Compilers. Prerequisites

Compiler Theory Introduction and Course Outline Sandro Spina Department of Computer Science

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Grammars and Parsing. Paul Klint. Grammars and Parsing

Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Creating a C++ Program

COP4020 Programming Assignment 1 - Spring 2011

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

Lecture08: Scope and Lexical Address

LECTURE 18. Control Flow

Compilers - Chapter 2: An introduction to syntax analysis (and a complete toy compiler)

COMPILER DESIGN LECTURE NOTES

University of Utrecht. 1992; Fokker, 1995), the use of monads to structure functional programs (Wadler,

COSC121: Computer Systems: Runtime Stack

Variables and literals

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

Compiler Construction

Administrivia. Compilers. CS143 10:30-11:50TT Gates B01. Text. Staff. Instructor. TAs. The Purple Dragon Book. Alex Aiken. Aho, Lam, Sethi & Ullman

2.2 Syntax Definition

Pointers (continued), arrays and strings

BASIC ELEMENTS OF A COMPUTER PROGRAM

Introduction to Lexical Analysis

Lecture 2: C Programming Basic

ISA: The Hardware Software Interface

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

[Syntax Directed Translation] Bikash Balami

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Extending xcom. Chapter Overview of xcom

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

Programming Language Processor Theory

CS 415 Midterm Exam Spring 2002

Advanced Programming & C++ Language

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Reminder: tutorials start next week!

Pioneering Compiler Design

Transcription:

1 Application Specific Signal Processors 521281S Dept. of Computer Science and Engineering Mehdi Safarpour 23.9.2018

Course contents Lecture contents 1. Introduction and number formats 2. Signal processor architectures 3. Transport-triggered processors 4. Program code and compilation 5. Performance optimization 6. Tools and FPGAs

What you will learn this time Structure of a compiler How to improve program performance by SW changes

Introduction In Lecture 2 we concentrated on the processor Human-readable code Compiler Machinereadable code Processor Output

Introduction This time we will concentrate on the compiler Human-readable code Compiler Machinereadable code Processor Output

Compiler structure Human-readable code Compiler

Compiler structure Human-readable code Front-end Compiler Intermediate representation

Compiler structure Human-readable code Front-end Compiler Intermediate representation Optimization Intermediate representation

Compiler structure Human-readable code Front-end Compiler Intermediate representation Optimization Intermediate representation Back-end

Compiler structure Human-readable code Front-end Compiler Intermediate representation Optimization Intermediate representation Back-end Target machine program

Compiler structure C C++ Fortran Java... Front-end Compiler Intermediate representation Optimization Intermediate representation Back-end x86 ARM c6x TTA

language-dependent front-end code optimizer processor dependent back-end Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Lexical analysis: divides the source code into parts Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Lexical analysis: divides the source code into parts for example: Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) y = x + 3 y symbol 1 x symbol 2 = token (=) + token (+) 3 number 1

Lexical analysis: divides the source code into parts for example: Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) y = x + 3 y symbol 1 x symbol 2 = token (=) + token (+) 3 number 1

Lexical analysis: divides the source code into parts An example of an entry that creates an error in the lexical analyzer: 6a = x + c; Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) supposing this is C language, identifiers can not start with a number

Symbol table: maintains a list of symbols that exist in the code Generally there are multiple symbol tables for different parts of the code Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Syntax analyzer (parser) Analyzes the relations between symbols, tokens and numbers according to precendence rules etc. Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Syntax analyzer (parser) Analyzes the relations between symbols, tokens and numbers according to precendence rules etc. y = x + 3 = y + Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) x 3

Syntax analyzer (parser) Analyzes the relations between symbols, tokens and numbers according to precendence rules etc. y = * + 3 = Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) y?

Semantic analyzer Analyzes the relations between symbols, tokens and numbers according to precendence rules etc. Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Semantic analyzer Analyzes the relations between symbols, tokens and numbers according to precendence rules etc. int array[10]; float index; return array[index]; Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Semantic analyzer Analyzes the relations between symbols, tokens and numbers according to precendence rules etc. int array[10]; float index; return array[index]; Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Intermediate code generator Translates the input coming from the previous stages to an abstract language that is used by the compiler for optimization etc. Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Two major styles of intermediate representation exist: 1) syntax trees 2) three-address codes Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Two major styles of intermediate representation exist: 1) syntax trees 2) three-address codes Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) + + * * a - d b c a + a * (b c) + (b - c) * d

Two major styles of intermediate representation exist: 1) syntax trees 2) three-address codes t 1 = b c t 2 = a * t 1 t 3 = a + t 2 t 4 = t 1 * d t 5 = t 3 + t 4 Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) a + a * (b c) + (b - c) * d

Reminder: This is the compiler front-end The front-end is languagedependent Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Code optimizer: Make transformations to the program so that it executes faster, but behaves identically to the original version. Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Exercise Together with your pair, answer the questions: 1) What does the C source code do? 2) What does the unoptimized assembly code contain? 3) What does the optimized assembly do? Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007) Description of puts(): int puts ( const char * str ); Writes the C string pointed by str to the standard output (stdout) and appends a newline character ('\n').

Code generator: Produces assembly instructions or machine code for a specific processor out of the intermediate representation. Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

Machine dependent code optimizer: Optimizes the assembly/machine code for a specific platform. For example, instruction scheduling. Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

language-dependent front-end code optimizer processor dependent back-end Figure source: Aho, Lam, Sethi, Ullman Compilers principles, techniques and tools (2007)

39 Loop scheduling Software pipelining: reorganize a loop so that parts of different loop iterations run in parallel Need prolog and epilog around the loop to set up

Practical compiler-related issues

Practical compiler-related issues Key question: how to make the program run more efficiently on the processor? Efficiency means Avoiding behavior that is not needed (e.g. Memory accesses) Improving the utilization of processor resources (less empty instructions) As a consequence the execution time improves and power consumption reduces The software-related methods how to do this depend somewhat on the processor and on the programming language that is used

Practical compiler-related issues For TTA processors the following issues slow down the program: 1. Global data 2. Use of pointers in some cases (int *p) 3. Data size changes (8-bit integer, 16-bit integer, etc) 4. Conditionals (if-then-else, switch)

Practical compiler-related issues 1. Global data In the C language, it is preferable that variables and arrays are defined inside functions, which means that they are local int main() { int x;... } However, sometimes, by accident or for some important reason, variables are defined outside functions, making them global. Reading and writing global variables is slow. int x; int main() {... } The reason is global variable is likely to be assigned in Memory rather than a register file

Practical compiler-related issues 2. Pointers In the C language, pointers are problematic because they can point to any place in the memory Because of this general problem, the C compiler cannot much optimize the code around a pointer. As a consequence, code containing pointer may run slow and/or use the data memory

Practical compiler-related issues 2. Pointers These cases can make pointers problematic for the compiler: Pointers as function parameters int filter (int *x, int *y) { } Pointer arithmetic int array[3] *(array + i) = value;

Practical compiler-related issues 2. Pointers How to avoid performance loss caused by pointers: Using the restrict keyword int filter (int * restrict x, int * restrict y) { } Index arrays by [] int array[3] array[i] = value;

Practical compiler-related issues 3. Data size changes Data size changes force the compiler to insert extra operations to the program code short val1; int val2; val2 = val1; A sign extension (sxhw) is inserted Or: unsigned int data; _TCE_FIFO_U8_STREAM_IN(0, data, status); An and-operation is inserted

Practical compiler-related issues 4. Conditionals The C compiler in the TTA toolset is very advanced and can most usually transform small if-statements to logical computations Still, in some cases the removal of if-statements must be done manually

Mini Assignment Take the filter.c program from Exercise 1 (\float folder). Compile using gcc compiler with optimization levels of 0 to 3. Use S to instruct the compiler to generate assembly code. Report obsereved changes in generated asm code. Example: gcc filter.c o filterlevel_1.asm O1 S Of course the asm code will be for X86 machine.