05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.

Slides:



Advertisements
Similar presentations
Chapter 2: Data Manipulation
Advertisements

Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
Comp Sci Floating Point Arithmetic 1 Ch. 10 Floating Point Unit.
Computer Organization CS224 Fall 2012 Lesson 19. Floating-Point Example  What number is represented by the single-precision float …00 
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
CSCE 212 Chapter 3: Arithmetic for Computers Instructor: Jason D. Bakos.
SPIM and MIPS programming
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1.
COMP3221: Microprocessors and Embedded Systems
1 CS61C L9 Fl. Pt. © UC Regents CS61C - Machine Structures Lecture 9 - Floating Point, Part I September 27, 2000 David Patterson
Instruction Set Architecture & Design
Microprocessors The MIPS Architecture (Floating Point Instruction Set) Mar 26th, 2002.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
1 Ó1998 Morgan Kaufmann Publishers Chapter 4 計算機算數.
Memory - Registers Instruction Sets
Computer Hardware What goes on inside?. Deeper.
1 Lecture 10: FP, Performance Metrics Today’s topics:  IEEE 754 representations  FP arithmetic  Evaluating a system Reminder: assignment 4 due in a.
The CPU The Central Presentation Unit Main Memory and Addresses Address bus and Address Space Data Bus Control Bus The Instructions set Mnemonics Opcodes.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Ellen Spertus MCS 111 October 11, 2001 Floating Point Arithmetic.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 5 Unsigned integer and floating point.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /14/2013 Lecture 16: Floating Point Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
Lecture 9: Floating Point
Floating Point Representation for non-integral numbers – Including very small and very large numbers Like scientific notation – –2.34 × –
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
CS 111 – Sept. 15 Chapter 2 – Manipulating data by performing instructions “What is going on in the CPU?” Commitment: –Please read through section 2.3.
A four function ALU A 00 ADD B MUX SUB 11 Result AND OR
CHAPTER 3 Floating Point.
CDA 3101 Fall 2013 Introduction to Computer Organization
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
1 Lecture 10: Floating Point, Digital Design Today’s topics:  FP arithmetic  Intro to Boolean functions.
MIPS mul div, and MIPS floating point instructions.
Rounding Modes 3 Rounding: the process to obtain the best possible floating-point representation for a given real value. ANSI/IEEE standard:
Exceptions and Interrputs CS 321 – Introduction to Computer Architecture and Machine-Level Programming Barry Britt, Systems Analyst II Department of Computer.
Computer Organization Rabie A. Ramadan Lecture 3.
Pseudo instructions. MIPS supports pseudo instructions. We have seen some like – li $t0, 4 which set $t0 to 4. – la $t0, A which puts the address of label.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
10/25/2005Comp 120 Fall October 25 Review for 2 nd Exam on Tuesday 27 October MUL not MULI Ask Questions!
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Morgan Kaufmann Publishers Arithmetic for Computers
Computer Architecture & Operations I
MIPS floating point instructions
Pseudo instructions.
Floating Point Arithmetics
Lecture 10: Floating Point, Digital Design
Register Use Policy Conventions
Assembly Programming using MIPS R3000 CPU
MIPS I/O and Interrupt.
SPIM Syscalls.
Computer Programming Machine and Assembly.
Pseudo instructions.
MIPS History MIPS is a computer family
Programmer’s View of the EAGLE
Review.
ECEG-3202 Computer Architecture and Organization
MIPS History MIPS is a computer family
MIPS Assembly.
ECEG-3202 Computer Architecture and Organization
Introduction to Microprocessor Programming
Assembly Programming using MIPS R3000 CPU
MIPS History MIPS is a computer family
CPU Structure CPU must:
CDA 3101 Spring 2016 Introduction to Computer Organization
Presentation transcript:

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir2 MIPS Floating Point Instructions  Use special registers $f0… $f31. For double precision $f0, $f2,.. $f30 (which are in fact pairs of registers).  The advantage of having separate registers for floating point operations – we have twice as many registers available and  We maintain the same number of bits in the instruction format.  Disadvantage – need more instructions – need special instructions to load words into the floating point registers.

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir3 MIPS Floating Point Instructions R2000 CPU

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir4 MIPS Floating Point Instructions  Floating point registers have special load and store instructions, but still use integer registers to store the base address for the loaded word  load word in coprocessor 1 lwc1 $f1, 100($s2) # $f1=memory[$s2+100]  store word from coprocessor 1 swc1 $f1, 100($s2) # memory[$s2+100]=$f2  there are move instructions to move data between integer and floating point registers  mtc1 $t1, $f5 #moves $t1 into $f5  mfc1.d $t2, $f2 #moves $f2, $f3 into $t2, $t3

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir5 MIPS Floating Point Instructions  The suffix.s or.d in an instruction specifies it is floating point..s if it is single and.d if it is double precision. add.s $f1, $f4, $f5 # $f1=$f4+$f5 sub.s $f2, $f4, $f6 # $f2=$f4-$f6 mul.s $f2, $f4, $f6 # $f2=$f4x$f6 div.s $f2, $f4, $f6 # $f2=$f4/$f6  To load two floating point numbers, subtract them and place the result into memory the code is lwc1 $f4, 100($s2) #loads a 32-bit floating point number into $f4 lwc1 $f6, 200($s2) #loads another 32-bit floating point number into $f6 sub.s $f10, $f4, $f6 #$f10=$f4-$f6 swc1 $f10, 240($s2) #store 32-bit floating point into memory

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir6 MIPS Floating Point Instructions  Flow operations also have floating point variants  Compare less than single and Compare less than double c.lt.s $f2, $f4 #if $f2<$f4 condition=true, otherwise condition bit is false c.lt.d $f2, $f4 #compare in double precision  R-type instruction  Other conditions can also be tested (eq, ne, gt, etc.)  Floating point has branch operations based on the state of the “condition” bit  Branch if FP comparison is true (true==1)  bc1t 25 #jump to address PC if true  Branch if FP comparison is false (true==0) bc1f 100 #jump to address PC if false  I-type instructions

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir7 Basic Addition Algorithm  For addition (or subtraction) there are specific steps that are taken to make sure the proper digits are added:  (1) the decimal (or binary) point has to be aligned  (2) this means that the significand of the smaller number is shifted to the right until the decimal points are aligned.  (3) then the addition of the significand takes place  (4) the result needs to be normalized, which means the decimal point is shifted left and exponent increases.  (5) the result needs to be truncated to available number of digits and round off (add 1 to the last available digit if number to the right is 5 or larger)

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir8 Basic Addition Algorithm  Addition example  add and  first shift to align decimal point  then truncate  then add  after normalization  after rounding

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir9 Arithmetic Unit for FP addition Subtract to determine which is smaller Output the larger exponent Significand of the smaller number Significand of the larger number Add significands Final result Round off significand

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir10 Extra Bits for rounding IEEE 754 allows the use of guard and round bits added to the allowed number of bits to reduce round-off errors How many extra bits? IEEE: As if computed the result exactly and rounded.  Guard Digits: digits to the right of the first P digits of significand to guard against loss of digits – can later be shifted left into first P places during normalization.  Addition: carry-out shifted in  Subtraction: borrow digit and guard  Multiplication: carry and guard, Division requires guard  Sticky bit is set to 1 if there are nonzero bits to the right of the round bit –helps deal with rounding numbers like 2.345

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir11 Extra Bits for rounding Exercise add numbers and with only three allowed significand digits: a) use guard and round digits; b) do not use these two digits a) We extend the numbers with the two digits and align and Then we add the significands After rounding off to three significand digits b) Without guard and round digits or Results differ

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir12 Using the sticky bit in rounding Exercise add numbers and with only three allowed significand digits: a) use guard, round bits and sticky bits; b) use only guard, round bits a) We extend the numbers with the two digits and align and Then we add the significands After rounding off to three significand digits because sticky bit was 1 b) Without sticky bit result is Results differ

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir13 Floating Point Multiplication  Biased exponents are added then one bias is subtracted  x  New exponent is 10-5=5  when using bias 137 (which is ) (is )-127=132  Significands are multiplied ten  Unormalized product is ten 10 5 Normalized is ten Rounded to four digits ten 10 6  Sign is determined by the sign of both operands ten 10 6

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir14 Exercise A single-precision IEEE number is stored at memory address X. Write a sequence of MIPS instructions to multiply the number at X by 2 and store the results back at location X. Accomplish this without using any floating point instructions (Don’t worry about overflow). a) Multiplying by 2 is same as adding 1 to the exponent field … bits $t … bits $s0 after addi tion lw $t0, X($0) addi $s0, $0, 1 sll $s0, $s0, 23 addu $t0, $t0, $s0 sw $t0, X($0)

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir15 Exercise X= two and Y= two represent single-precision IEEE 754 floating point numbers. a)What is x + y ? b)What is x * y ? a) Remember that 18 bits23 bits sign Signed exponent mantissa: sign + magnitude, normalized binary significand SE M Convert * –1.11*2 – – –

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir16 Exercise - continued b) What is x * y ? First we calculate a new exponent – minus bias new exponent Then we multiply × the significands

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir17 Exercise - continued Normalize and round: exponent significand Signs differ, so result is negative:

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir18 Exercise IA-32 uses 82-bit registers, allowing 64-bit significands and 16-bit exponents: -what is the bias in the exponent? -Range of numbers? -How much greater accuracy compared to double precision? a)There are 15 bits available for the exponent size, thus bias is = ; a) range of numbers is 2.0 x 10 –9864 to 2.0 x b) accuracy is 20% better double precision range was 2.0 ten x to 2.0 ten x so range is 32 times larger (9834/308)