CSECE 365 Computer Architecture - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

CSECE 365 Computer Architecture

Description:

A,B, P registers should be p bit wide. multiply the significand, obtain 2p bits (P,A) registers ... with p bits of precision and return a p bit result. Example ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 28
Provided by: ESO17
Category:

less

Transcript and Presenter's Notes

Title: CSECE 365 Computer Architecture


1
CS/ECE 365 Computer Architecture
  • Soundararajan Ezekiel
  • Department of Computer Science
  • Ohio Northern University

2
Floating Point
  • many applications requires non integer numbers
  • one non-integer type is called floating point
  • two parts -- exponent --- significand
  • 1.52(-3) 0.1875 exponent -3, significand1.5
  • IEEE standard

3
IEEE standard
  • when rounding a halfwayresult to the nearest
    floating point number it picks the one that is
    even 6.10.53.05 ( if this need it to be rounded
    2 digits 3.0 not 3.1)
  • It includes the special values NaN(Not a Number),
    ? and -?
  • divide by zero (will give ? )or square root of
    negative number(NaN)

4
Continue
  • It uses denormal number that represent less than
    1.02(Emin)
  • xy ltgtx-y 0
  • x1.25610Emin, y1.23410Emin
  • x-y0.2210Emin which flushes to 0
  • even though x not equal to y, x-y0
  • It rounds to nearest by default, but it also has
    three other rounding modes
  • It has sophisticated facilities for handling
    exceptions

5
representation of floating point
  • single precision stored in 32 bitgt1 for sign, 8
    for exponent, 23 for fraction
  • Ex 1 10000001 010.0
  • exponent is 129 making the value 129-1272
  • (-1)S(1significand)2(exponent-Bias)
  • (-1)(10.25)22-5 ( significand
    12(-2)1/40.25)
  • left to right (significand bit)s1,s2,s3, gt
    s12(-1)s22(-2)
  • significand 1/4gt0.25

6
floating point multiplication
  • xs2s
  • (s12(e1))(s12(e1))(s1s2)(2(e1e2))
  • 1 10000010 00000 -123
  • 0 10000011 000000 124
  • When unpacked, the significance are both 1.0
    their product is 1.0 so the result is is of the
    form 1 ?????? 000000
  • To compute the exponent use this formula

7
conti
  • biased exp(e1e2)biased exp(e1)biased
    exp(e2)-bias
  • exp bias 127 01111111 so in 2s complement
    -12710000001
  • 10000010
  • 10000011
  • 10000001
  • -------------
  • 10000110 since this is 134 , 134-1277 as exponent

8
rounding
  • the interest part of floating point is rounding
  • example
  • 1.236.788.3394 8.34
  • 2.834.4712.65011.27101
  • 1.287.8109.99681.00101
  • round digit gt 5 add 1 as in first case
  • in last case when adding one there may be
    carry-out

9
continue
  • if the round digit is exactly 5 as in second case
    then additional bit must be examined to decide
    between truncation or incrementing
  • in the following algorithm it will recorded in
    sticky bit
  • there is a straight forward method of handling
    rounding using the multiplier together with an
    extra sticky bit
  • p number of pit in significand
  • A,B, P registers should be p bit wide

10
  • multiply the significand, obtain 2p bits (P,A)
    registers
  • during the multiplication the first p-2 times a
    bit is shifted into A or into sticky bit
  • let s represent sticky bit, g the most
    significant bit of A, r the second most
    significant bit of A, there are two cases
  • 1. Higher order bit of P is 0,Shift P left 1 bit,
    shifting in the g bit from A. Shifting the rest
    of A is not necessary
  • 2. Higher order bit 1, set ssVr, and rg, and
    add 1 to the exponent

11
two cases of floating point multiply algorithm
x0,x1,x2, x3,x4,x5
g, r, s, s ,s,s
sticky
x1,x2,x3,x4,x5,g
Case1x00 shift needed
sticky
x0,x1,x2,x3,x4,x5
x01 increment needed
Adjust binary point add 1 to exponent to
components
12
Floating point addition
  • floating point operations take two inputs with p
    bits of precision and return a p bit result
  • Example
  • sum of binary 6-bit number 1.10011 and
    1.100012(-5)
  • 1.10011
  • .0000110001
  • -----------------
  • using 6-bit adder gives

13
  • 1.10011
  • .00001
  • ----------
  • 1.10100
  • the first discard bit is 1
  • this isnt enough to decide whether to round up
  • the rest of the discarded bits 0001
  • so sticky is 1
  • the final sum is 1.10101

14
  • Here is another example
  • 1.11011
  • .0101001
  • ----------
  • A 6 bit adder gives
  • 1.11011
  • .01010
  • ----------
  • 10.00101

15
  • Because the carry out on the left, the round bit
    is isnt first discarded bit rather, it is the
    low order bit of the sum (1)
  • the discard bit is 01
  • because the round and sticky are both 1
  • the final answer is 10.0011

16
  • Here is the subtraction
  • 1.00000
  • -.00000101111
  • ------------------
  • convert negative by 2s complement and add and
    add
  • 100000
  • 1.11111010001
  • ----------------
  • 0.11111

17
Floating point addition algorithm
  • a1 and a2 be two number to be added
  • ei exponent
  • sisignificand
  • there are 8 steps
  • we will go for each step with this example
  • a1-1.0012(-2)
  • a2-1.11120
  • s11.001 e1-2 s21.111 e20

18
step1
  • if e1lte2 swap the operands. This ensures that the
    difference of the exponents satisfies de1-e2gt0
    tentatively set the exponent of the result to e1
  • e1lte2 so swap d2 tentative exp0

19
step 2
  • if the signs of a1 and a2 differs replace s2 by
    its 2s complement
  • here the signs of the both are negative dont
    negate s2

20
step3
  • place s2 in a p-bit register and shift it
    dee1-e2 places to the right.From the bits
    shifted out, set g to be the most significant
    bit, r to the next most sig, and set sticky hit
    the OR of the rest
  • Here shift s2(1.001after swap) right by 2, giving
    s2.010, g0, r1., s0

21
step 4
  • compute a preliminary significand Ss1s2, by
    adding s1 to the p-bit registers containing s2,If
    the signs of a1, a2 are different the most
    significant bit of S is 1, and there was no
    carry-out, the S is negative, Replace S with its
    twos complement. this can only happen when d0
  • 1.111
  • .010
  • -------
  • (1)0.001 S0.001 with a carry out

22
step 5
  • Shift S as follows. If the signs of a1 and a2 are
    the same and there was a carry out in step 4,
    shift S right by one, filling in the high order
    position with 1. Otherwise shift it left until it
    is normalized. When left shifting on the first,
    shift fill in the low-order position with the g
    bit. After that shift,in zeros. Adjust the
    exponent of the result accordingly
  • Carry-out, so shift S right , S1.000, expexp1,
    exp1

23
step 6
  • adjust r and s. if S was shifted right in step 5,
    set rlow-order bit of S before shifting and sg
    OR s. If there was no shift se rg, sr OR s If
    there was a single left shift, dont change r and
    s, If there were two or more left shifts,
    r0,s0,
  • rlow-order bit of sum1, sg v r v s0v1v01(v
    denotes OR)

24
step7
  • Round S by using the follows. if the entry is non
    empty and 1 to the low-order bit of S. If
    rounding causes carry-out, shift S right and
    adjust the exponent. this the signiciand of the
    result
  • r AND strue so round up , SS1, S1.001

25
Table
  • swap compl sign(a1)
    sign(a2)sign(result)
  • yes
    - -
  • yes -
  • no no
    -
  • no no -
    -
  • no yes
    - -
  • no yes -

26
step 8
  • compute the sign of the result. If a1 and a2 have
    the same sign, this is the sign of the result. If
    a1 and a2 have different signs, then the sign of
    the result depends on which of a1, a2 is
    negative,. whether there is swap in step 1 and
    whether S was replaced by its 2s complement ins
    step 4 use the above table
  • both signs are negative so sign of result is
    negative
  • Final answer -S2exp-1.00121

27
Exercise
  • Use the algorithm to compute the sum
    (-1.010)1.100
Write a Comment
User Comments (0)
About PowerShow.com