B1010 Advanced Math Stuff ENGR xD52 Eric VanWyk Fall 2012.

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

Recursion in MIPS Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Leaf and Non-Leaf Procedures A leaf procedure is one that.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Solution 2nd Exam.
10/6: Lecture Topics Procedure call Calling conventions The stack
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Assembly Code Example Selection Sort.
The University of Adelaide, School of Computer Science
Computer Architecture CSCE 350
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
.text fact: addiu $sp, $sp, -32 sw $ra, 20($sp) sw $fp, 16($sp) addiu $fp, $sp, 28 sw $a0, 0($fp) bgtz $a0, L2 li $v0, 1 b suffix L2: addi $a0, $a0,
Procedure call frame: Hold values passed to a procedure as arguments
Solution to Problem Recitation #1 (Week 2) ECEN350 Prof. Choi.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS Assembly Language
20/06/2015CSE1303 Part B lecture notes 1 Functions, part 2 Lecture B15 Lecture notes, section B15.
Intro to Computer Architecture
CSCE 212 Quiz 2 – 2/2/11 1.What is the purpose of the jal instruction? 2.What are the two conditional branching (if, goto; not the slt instruction) instructions.
Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )
MIPS R3000 Subroutine Calls and Stack Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Higher Level languages have adopted a standard Referred to as C-style calling Uses the stack.
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
Procedures 2a MIPS code examples Making Use of a Stack.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
MIPS Subroutines Subroutine Call – jal subname Saves RA in $31 and jumps to subroutine entry label subname Subroutine Return – jr $31 Loads PC with return.
Pushing the Return Address To return to the caller a subroutine must have the correct return address in $ra when the jr instruction is performed. But this.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
B1101 Call of Duty ENGR xD52 Eric VanWyk Fall 2013.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Computer Architecture & Operations I
Function Calls in MIPS To call a function: jal func
CSCI206 - Computer Organization & Programming
MIPS Assembly Language Programming
Function Calls in MIPS To call a function: jal func
CSCI206 - Computer Organization & Programming
MIPS Procedures.
Procedures (Functions)
ENGR xD52 Eric VanWyk Fall 2014
CSCI206 - Computer Organization & Programming
CSCI206 - Computer Organization & Programming
What's wrong with this procedure?
CSCI206 - Computer Organization & Programming
MIPS Procedures.
Addressing in Jumps jump j Label go to Label op address 2 address
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
MIPS Functions.
MIPS Functions.
MIPS functions.
MIPS Procedures.
MIPS Functions.
Systems Architecture I
MIPS function continued
MIPS Functions.
MIPS function continued
MIPS Functions.
MIPS R3000 Subroutine Calls and Stack
Presentation transcript:

b1010 Advanced Math Stuff ENGR xD52 Eric VanWyk Fall 2012

Acknowledgements Ray Andraka: A survey of CORDIC algorithms for FPGA based computers Lumilogic Jack E. Volder, The CORDIC Trigonometric Computing Technique

Today Review Recursive Function Calls Homework 3 CORDIC: Sines, Cosines, Logarithms, Oh My

Factorial Function int Fact(int n){ if(n>1) return n* Fact(n-1) else return 1

Factorial Function int Fact(int n){ if(n>1) goto end: return n* Fact(n-1) end: return 1

Factorial Function $v0 Fact(int n){ if(n>1) goto end: $v0 =n* Fact(n-1) jr $ra end: $v0 = 1 jr $ra

Factorial Function $v0 Fact ($a0) ble $a0, 1, end: Fact(n-1) $v0 =n* Fact(n-1) jr $ra end: $v0 = 1 jr $ra We have most of what we need: – Goto flow control for if – jr $ra for return – Registers assigned Now we need to call Fact – What do we save? – What order? Lets focus on the call site

Factorial Function Call Site To Call Fact: – Push registers I need to save $ra $a0 – Setup Arguments N-1: $a0 = $a0-1 – Jump and Link Fact: – Restore registers

Factorial Function Call Site sub $sp, $sp, 8 sw $ra, 4($sp) sw $a0, 0($sp) sub $a0, $a0, 1 jal fact lw $ra, 4($sp) lw $a0, 0($sp) add $sp, $sp, 8 To Call Fact: – Push $ra, $a0 – Setup $a0 – Jump and Link Fact: – Restore $ra, $a0

Factorial Function Call Site sub $sp, $sp, 8 sw $ra, 4($sp) sw $a0, 0($sp) sub $a0, $a0, 1 jal fact lw $ra, 4($sp) lw $a0, 0($sp) add $sp, $sp, 8 To Call Fact: – Push $ra, $a0 – Setup $a0 – Jump and Link Fact: – Restore $ra, $a0

Factorial Function Call Site sub $sp, $sp, 8 sw $ra, 4($sp) sw $a0, 0($sp) sub $a0, $a0, 1 jal fact lw $ra, 4($sp) lw $a0, 0($sp) add $sp, $sp, 8 To Call Fact: – Push $ra, $a0 – Setup $a0 – Jump and Link Fact: – Restore $ra, $a0

Factorial Function Call Site sub $sp, $sp, 8 sw $ra, 4($sp) sw $a0, 0($sp) sub $a0, $a0, 1 jal fact lw $ra, 4($sp) lw $a0, 0($sp) add $sp, $sp, 8 To Call Fact: – Push $ra, $a0 – Setup $a0 – Jump and Link Fact: – Restore $ra, $a0

Factorial Function fact: ;if(N<=1) return 1 ble $a0, 1, end: ;Push $ra, $a0 sub $sp, $sp, 8 sw $ra, 4($sp) sw $a0, 0($sp) ;Argument N-1 sub $a0, $a0, 1 jal fact ;Pop $ra, $a0 lw $ra, 4($sp) lw $a0, 0($sp) add $sp, $sp, 8 ;Return N*Fact(N-1) mul $v0, $v0, $a0 jr $ra end: ;Return 1 $v0 = 1 jr $ra

Calling Function li $a0, 4 jal factorial move $s0, $v0 li $a0, 2 jal factorial move $s1, $v0 li $a0, 7 jal factorial move $s2, $v0 li $v0, 10 syscall Calls Factorial several times Stores results in $sN li is a pseudoinstruction – What does it assemble to?? The final two lines call a special simulator function to end execution – 10 means exit – Look up other syscalls in help

Key Gotchas jal calls a subroutine jr $ra returns from it Sandwich jal with push and pop pair – Caller responsible for stack (CDECL) There are other options, but be consistent!

Practice You have 40 minutes. Do any of the following: Get recursive factorial working and step trace it Pretend mul&mult don’t exist – Write a leaf function that does their job with add&shift in a loop. Write IQ Multiply: IQmult(a, b, Q) – Multiply two IQN numbers IQ24 means I8Q24 – Hint: MULT $t0, $t1 stores the results in $HI$LO Retrieve using mfhi and mflo

Calculating Interesting Functions So far we have: – Add, Subtract, And, Or, Shift, Multiply, Divide(ish) I’ve promised that this can do EVERYTHING – Square Root, Transcendentals, Trig, Hyperbolics… How?

Calculating Interesting Functions GIANT LUTs – Because we have silicon area to burn – Area doubles per bit of accuracy Power Series and LUTs: – Approximation by polynomial – More efficient in space, but still improves slowly Lets find better ways – That gain accuracy faster

CORDIC Multiplies are expensive in hardware – So many adders! Jack Volder invented CORDIC in 1959 – Trig functions using only shifts, adds, LUTs – We’ll be looking at this half John Stephen Welther generalized it at HP – Hyperbolics, exponentials, logs, etc – This half is awesome too

CORDIC? CORDIC COordinate Rotation DIgital Computer – A simple way to rotate a vector quickly Creates rotation matrices based on 2^i – Makes the math redonkulously quick

Super Glossy Transformation Step

The Clever Bit

The Result

Example: Finding the Phase

Find Phase of -1+3j Rotate into a start Quadrant – This is not yet CORDIC

Example: Finding the Phase I=0 Iteration 0 Y is positive – Rotate “Down”

Example: Finding the Phase I=1 Iteration 1 Y is negative – Rotate “Up”

Example: Finding the Phase I=2

Example: Finding the Magnitude

Am I lucky or what?!

The Point? Area increases linearly per bit of accuracy Cheap Hardware Very reusable

With Remaining Time Play with CORDIC – What other functions can it calculate? Continue with practice from before Start HW3