Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comp Sci 251 -- Floating Point Arithmetic 1 Ch. 10 Floating Point Unit.

Similar presentations


Presentation on theme: "Comp Sci 251 -- Floating Point Arithmetic 1 Ch. 10 Floating Point Unit."— Presentation transcript:

1 Comp Sci Floating Point Arithmetic 1 Ch. 10 Floating Point Unit

2 Comp Sci Floating Point Arithmetic 2 MIPS Floating point arithmetic Floating point Coprocessor "Coprocessor 1" Processor System bus MemoryCoprocessor 1 l.s

3 Comp Sci Floating Point Arithmetic 3 Coprocessor architecture Floating point registers: $f0, …, $f31 Each 32 bits wide Single precision value: one register Double precision value: – Even/odd pair of registers – Examples: $f0:$f1$f4:$f5$f28:$f29 $f3:$f4

4 Comp Sci Floating Point Arithmetic 4 Floating point MIPS assembly code Data definitions x:.float # single precision y:.double # double precision Load/store instructions l.s $f5, x# load single s.s $f5, x# store single

5 Comp Sci Floating Point Arithmetic 5 Floating Point Arithmetic Logical Unit (FALU) Control Unit Main Memory FP Register Registe r load: l.s or l.d mov.s or mov.d store: s.s or s.d mfc1 or mtc1

6 Comp Sci Floating Point Arithmetic 6 Instructions Condition Code Control unit and clocks Operands Register unit (16 x 64) Exponent part fraction A B result Exponent Unit A B result Add Unit A B result Divide unit A B result Multiply unit Data Bus

7 Comp Sci Floating Point Arithmetic 7 Floating point instructions Register  register copy mov.s $f5, $f23# move single, $f5  $f23 CPU  FPU copy mfc1 $t0, $f5# move from coprocessor1, $t0  $f5 mtc1 $t0, $f5# move to coprocessor1, $t0  $f5

8 Comp Sci Floating Point Arithmetic 8 Floating point instructions Arithmetic (replace s with d for double precision) add.s $f2, $f4, $f6# $f2  $f4 + $f6 sub.s $f2, $f4, $f6# $f2  $f4 - $f6 mul.s $f2, $f4, $f6# $f2  $f4 * $f6 div.s $f2, $f4, $f6# $f2  $f4 / $f6 abs.s $f2, $f4# $f2  |$f4|

9 Comp Sci Floating Point Arithmetic 9 Floating point instructions Comparison: affects coprocessor status flag (replace s with d for double precision) c.eq.s $f0, $f6# flag  $f0 == $f6 c.le.s $f0, $f6# flag  $f0 <= $f6 c.lt.s $f0, $f6# flag  $f0 < $f6 Conditional branches bc1t label# branch if flag == true bc1f label# branch if flag == false

10 Comp Sci Floating Point Arithmetic 10 Floating point instructions Type conversion – between integer ( w ), single ( s ), double ( d ) data types – Examples: # convert to word (int) in $f0 from single in $f2 cvt.w.s $f0, $f2 # convert to single in $f0 from word (int) in $f2 cvt.s.w $f0, $f2

11 Comp Sci Floating Point Arithmetic 11 Exercise Write MIPS for the following statements float f = 4.99; cout << (int) f << endl;


Download ppt "Comp Sci 251 -- Floating Point Arithmetic 1 Ch. 10 Floating Point Unit."

Similar presentations


Ads by Google