html5-img
1 / 36

IA32 Floating Point

IA32 Floating Point. History 8086: first computer to implement IEEE FP separate 8087 FPU (floating point unit) 486: merged FPU and Integer Unit onto one chip Summary Hardware to add, multiply, and divide Floating point data registers Various control & status registers

samara
Download Presentation

IA32 Floating Point

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. IA32 Floating Point • History • 8086: first computer to implement IEEE FP • separate 8087 FPU (floating point unit) • 486: merged FPU and Integer Unit onto one chip • Summary • Hardware to add, multiply, and divide • Floating point data registers • Various control & status registers • Floating Point Formats • single precision (C float): 32 bits • double precision (C double): 64 bits • extended precision (C long double): 80 bits Instruction decoder and sequencer Integer Unit FPU Memory

  2. 0 79 78 64 63 s exp frac %st(3) %st(2) %st(1) “Top” %st(0) FPU Data Register Stack • FPU register format (extended precision) • FPU registers • 8 registers • Logically forms shallow stack • Top called %st(0) • When push too many, bottom values disappear stack grows down

  3. Floating Point Registers • ST: Stack top, called ST(0) • ST(1), the register just below the stack top. • ST(2), the register below ST(1) • ST(3), ST(4), ST(5), ST(6) • ST(7) the last register at the bottom of the stack • The FPU stack is virtual since values can be removed not only from the top of the stack ST(0)

  4. Fld memory (real) Fild memory (integer) Flb memory (BCD) Fld1 (none) Fldz (none) Fldpi (none) Fldl2e(none) Fldl2t (none) Fldlg2 (none) Fldln2 (none) Real value pushed into stack Integer value converted to float BCD/float pushed into the stack 1.0 pushed into the stack 0.0 pushed into the stack Pi pushed into the stack Log 2(e) pushed into the stack Log 2(10) pushed into the stack Log 10(2) pushed into the stack Log (2) pushed into the stack Floating Point Load Instructions

  5. Floating Point Instructions • Most floating point instructions operate over the stack top ST(0) and one other operand in another floating point register or in memory. • No floating point instruction can transfer data between an 80x86 register like EAX and a floating point register. • Transfers must be made using memory locations for intermediate storage.

  6. Floating Point Load Examples Consider the following table for the examples fpValue Real4 10.0 intValue Dword 20 bcdValue TBYTE 30

  7. Floating Point Load Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • Fld fpValue

  8. Floating Point Load Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • Fld st(2) • Notice that the value stored in register ST(2) was pushed again to the top of the stack but was not removed from its current position.

  9. Floating Point Load Instructions • Assuming the FPU stack is as shown before, lets analyze the following commands. • Fild intValue • The integer value is converted to a 10 byte floating point value and pushed into the stack.

  10. Floating Point Load Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • Fbld bcdValue • The bcd value is also converted into a 10 byte floating point value.

  11. Floating Point Load Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • Fldz • Finit ; initialize the math processor • Finit is desirable near the beginning of the code since it erases all the FPU registers.

  12. Fst st(num) Fstp st(num) Fst memory(real) Fstp memory(real) Fist memory(integer) Fistp memory(integer) Fbstp memory (BCD) Replaces st(num) by a copy of st, only st num is affected. Replaces st(num) by a copy of st, st is popped from the stack. Copy of ST is stored as a real value in mem. Stack not affected. Copy of st is stores in mem. ST popped from the stack. Copy of ST is converted into integer and sotred in mem. Same but ST popped. Copy of ST converted into BCD and stored in memory, st popped from stack. Floating Point Store Instructions

  13. Floating Point Store Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • The stack is initialized as shown. • intValue Dword ?

  14. Floating Point Store Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • Fist intValue • intValue obtains 0000000A

  15. Floating Point Store Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • Fistp intValue • intValue 000000A

  16. Floating Point Store Examples • Assuming the FPU stack is as shown before, lets analyze the following commands. • The situation is more confusing when the destination is another floating point register. • Fst st(2) • Fstp st(2) • The first command copies the content of the ST into St(2) • The second does the same and then pops ST from the stack. Original state Fst st(2) Fstp st(2)

  17. Exchange Instructions • In addition to the load and store instructions, the floating point unit has the fxch instruction that will exchange the contents of two floating point registers with no needed operand. • Another version of the instruction lets you specify which register you want to change the contents with the stack top.

  18. Exchange Instruction • Instruction • Fxch ; exchanges ST and ST(1) • Fxch st(num) ; exchanges ST and ST(num); • Examples: • Finit; • Fld1; • Fldz; • Fxchg; • What are the contents of ST and ST(1)?

  19. Floating Point Addition Instructions • The floating point unit contains special instructions for addition purposes. • There are versions of theses instructions to add the contents of ST to another register, the contents of another register to ST, a real number from memory or even an integer number. There are no special instructions for BCD numbers. • The instructions that have a “p” at the end remove the stack top from the floating point registers.

  20. Floating Point Addition Instructions • Fadd (none) ;pops both ST and ST(1), adds these values and pushes the sum onto the stack top • Fadd st(num), st ; adds ST(num) and ST; replaces ST(num) by the sum. • Fadd st, st(num) ; adds ST and ST(num), replaces ST by the sum. • Fadd memory(real) ; adds ST and real number from memory, replaces ST by the sum. • Fiadd memory (integer) ; adds ST and integer from memory, replaces ST by the sum. • Faddp st(num), st ; adds ST(num) and ST; replaces ST(num) by the sum and pops ST from the stack.

  21. 50.00 ST 20.00 ST(1) 30.00 ST(2) 40.00 ST(3) ST(4) ST(5) ST(6) ST(7) Floating Point Addition Examples Assume we have the stack: After executing: Fadd st, st(3)

  22. Floating Point Addition Examples • Using the results from the previous example, assume with run the follogin instructions: • FpValue Real4 5.0 • intValue Dword 1 • Fadd fpValue • Fiadd intValue • What is the result of the floating point stack registers?

  23. 50.00 56.00 ST ST 20.00 20.00 ST(1) ST(1) 30.00 30.00 ST(2) ST(2) 40.00 40.00 ST(3) ST(3) ST(4) ST(4) ST(5) ST(5) ST(6) ST(6) ST(7) ST(7) Floating Point Addition Examples Original Stack After instructions

  24. 56.00 20.00 ST ST 86.00 20.00 ST(1) ST(1) 30.00 40.00 ST(2) ST(2) 40.00 ST(3) ST(3) ST(4) ST(4) ST(5) ST(5) ST(6) ST(6) ST(7) ST(7) Floating Point Addition Examples Finally after the instruction: Faddp st(2), st

  25. Floating Point Substraction Instructions • Substraction instructions are very similary to the corresponding addition instructions. We have 12 of them, divided into two different groups. • The first six are equivalent to the addition instructions. • The second six, are the same except that the operands are the opposite, since substraction is not commutative.

  26. Floating Point Substraction Instructions • First 6 Substraction instructions • Fsub (none) ; pops ST and ST(1), calculates ST(1)-ST; and pushes the difference into the stack • Fsub st(num), st ; calculates ST(num)-st, replaces ST(num) by the diff. • Fsub st, st(num) ; calculates ST-ST(num), replaces ST by the diff. • Fsub memory(real) ; calculates ST- real and replaces ST by the diff. • Fsub memory (int) ; calculates ST- int and replaces ST by the diff. • Fsubp st(num), st ; calculates ST(num)-st, replaces st(num) by the diff and pops st from the stack.

  27. Floating Point Substraction Instructions • Substraction instructions “opposite” • Fsubr (none) ; pops ST and ST(1), calculates ST-ST(1), pushes difference onto the stack. • Fsubr st(num), st ; calculates st-st(num), replaces st(num) with the diff. • Fsubr st, st(num) ; calculates st(num)-st, replaces st with the diff. • Fsubr memory(real) ; calculates mem-st, replaces st with the diff. • Fsub rmemory(int) ; calculates mem-st, replaces st with the diff. • Fisubr mem(int) ; calculates mem-st, replaces st with the diff. • Fsubpr st(num), st ; calculates st-st(num), replaces st(num) with the difference and pops st from the stack.

  28. -30.00 15.00 15.0 ST ST ST 25.00 25.00 25.00 ST(1) ST(1) ST(1) 35.00 35.00 35.00 ST(2) ST(2) ST(2) 45.00 45.00 30.00 ST(3) ST(3) ST(3) ST(4) ST(4) ST(4) 55.00 55.00 55.00 ST(5) ST(5) ST(5) ST(6) ST(6) ST(6) ST(7) ST(7) ST(7) Floating Point Substraction Examples Assuming a source stack: After fsub st, st(3) After fsub st(3), st

  29. Floating Point Multiplication and Div • Multiplicating instructions have the same format as addition instructions. • Division instructions have the same format as substraction instructions and also contain the suffix “R” for the reverse operands, in this case the roles of dividend and divisor.

  30. Floating Point Multiplication and Div • Fmul (none) ; pops ST and ST(1), multiplies them and pushes to stack. • Fmul st(num), st ; multiplies ST(num) by ST, replaces ST(num) with the product. • Fmul st, st(num) ; multiplies ST by ST(num), replaces ST with the product. • Fmul memory(real) ; multiplies ST by a real number in memory, replaces ST with the product. • Fimul memory(int) ; multiplies ST and an integer in memory, replaces ST by the product. • Fmulp st(num), st ; multiplies ST(num) and ST, replaces ST(num) bu the product, pops ST from the stack.

  31. Floating Point Multiplication and Div • Fdiv (none) ; pop ST and ST(1), calculates ST(1)/ST pushes quotient onto th estack • Fdiv st(num), st ; calculates ST(num)/ST, replaces ST(num) by quoit. • Fdiv st, st(num) ; calculates ST/ST(num), replaces ST by quot. • Fdiv mem(real) ; calculates ST / mem, replaces ST by quotient. • Fdiv mem (int) ; calculates ST / mem, replaces ST by quotient. • Fdivp st(num), st ; calculates ST(num)/ST , replaces ST(num) by the quotient and pops ST from the stack. • Fdivr (none) ; pops ST and ST(1), caculates ST/ST(1) and pushes quotient onto the stack. • Fdivr st(num), st ; calculates ST/ST(num), replaces ST(num) by quot. • Fdivr st,st(num) ; calculates ST(num)/st, replaces ST by quot. • Fdivr mem(real, int) ; calc, mem/ST, replaces ST by the quotient. • Fdivpr st(num), st ; calc ST/ST(num), rep st(num) and pops st fromst.

  32. Floating Point Extra Instructions • Some other instructions pertaining to the floating point unit are listed below: • Fabs (none) ; st= |st| (absolute value) • Fchs (none) ; st = -st (change sign) • Frndint (none) ; rounds st to an integer value • Fsqrt (none) ; replaces the contents of ST by its square root

  33. Floating Point Compare Instructions • The floating point unit provides a collection of instructions to compare the stack top ST to a second operand. It has a 16 bit status word (control register) which stores the results of this comparisons. • Fcom (none) ; compares ST and ST(1) • Fcom st(num) ; compares ST and ST(num) • Fcom memory(real) ; compares ST and a real in memory • Ficom memory(int); compares ST and an int in memory • Ftst (none) ; compares ST and 0.0 • Fcomp (none) ; compares ST and ST(1), pops stack. • Fcomp st(num) ; compares ST and ST(num), pops stack. • Fcomp memory(real) ; compares ST and a real in memory, pops stack. • Ficomp memory(int); compares ST and an int in memory, pops stack. • Fcompp (none) ; compares ST and ST(1), pops stack twice.

  34. Floating Point Compare Instructions • The comparison instructions assign values to the bits 14, 10 and 8 of the status word, these “condition codes” bits are named C3, C2 and C0 respectively and the flags are set as follows: • If the operands are not comparable (IEEE NAN) all bits are set to 1.

  35. Floating Point Compare Instructions • Status word “conditional codes” cannot be access directly by the conditional jump instructions of the 80x86 processor. Special instructions must be used to copy these values to memory locations and to the AX register, they are as follows: • Fstsw memory word ; copies status register to a memory word. • Fstsw AX ; copies status register to AX. • Fstcw memory word ; copies control word to memory word. • Fldcw memory word ; copies memory word to control word. • Under certain circumstances a cpu might perform more than one FP operation per clock cycle.

  36. 9.00 ST 12.00 ST(1) 23.00 ST(2) 24.00 ST(3) ST(4) 35.00 ST(5) ST(6) ST(7) Floating Point Exercises • Solve the following Exercises: • Fld st(2) • Fld fpValue (value = 10.0) • Fild intValue (int = 1) • Fldpi • Fst st(4) • Fstp st(4) • Fxch st(3) • Fadd • Fadd st(3), st • Fadd st, st(3) • Faddp st(3), st • Fsub fpValue (value = 2.00) • Fisub intValue (int = 1) • fsqrt Given the following stack Fmul st(3), st Fmul st, st(4) Fmul Fdivr Fchs

More Related