A first attempt at learning about optimizing the TigerSHARC code

Slides:



Advertisements
Similar presentations
Lecture 6 Programming the TMS320C6x Family of DSPs.
Advertisements

Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Building a simple loop using Blackfin assembly code M. Smith, Electrical and Computer Engineering, University of Calgary, Canada.
Review of Blackfin Syntax Moves and Adds 1) What we already know and have to remember to apply 2) What we need to learn.
Software and Hardware Circular Buffer Operations First presented in ENCM There are 3 earlier lectures that are useful for midterm review. M. R.
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter.
Understanding the Blackfin ADSP-BF5XX Assembly Code Format
TigerSHARC processor General Overview. 6/28/2015 TigerSHARC processor, M. Smith, ECE, University of Calgary, Canada 2 Concepts tackled Introduction to.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Ultra sound solution Impact of C++ DSP optimization techniques.
Processor Architecture Needed to handle FFT algoarithm M. Smith.
Blackfin Array Handling Part 2 Moving an array between locations int * MoveASM( int foo[ ], int fee[ ], int N);
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter – Part 3 Understanding the memory pipeline issues.
Averaging Filter Comparing performance of C++ and ‘our’ ASM Example of program development on SHARC using C++ and assembly Planned for Tuesday 7 rd October.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM511.
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter – Part 2 Understanding the pipeline.
Generating “Rectify( )” Test driven development approach to TigerSHARC assembly code production Assembly code examples Part 1 of 3.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);
A first attempt at learning about optimizing the TigerSHARC code TigerSHARC assembly syntax.
Building a simple loop using Blackfin assembly code If you can handle the while-loop correctly in assembly code on any processor, then most of the other.
Generating a software loop with memory accesses TigerSHARC assembly syntax.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Software and Hardware Circular Buffer Operations
General Optimization Issues
TigerSHARC processor General Overview.
Generating the “Rectify” code (C++ and assembly code)
Generating “Rectify( )”
A Play Core Timer Interrupts
DMA example Video image manipulation
The planned and expected
Overview of SHARC processor ADSP Program Flow and other stuff
Trying to avoid pipeline delays
Generating a software loop with memory accesses
Understanding the TigerSHARC ALU pipeline
Comparing 68k (CISC) with 21k (Superscalar RISC DSP)
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during.
TigerSHARC processor and evaluation board
VisualDSP++ and Test Driven Development What happened last lecture?
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Understanding the TigerSHARC ALU pipeline
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Using Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
A Play Lab. 2 Task 8 Core Timer Interrupts
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
* M. R. Smith 07/16/96 This presentation will probably involve audience discussion, which will create action items. Use PowerPoint.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during.
Getting serious about “going fast” on the TigerSHARC
General Optimization Issues
Concept of TDD Test Driven Development
Explaining issues with DCremoval( )
General Optimization Issues
Lab. 4 – Part 2 Demonstrating and understanding multi-processor boot
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
DMA example Video image manipulation
Developing a bicycle speed-o-meter
Developing a bicycle speed-o-meter
Developing a bicycle speed-o-meter
Building a simple loop using Blackfin assembly code
Understanding the TigerSHARC ALU pipeline
This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during.
Mistakes, Errors and Defects
Working with the Compute Block
Blackfin Syntax Moves and Adds
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
A first attempt at learning about optimizing the TigerSHARC code
* M. R. Smith 07/16/96 This presentation will probably involve audience discussion, which will create action items. Use PowerPoint.
Presentation transcript:

A first attempt at learning about optimizing the TigerSHARC code TigerSHARC assembly syntax

What we NOW KNOW! Can we return from an assembly language routine without crashing the processor? Return a parameter from assembly language routine (Is it same for ints and floats?) Pass parameters into assembly language Do IF THEN ELSE statements Read and write values to memory Read and write values in a loop Do some mathematics on the values fetched from memory All this stuff is demonstrated by coding HalfWaveRectifyASM( ) 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Not bad for a first effort Faster than compiler in debug mode Need to learn from the compiler on how to speed code 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

How does compiler do it? Use mixed mode to show Warning – out of order instructions displayed 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Many new instructions. Many parallel instruction Many new instructions. Many parallel instruction. Ones inside loop are key How important is stating if jump is predicted or not? BIG 25% 523  435 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Many new instructions. Many parallel instruction Many new instructions. Many parallel instruction. Ones inside loop are key JMP (NP) 523  435 XR1 not J1 435  491 How important is not using J registers when reading from memory XR1 rather than J1 Now need Condition XALT rather than JLT XCOMP rather than COMP 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Many new instructions. Many parallel instruction Many new instructions. Many parallel instruction. Ones inside loop are key JMP (NP) 523  435 XR1 not J1 435  491 and ++ operator 491  435 How important is not using J registers when reading from memory, and using pointers (*pt++) rather than array ( pt[count]) XR1 rather than J1 Now need Condition XALT rather than JLT XCOMP rather than COMP 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Code to this point. Note new instructions using XR2 and R2 Try a little thing. R2 = 0 is a constant – move outside loop Already outside loop Difference, about half the time – expect improve by 12 cycles Got 491  476 = 15 – timing only accurate to around 10 cycles 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

The IF THEN JUMPS in the loop are killing us The IF THEN JUMPS in the loop are killing us. Rewrite C++ code into optimized form Reduce loop size from 6 if > 0 and 7 if < 0 to 4 any way. Loop size 24 – expect improvement of 48 cycles We go from 476 to 250 cycles That’s 225 cycles or roughly 9 cycles each time around the loop The jumps were causing us 9 cycles by disrupting the pipeline Need to get rid of this jump and counter increment. Blackfin has hardware loops Does the TigerSHARC – Duh!! 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Many new instructions. Many parallel instruction Many new instructions. Many parallel instruction. Ones inside loop are key JMP (NP) 523  435 XR1 not J1 491 and ++ operator 435 Remove inner jumps from loop 250 Hardware loop instructions LC0 = loop counter 0 – may only be a few hardware loops possible SHARC ADSP-21061 – allows 6, Blackfin ADSP-BF5XX – allows 2, so need to still understand software loops IF LC0E  If hardware loop expired, IF NLC0E, if not expired – MM!! 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

With hardware loops – 166 cycles! Are we cooking or what! Fine tuning – can we save N cycles (1 each time round loop) by merging instructions 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Merge those two instructions and use our fancy SIGN-BIT trick for float code We are beating the optimized compiler on the float code by a factor of 2 We need 1 cycle to beat the compiler on the optimized int code Find in for Assignment 1 I did 138 cycles 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

My code passes the tests in 138 cycles Extra 11 cycles from outside the loop (not worth the time and effort if the loop was larger, or there were more points to process) Does turning off the Cache make any difference to our code Find out in assignment 1 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Trying to understand what we have done Most TigerSHARC instructions can be made conditional. WHY? Because doing a NOP instruction (if condition not met) is much less disruptive to the instruction pipeline than doing a JUMP (lose of 9 cycles if jump taken – probably more because of code format) 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Trying to understand what we have done Use J registers for address operations, but store values from memory in XR1 and YR1 WHY? Instructions like this [J1] = XR1;; has the potential to be put in parallel with more operations 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Why mostly conditional instructions? TigerSHARC has a very deep pipeline, so that conditional jumps cause a potential large disruption of the pipeline Better to use non-jump instructions which don’t disrupt pipeline, even if instruction is not executed (acts as nop) If (N < 1) return_value = NULL; else return_value = NULL; 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Why mostly conditional instructions? If (N < 1) return_value = NULL; else return_value = value; COMP(N, 1);; IF NJLT, JUMP _ELSE;; J5 = NULL;; JUMP _END_IF;; _ELSE: J5 = value;; If (N < 1) return_value = NULL; else return_value = value; COMP(N, 1);; IF NJLT; DO J5 = NULL;; IF JLT; DO J5 = value;; Concept is there – we need to Check on whether syntax is correct 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Hardware – zero overhead loop. About 4 Hardware – zero overhead loop. About 4 * N cycles better (N is times round the loop) LC0 = N;; Load counter 0 with value N Start_of_loop_LABEL: Loop code here ;; IF NLC0E, JUMP Start_of_loop_LABEL;; NLC0E – Not LC0 expired – essentially Compare LC0 with 2 If less than 2, continue (don’t jump) If 2 or more, then decrement LC0 and jump All sorts of stall issues if not properly aligned –TigerSHARC manual 8-23 CAN’T USE WHEN THERE IS A FUNCTION CALL IN THE LOOP? WHY NOT? – WHAT HAPPENS – NEED TO EXPLORE MORE. Using a software loop when there is a function is okay since calling a function is slow anyway – don’t need efficiency 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Hardware – zero overhead loop. BIG WARNING LC0 = N;; Load counter 0 with value N LC0 uses UNSIGNED ARITHMETIC – MAKE SURE N is not negative, as a negative number has the same bit pattern as a VERY large unsigned number, and the processor will go around the loop for a week We did a check for N <= 0 before entering the hardware loop as another part of our code – so we lucked in – otherise could have big problems. This issue is so important (and time wasting in the laboratories) that will be deducting marks in quizzes and exams 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

What’s this XR1, YR1 and R1 stuff TigerSHARC is designed to do many things at once So you need appropriate syntax to control it 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

What’s this XR1, YR1 and R1 stuff XYR1 = R2 + R3;; does 2 adds XR1 = XR2 + XR3 and YR1 = YR2 + YR3; You can add the X values and not the Y values with this syntax XR1 = R2 + R3;; And NOT with XR1 = XR2 + XR3;; Ugly – but they (ADI) will not change the syntax (DAMY) 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

What’s this XR1, YR1 and R1 stuff XYR1 = [J0 += 0x1];; Does a 32-bit fetch and puts the same value into XR1 and YR1. Same as doing XR1 = [J0 += 0];; AND YR1 = [J0 += 1];; at the same time XYR1 = L[J0 +0x2];; Does a dual 64 bit fetch and is the same as doing XR1 = [J0 += 1];; AND 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

What’s this XR1, YR1 and R1 stuff XYR1 = [J0 += 0x1];; means XR1 = [J0 += 0];; AND YR1 = [J0 += 1];; XYR1 = L[J0 +0x2];; XR1 = [J0 += 1];; AND YR1 = [J0 += 1];; at the same time XR1:0 = L[J0 +0x2];; XR0 = [J0 += 1];; AND XR1 = [J0 += 1];; XYR1:0 = L[J0 +0x2];; XR0 = [J0 += 0];; AND YR0 = [J0 += 1];; AND XR1 = [J0 += 0];; 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

What’s this XR1, YR1 and R1 stuff XYR1:0 = L[J0 +0x2];; means XR0 = [J0 += 0];; AND YR0 = [J0 += 1];; AND XR1 = [J0 += 0];; YR1 = [J0 += 1];; XR3:0 = Q[J0 +0x4];; XR0 = [J0 += 1];; AND XR1 = [J0 += 1];; AND XR2 = [J0 += 1];; AND XR3 = [J0 += 1];; XYR3:0 = Q[J0 +0x4];; XR1 = [J0 += 0];; AND YR1 = [J0 += 1];; AND XR2 = [J0 +=0];; AND YR2 = [J0 += 1];; AND XR3 = [J0 += 0];; AND YR3 = [J0 += 1];; 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Float release – identify new instructions I see 1 new instructions 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Difference between integer and math operations XYR1 = R2 + R3;; does 2 INTEGER adds XR1 = XR2 + XR3 and YR1 = YR2 + YR3; SYNTAX XR1 = R2 + R3;; And NOT with XR1 = XR2 + XR3;; Use F syntax to make it a float operation XYFR1 = R2 + R3;; does 2 FLOATING adds XFR1 = R2 + R3 YFR1 = R2 + R3; 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Exercise 1 – needed for Lab. 1 FIR filter operation -- data and filter-coefficients are both integer arrays – Write in C++ New_value from Audio A/D, output sent to Audio D/A 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Exercise – needed for Lab. 1 FIR filter operation -- data and filter-coefficients are both integer arrays -- ASM 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Insert C++ code – for Lab. 1 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

Insert assembler code version (Lab. 2) 5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada

What we NOW KNOW EVERYTHING FOR THE FINAL (REALLY -- ALMOST)! Can we return from an assembly language routine without crashing the processor? Return a parameter from assembly language routine (Is it same for ints and floats?) Pass parameters into assembly language Do IF THEN ELSE statements Read and write values to memory Read and write values in a loop Do some mathematics on the values fetched from memory All this stuff was demonstrated by coding HalfWaveRectifyASM( ) --  5/11/2019 TigerSHARC assemble code 3, M. Smith, ECE, University of Calgary, Canada