Generating “Rectify( )”

Slides:



Advertisements
Similar presentations
6/2/2015 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada 1 Automated Testing Environment Concepts.
Advertisements

Review of Blackfin Syntax Moves and Adds 1) What we already know and have to remember to apply 2) What we need to learn.
More Example Blackfin Code Using the E-UNITTest Framework.
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.
VisualDSP++ and Test Driven Development Prelaboratory assignment information.
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.
Just enough information to program a Blackfin Familiarization assignment for the Analog Devices’ VisualDSP++ Integrated Development Environment.
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.
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);
Mistakes, Errors and Defects. 12/7/2015Mistakes, Errors, Defects, Copyright M. Smith, ECE, University of Calgary, Canada 2 Basic Concepts  You are building.
12/14/2015 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada 1 Automated Testing Environment Concepts.
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.
“Lab. 5” – Updating Lab. 3 to use DMA Test we understand DMA by using some simple memory to memory DMA Make life more interesting, since hardware is involved,
Generating a software loop with memory accesses TigerSHARC assembly syntax.
CS2100 Computer Organisation
Help for Lab. 1 Subroutines calling Subroutines
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.
Arrays, For loop While loop Do while loop
Generating the “Rectify” code (C++ and assembly code)
A Play Core Timer Interrupts
Introduction to Test Driven Development
Automated Testing Environment
The planned and expected
Trying to avoid pipeline delays
Generating a software loop with memory accesses
Understanding the TigerSHARC ALU pipeline
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Lab. 2 – More details – Later tasks
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.
Assembly Language Review
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.
Assembly Language Review
Hints for Post-Lab Quiz 1
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.
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
COMS 361 Computer Organization
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Building a simple loop using Blackfin assembly code
Understanding the TigerSHARC ALU pipeline
Mistakes, Errors and Defects
A first attempt at learning about optimizing the TigerSHARC code
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
Building tests and code for a “software radio”
Presentation transcript:

Generating “Rectify( )” Assembly code examples Part 1 of 3

Concepts Concepts of C++ “stubs” Forcing the test to fail – test of test Generating valid “C++ code” to satisfy the tests Need for “name mangling” for overloaded functions How do you find out the name mangled name so it can be used in assembly code Learning just enough TigerSHARC assembly code to make things “work” 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Software “AM” radio concept RF STAGE Antenna Pickup AUDIO STAGE Low pass Filter + amplifier Low pass Filter Rectifier Mixer Local Oscillator IF STAGE Audio out Most stages handled with high speed software 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Test Driven Development Work with customer to check that the tests properly express what the customer wants done. Iterative process with customer “heavily involved” – “Agile” methodology. CUSTOMER DEVELOPER 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

E-TDD Test. cpp files have four main components E-TDD Test.cpp files have four main components. Many error messages if not present Include Files – cut-and-paste (always the same) TEST_CONNECT (TestFileInfo) TEST(testNAME, testTYPE) NOTE: Tests execute from LAST in file to FIRST. As normally the LAST test is the most recently added test, this is good. You test if new code works and then check (regression test) that you did not break anything LINK_TEST(TestFileInfo, testTYPE) 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Now expand the Customer Tests to do what the customer has requested Problems to be fixed in Assignment 1 Add test for If N <= 0, return NULL otherwise return the start of the output array Tests are working by mistake as We are not resetting the output array to 0 between function calls 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Name mangled names can be seen from linker C++ name as used The name mangled name generated by in C++ code by the C++ compiler in response to function overloading. These are the “assembly code” names 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Next step: Write just enough code to satisfy the linker – C++ stubs 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Write the assembly language stub We lost control of the processors in the debug environment. 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Build the code incrementally to satisfy tests See speed change now we Are executing code – but why failures Note what if N < = 0 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Compiler optimization FLOATS 927  304 -- THREE FOLD Note Special marker Compiler optimization FLOATS 927  304 -- THREE FOLD INTS 960  150 – SIX FOLD Why the difference, and can we do better, and do we want to? Note the failures – what are they 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Fix Tests to only show “FAILURES 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Generate assembly code Do the code in steps, attempting to satisfy one test at a time Learn “the assembler” in steps Get “some idea” of the issues we need to learn about as we go along Just enough knowledge “to get things to work” Worry about full details later 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

What we need to know based on experiences from other processors 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( ) 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Write tests about passing values back from an assembly code routine 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

What we have learned We passed the “very general” test Managed to call and return from an assembly code and did not crash the system We passed some specific tests in the test file “by accident” CJMP – is the “way to return” from an assembly code function to “C++” Instruction format is interesting nop; nop; nop;; ; separate instructions executed together CJMP (ABS);; ;; indicates the end of an “grouped” instruction CJMP must be like RTS – meaning there is a CJMP register (or memory location) storing the address to return to after this COMPARE TO Blackfin P0 = [FP + 4]; Place storing return address UNLINK; JUMP (P0); 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

More detailed look at the code As with 68K and Blackfin needs a .section But name and format different As with 68K need .align statement Is the “4” in bytes (8 bits) or words (32 bits) As with 68K need .global to tell other code that this function exists Single semi-colons Double semi-colons Start function label End function label Used for “profiling code” Label format similar to 68K Needs leading underscore and final colon 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Need to know How do we return “an integer pointer” Need to look at “C++” manual for coding conventions As with 68K, MIPS and Blackfin expect to have Volatile registers – function variate registers, that DON’T need to be conserved when developing a function Non-volatile, preserved registers – function invariate registers, that DO need to be conserved when developing a function 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Return registers There are many, depending on what you need to return Here we need to use J8 Many registers available – need ability to control usage J0 to J31 – registers (integers and pointers) (SISD mode) XR0 to XR31 – registers (integers) (SISD mode) XFR0 to XFR31 – registers (floats) (SISD mode) Did I also mention I0 to I31 – registers (integers and pointers) (SISD mode) YR0 to YR31 , YFR0 to YFR31 (SIMD mode) XYR, YXR and R registers (SIMD mode) And also the MIMD modes And the double registers and the quad registers ……. #define return_pt_J8 J8 // J8 is a VOLATILE, NON-PRESERVED register 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Using J8 for returned int * value Now passing this test “by accident Should be conditionally passing back NULL 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Conditional tests Need to code – returning a NULL or the starting address of the final array int *HalfWaveRectifyRelease(int initial_array[ ], int final_array[ ], int N) if ( N < 1) return_pt = NULL; else /* after some calculations */ return_pt = &final[ 0]; Questions to ask the instruction manual How are parameters passed to us? On the stack (as with 68K) or in registers / stack (as with MIPS and Blackfin)? – answer turns out to be more like MIPS and Blackfin How do you do an IF? How do you do conditional jumps? 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Parameter passing Spaces for first four parameters ARE ALWAYS present on the stack (as with 68K) But the first four parameters are passed in registers (J4, J5, J6 and J7 most of the time) (as with MIPS) The parameters passed in registers are often then stored into the spaces on the stack (like the MIPS) for “safe keeping” when assembly code functions call assembly code functions J4, J5, J6 and J7 are volatile, non-preserved registers 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Coding convention // int *HalfWaveRectifyRelease(int initial_array[ ], // int final_array[ ], int N) #define initial_pt_inpar1 J4 incoming parameters #define final_pt_inpar2 J5 #define N_J6_inpar3 J6 #define return_pt_J8 J8 return value 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Can we pass back the start of the final array Still passing tests by accident and the start of the array needs to be conditional return value 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

What we need to know based on experiences from other processors 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( ) 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Doing an IF (N < 1) JUMP type of instruction 68K version CMP.L #1, D1 ; Performs subtraction (D1 – 1) and sets ; condition code flag BLT ELSE ; Branch if result of (D1 – 1) < 0 ; BLE is a branch if less than ; zero instruction NOT on whether D1 < 1 TigerSHARC version COMP(N_inpar3, 1);; // Perform N < 1 test IF JLT, JUMP ELSE;; // NOTE: Use of comma , and semi-colons ;; Same possible error on BOTH processors 68K -- which test BLE, BLT or BGT should be used? TigerSHARC – which test JLE, JLT or NJLE should be used? 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

ELSE is a TigerSHARC keyword Should have guessed as editor turned in blue ELSE is a KEYWORD Fix that error first 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Why is ELSE a keyword FOUR PART ELSE INSTRUCTION IS LEGAL IF JLT; ELSE, J1 = J2 + J3; // Conditional execution – if true ELSE, XR1 = XR2 + XR3; // Conditional – if true YFR1 = YFR2 + YFR3;; // Unconditional -- always IF JLT; DO, J1 = J2 + J3; // Conditional execution -- if true DO, XR1 = XR2 + XR3; // Conditional -- if true YFR1 = YFR2 + YFR3;; // Unconditional -- always Having this sort of format means that the instruction pipeline is not disrupted by jumps when we do IF statements 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Fix ELSE keyword error GREATER a keyword? Not blue Just change it to something else rather than wasting time 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Label name is not the problem NOTE: This is “C-like” syntax, But it is not “C” Statement must end in ;; Not ; 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Should learn to read – looking at wrong error. Click on error line Missing ;; 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Still not got the correct syntax Because of missing ;; (dual semicolons) Processor thinks we want return_pt = 0; JUMP END_IF; return_pt = INPAR3 ;; Apparently such a complicated instruction IS LEGAL provided the jump is at the start of the multiple issue instruction 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Add dual-semicolons everywhere Worry about “multiple issues” later This dual semi-colon Is so important that you MUST code review for it all the time or else you waste so much time in the Lab. Key in exams / quizzes At last an error I know how to fix  11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Well I thought I understood it !!! Speed issue – JUMPS can’t be too close together. Not normally a problem when “if” is larger 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Add a single instruction of 4 NOPs nop; nop; nop; nop;; Fix the last error as part of Assignment 1 Fix the remaining error in handling the IF THEN ELSE as part of assignment 1 Worry about code efficiency later (refactor) when all code working 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

What we need to know based on experiences from other processors 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( ) 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Assignment 1 – code the following as a software loop – follow 68K approach extern “C” int CalculateSum(void) { int sum = 0; for (int count = 0; count < 6; count++) { sum = sum + count; } return sum; extern “C” – means that this function is “C” compatible rather than “C++”. No overloading (requiring name-mangling) permitted 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada

Reminder – software for-loop becomes “while loop” with initial test extern “C” int CalculateSum(void) { int sum = 0; int count = 0; while (count < 6) { sum = sum + count; count++; } return sum; Do line by line translation 11/15/2018 TigerSHARC assemble code 1, M. Smith, ECE, University of Calgary, Canada