1 / 13

MIPS Floating Point Arithmetic: Registers, Load/Store Instructions, Data Movement

Learn about floating point arithmetic on MIPS, including the use of floating point registers, load/store instructions, and data movement between coprocessors. This tutorial covers chapters 29-32 of the MIPS programming model.

jeffb
Download Presentation

MIPS Floating Point Arithmetic: Registers, Load/Store Instructions, Data Movement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FloataingPoint Arithmetic on MIPS Floating Point Registers Load, store instructions Data movement between coprocessors Load immediate FP Trap handlers FP arithmetic instructions Central Connecticut State University, MIPS Tutorial. Chapters 29-32.

  2. Review: MIPS programming model • MIPS contains: • Integer arithmetic processor • Floating point arithmetic processor • Whole system’s Control Processor • In this model from the textbook we can see several additional groups of MIPS instructions : • Integer Multiplication Division instructions. • Floatingpoint arithmetic instructions. • System Control instructions

  3. FP Registers. 32 or 64 ? • MIPS has 32single precision (32 bit) floating point registers • The registers are named $f0 – $f31 • $f0is not special (it can hold any bit pattern, not just zero). • Single precision floating point load, store, arithmetic, and other instructions work with these registers.

  4. Double Precision Registers. The same ? MIPS also has hardware for double precision (64 bit) floating point operations. For this, it uses pairs of single precisionregisters to hold operands. There are 16 pairs, named $f0, $f2, — $f30. Only the even numbered register is specified in a double precision instruction; the odd numbered register of the pair is included automatically.

  5. Both formats of register usage Double Floating Point Registers FP0 =00000000,00000000 FP16=00000000,00000000 FP2 =00000000,00000000 FP18=00000000,00000000 FP4 =00000000,00000000 FP20=00000000,00000000 FP6 =00000000,00000000 FP22=00000000,00000000 FP8 =00000000,00000000 FP24=00000000,00000000 FP10=00000000,00000000 FP26=00000000,00000000 FP12=00000000,00000000 FP28=00000000,00000000 FP14=00000000,00000000 FP30=00000000,00000000 Single Floating Point Registers FP0 =00000000 FP8 =00000000 FP16=00000000 FP24=00000000 FP1 =00000000 FP9 =00000000 FP17=00000000 FP25=00000000 FP2 =00000000 FP10=00000000 FP18=00000000 FP26=00000000 FP3 =00000000 FP11=00000000 FP19=00000000 FP27=00000000 FP4 =00000000 FP12=00000000 FP20=00000000 FP28=00000000 FP5 =00000000 FP13=00000000 FP21=00000000 FP29=00000000 FP6 =00000000 FP14=00000000 FP22=00000000 FP30=00000000 FP7 =00000000 FP15=00000000 FP23=00000000 FP31=00000000

  6. Single precision load instruction • Whatever 32 bits are located at addrare copied into $fd. • The address addrcan be an ordinary symbolic address, or an indexed address. • If the data makes no sense as a floating point value, that is OK for this instruction. Later on the mistake will be caught when floating point operations are attempted • There is a load delay slot after lwc1 instruction. • the memory address must be full-word aligned • l.s is pseudo instruction • It is translated into 2 basic instructions l.s$f2,a .data a: .float 1.0 [0x00400018] 0x3c011001 lui $1, 4097 [a] [0x0040001c] 0xc4220000 lwc1 $f2, 0($1) [a] [0x10010000] 0x3f800000 This means load the word to the Coprocessor 1 l.s$fd, addr

  7. Single precision store instruction • Whatever 32 bits are in $fd are copied intoaddr. • The address addrcan be an ordinary symbolic address, or an indexed address. • the memory address must be full-word aligned s.s$f1,a .data a: .float 8.32 • s.s is pseudo instruction • It is translated into 2 basic instructions [0x00400018] 0x3c011001 lui $1, 4097 [a] [0x0040001c] 0xe4210000 swc1 $f1, 0($1) [a] This means to store the word from Coprocessor 1 [0x10010000] 0x41051eb8 s.s $fd, addr

  8. Load, Store Example ## swap.asm ## Exchange the values in valA and valB .text .globl main main: l.s $f0,valA # $f0 <-- valA l.s $f1,valB # $f1 <-- valB s.s $f0,valB # $f0 --> valB s.s $f1,valA # $f1 --> valA .data valA: .float 8.32 # 32 bit floating point value valB: .float -0.6234e4 # 32 bit floating point value # small 'e' only

  9. Data Movement Sometimes the floating point registers are used as temporary registers for integer data. For example, rather than storing a temporary value to memory, you can copy it to an unused floating point register. This is OK, as long as you don't try to do math with them. So a complicated calculation with integers can use float registers for intermediate results. And a complicated calculation with floats can use general purposeregisters the same way.

  10. Data Movement instructions

  11. Load Immediate li.s $f1, 1.0 # $f1 = constant 1.0 li.s $f2, 2.0 # $f2 = constant 2.0 li.s $f10, 1.0e-5 # $f10 = 0.00001 lui $1, 16256 ;li.s$f1,1.0 # $f1 = constant 1.0 mtc1$1, $f1 lui $1, 16384 ;li.s$f2,2.0 # $f2 = constant 2.0 mtc1$1, $f2 lui $1, 14119 ;li.s$f10,1.0e-5 # $f10 = 0.00001 ori $1, $1, -14932 mtc1$1, $f10 li.s$fd,val load register $fdwith val (pseudoinstruction) 

  12. Floating Point Trap Handler Services

  13. Single Precision Arithmetic Why we do not need HiLo register in this case? The result is also floating point. So it takes one 32 bit register. The first instruction computes the absolute value (makes a positive value) of the value in register $fs All instructions correspond to one machine instruction. The double precision version of these and many previously discussed instructions has a "d" in place of the "s". So add.s becomes add.d and corresponds to the machine code that adds double precision.

More Related