110 likes | 413 Views
Ch. 10 Floating Point Unit. MIPS Floating point arithmetic. Floating point Coprocessor "Coprocessor 1". System bus. l.s. Processor. Memory. Coprocessor 1. Coprocessor architecture. Floating point registers: $f0, …, $f31 Each 32 bits wide Single precision value: one register
E N D
Ch. 10 Floating Point Unit Comp Sci 251 -- Floating Point Arithmetic
MIPS Floating point arithmetic • Floating point Coprocessor • "Coprocessor 1" System bus l.s Processor Memory Coprocessor 1 Comp Sci 251 -- Floating Point Arithmetic
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 Comp Sci 251 -- Floating Point Arithmetic
Floating point MIPS assembly code • Data definitions x: .float 32.568 # single precision y: .double 32.568 # double precision • Load/store instructions l.s $f5, x # load single s.s $f5, x # store single Comp Sci 251 -- Floating Point Arithmetic
Control Unit Floating Point Arithmetic Logical Unit (FALU) Register Register mfc1 or mtc1 FP Register FP Register mov.s or mov.d store: s.s or s.d load: l.s or l.d Main Memory Comp Sci 251 -- Floating Point Arithmetic
Data Bus 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 Comp Sci 251 -- Floating Point Arithmetic
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 Comp Sci 251 -- Floating Point Arithmetic
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| Comp Sci 251 -- Floating Point Arithmetic
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 Comp Sci 251 -- Floating Point Arithmetic
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 Comp Sci 251 -- Floating Point Arithmetic
Exercise • Write MIPS for the following statements float f = 4.99; cout << (int) f << endl; Comp Sci 251 -- Floating Point Arithmetic