Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department."— Presentation transcript:

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

2 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.

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

4 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

5 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

6 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

7 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)

8 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

9 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

10 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

11 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

12 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

13 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

14 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)

15 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 – – –

16 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

17 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:

18 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)


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

Similar presentations


Ads by Google