Al2ed chapter18

402 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
402
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Al2ed chapter18

  1. 1. Floating-Point Operations Chapter 18 S. Dandamudi
  2. 2. Outline <ul><li>Introduction </li></ul><ul><li>FPU organization </li></ul><ul><ul><li>Data registers </li></ul></ul><ul><ul><li>Control and status registers </li></ul></ul><ul><ul><li>Tag register </li></ul></ul><ul><li>Floating-point instructions </li></ul><ul><ul><li>Data movement </li></ul></ul><ul><ul><li>Addition/Subtraction </li></ul></ul><ul><ul><li>Multiplication/Division </li></ul></ul><ul><ul><li>Comparison </li></ul></ul><ul><ul><li>Miscellaneous </li></ul></ul><ul><li>Illustrative examples </li></ul>
  3. 3. Introduction <ul><li>Three components </li></ul><ul><ul><li>Sign </li></ul></ul><ul><ul><ul><li>Identified the number </li></ul></ul></ul><ul><ul><ul><ul><li>positive or negative </li></ul></ul></ul></ul><ul><ul><li>Mantissa </li></ul></ul><ul><ul><li>Exponent </li></ul></ul><ul><li>Follows IEEE 754 standard </li></ul><ul><li>More details in Appendix A </li></ul>
  4. 4. FPU Organization <ul><li>FPU consists of </li></ul><ul><ul><li>Data registers </li></ul></ul><ul><ul><ul><li>8 registers ST0, ST1, …, ST7 </li></ul></ul></ul><ul><ul><ul><li>Organized as a register stack </li></ul></ul></ul><ul><ul><ul><li>Names are not statically assigned </li></ul></ul></ul><ul><ul><li>Control and status registers </li></ul></ul><ul><ul><li>Pointer registers </li></ul></ul><ul><ul><ul><li>Instruction and data pointer registers </li></ul></ul></ul><ul><ul><ul><li>Provides support for programmed exception handlers </li></ul></ul></ul><ul><ul><ul><li>Not discussed </li></ul></ul></ul>
  5. 5. FPU Organization (cont’d) FPU Registers
  6. 6. FPU Organization (cont’d) FPU Control Register
  7. 7. FPU Organization (cont’d) FPU Status Register
  8. 8. FPU Organization (cont’d) <ul><li>FPU Tag Register </li></ul><ul><ul><li>Two bits for each register </li></ul></ul><ul><ul><li>Gives the following information </li></ul></ul><ul><ul><ul><li>00 valid </li></ul></ul></ul><ul><ul><ul><li>01 zero </li></ul></ul></ul><ul><ul><ul><li>10 special (invalid, infinity, or denormal) </li></ul></ul></ul><ul><ul><ul><li>11 empty </li></ul></ul></ul>
  9. 9. Floating-Point Instructions <ul><li>Several floating-point instructions for </li></ul><ul><ul><li>Data movement </li></ul></ul><ul><ul><li>Addition/Subtraction </li></ul></ul><ul><ul><li>Multiplication/Division </li></ul></ul><ul><ul><li>Comparison </li></ul></ul><ul><ul><li>Miscellaneous </li></ul></ul><ul><li>These instructions, by default, affect the flags as follows: </li></ul><ul><ul><li>Flag bits C0, C2, and C3 are undefined </li></ul></ul><ul><ul><li>C1 is updated to indicate overflow/underflow condition </li></ul></ul>
  10. 10. Floating-Point Instructions (cont’d) <ul><li>Data movement </li></ul><ul><ul><li>Two types </li></ul></ul><ul><ul><ul><li>Load and store </li></ul></ul></ul><ul><ul><li>Load instructions </li></ul></ul><ul><ul><ul><li>fld src </li></ul></ul></ul><ul><ul><ul><ul><li>Pushes src onto the FPU stack </li></ul></ul></ul></ul><ul><ul><ul><ul><li>src operand can be in a register or in memory </li></ul></ul></ul></ul><ul><ul><ul><ul><li>It can be a single-precision (32 bits), double-precision (64 bits) or extended (80-bit) floating-point number </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Single- and double-precision numbers are converted to extended format </li></ul></ul></ul></ul></ul>
  11. 11. Floating-Point Instructions (cont’d) <ul><li>FP Instructions to push constants </li></ul><ul><ul><li>Instruction Description </li></ul></ul><ul><ul><li>fldz Push +0.0 onto the stack </li></ul></ul><ul><ul><li>fld1 Push +1.0 onto the stack </li></ul></ul><ul><ul><li>fldpi Push  onto the stack </li></ul></ul><ul><ul><li>fldl2t Push log 2 10 onto the stack </li></ul></ul><ul><ul><li>fldl2e Push log 2 e onto the stack </li></ul></ul><ul><ul><li>fldlg2 Push log 10 2 onto the stack </li></ul></ul><ul><ul><li>fldln2 Push log e 2 onto the stack </li></ul></ul><ul><ul><li>To load an integer: fild src </li></ul></ul>
  12. 12. Floating-Point Instructions (cont’d) <ul><li>Store instructions </li></ul><ul><ul><ul><li>fst dest </li></ul></ul></ul><ul><ul><li>Stores the top-of-stack value at dest </li></ul></ul><ul><ul><ul><li>Does not pop it off the stack </li></ul></ul></ul><ul><ul><li>To the value use </li></ul></ul><ul><ul><ul><li>fstp dest </li></ul></ul></ul><ul><ul><li>Integer version of the store instruction </li></ul></ul><ul><ul><ul><li>fist dest </li></ul></ul></ul><ul><ul><li>Its pop version is </li></ul></ul><ul><ul><ul><li>fistp dest </li></ul></ul></ul>
  13. 13. Floating-Point Instructions (cont’d) <ul><li>Addition </li></ul><ul><ul><ul><li>fadd src </li></ul></ul></ul><ul><ul><li>adds the number in memory at src to that in ST0 and stores the result in ST0 </li></ul></ul><ul><ul><ul><li>Does not pop the stack </li></ul></ul></ul><ul><ul><li>Two operand version </li></ul></ul><ul><ul><ul><li>fadd dest,src </li></ul></ul></ul><ul><ul><ul><ul><li>Both dest and src must be FPU registers </li></ul></ul></ul></ul><ul><ul><li>Its pop version </li></ul></ul><ul><ul><ul><li>faddp dest,src </li></ul></ul></ul><ul><ul><li>Integer version </li></ul></ul><ul><ul><ul><li>fiadd src </li></ul></ul></ul>
  14. 14. Floating-Point Instructions (cont’d) <ul><li>Subtraction </li></ul><ul><ul><ul><li>fsub src </li></ul></ul></ul><ul><ul><li>Performs ST0 = ST0  src </li></ul></ul><ul><ul><ul><li>Does not pop the stack </li></ul></ul></ul><ul><ul><li>Two operand version </li></ul></ul><ul><ul><ul><li>fsub dest,src </li></ul></ul></ul><ul><ul><ul><ul><li>Both dest and src must be FPU registers </li></ul></ul></ul></ul><ul><ul><li>Its pop version </li></ul></ul><ul><ul><ul><li>fsubp dest,src </li></ul></ul></ul><ul><ul><li>Reverse subtract version </li></ul></ul><ul><ul><ul><li>fsubr src </li></ul></ul></ul><ul><ul><ul><ul><li>Performs ST0 = src – ST0 </li></ul></ul></ul></ul>
  15. 15. Floating-Point Instructions (cont’d) <ul><li>Multiplication </li></ul><ul><ul><ul><li>fmul src </li></ul></ul></ul><ul><ul><li>Performs ST0 = ST0  src </li></ul></ul><ul><ul><ul><li>Does not pop the stack </li></ul></ul></ul><ul><ul><li>Two operand version </li></ul></ul><ul><ul><ul><li>fmul dest,src </li></ul></ul></ul><ul><ul><ul><ul><li>Both dest and src must be FPU registers </li></ul></ul></ul></ul><ul><ul><li>Its pop version </li></ul></ul><ul><ul><ul><li>fmulp dest,src </li></ul></ul></ul><ul><ul><li>Special pop version with no operands </li></ul></ul><ul><ul><ul><li>fmulp Performs ST0 = ST1 * ST0 </li></ul></ul></ul><ul><ul><li>Multiplication by integer </li></ul></ul><ul><ul><ul><li>fimul src </li></ul></ul></ul>
  16. 16. Floating-Point Instructions (cont’d) <ul><li>Division </li></ul><ul><ul><ul><li>fdiv src </li></ul></ul></ul><ul><ul><li>Performs ST0 = ST0 / src </li></ul></ul><ul><ul><ul><li>Does not pop the stack </li></ul></ul></ul><ul><ul><li>Two operand version </li></ul></ul><ul><ul><ul><li>fdiv dest,src Performs dest = dest/src </li></ul></ul></ul><ul><ul><ul><ul><li>Both dest and src must be FPU registers </li></ul></ul></ul></ul><ul><ul><li>Its pop version </li></ul></ul><ul><ul><ul><li>fdivp dest,src </li></ul></ul></ul><ul><ul><li>Reverse division version </li></ul></ul><ul><ul><ul><li>fdivr src Performs ST0 = src / ST0 </li></ul></ul></ul><ul><ul><li>Multiplication by integer </li></ul></ul><ul><ul><ul><li>fidiv src </li></ul></ul></ul>
  17. 17. Floating-Point Instructions (cont’d) <ul><li>Comparison </li></ul><ul><ul><ul><li>fcom src </li></ul></ul></ul><ul><ul><li>Compares the value in ST0 with src and sets the FPU flags C0, C2, and C3 as follows </li></ul></ul><ul><ul><ul><li>Relationship C3 C2 C0 </li></ul></ul></ul><ul><ul><ul><li>ST0 > src 0 0 0 </li></ul></ul></ul><ul><ul><ul><li>ST0 = src 1 0 0 </li></ul></ul></ul><ul><ul><ul><li>ST0 < src 0 0 1 </li></ul></ul></ul><ul><ul><ul><li>Not comparable 1 1 1 </li></ul></ul></ul><ul><ul><li>Double pop version </li></ul></ul><ul><ul><ul><li>fcompp </li></ul></ul></ul><ul><ul><ul><ul><li>Compares ST0 and ST1 and pops these two values from the stack </li></ul></ul></ul></ul>
  18. 18. Floating-Point Instructions (cont’d) <ul><li>Comparison (cont’d) </li></ul><ul><ul><li>Comparison with an integer </li></ul></ul><ul><ul><ul><li>ficom src </li></ul></ul></ul><ul><ul><li>Comparison with zero </li></ul></ul><ul><ul><ul><li>ftst </li></ul></ul></ul><ul><ul><li>To examine number type </li></ul></ul><ul><ul><ul><li>fxam </li></ul></ul></ul><ul><ul><ul><ul><li>Examines the number in ST0 and returns its sign in C1 (0 for positive, 1 for negative) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>C0, C2, and C3 return the following information </li></ul></ul></ul></ul>Type C3 C2 C0 Unsupported 0 0 0 NaN 0 0 1 Normal 0 1 0 Infinity 0 1 1 Zero 1 0 0 Empty 1 0 1 Denormal 1 1 0
  19. 19. Floating-Point Instructions (cont’d) <ul><li>Miscellaneous </li></ul><ul><ul><li>Change the sign </li></ul></ul><ul><ul><ul><li>fchs </li></ul></ul></ul><ul><ul><ul><ul><li>Changes the sign of the number in ST0 </li></ul></ul></ul></ul><ul><ul><li>Loading the control word </li></ul></ul><ul><ul><ul><li>fldcw src </li></ul></ul></ul><ul><ul><li>Storing the control word </li></ul></ul><ul><ul><ul><li>fstcw dest </li></ul></ul></ul><ul><ul><li>Storing the status word </li></ul></ul><ul><ul><ul><li>fstsw dest </li></ul></ul></ul>
  20. 20. Illustrative Examples <ul><li>Example 1 </li></ul><ul><ul><li>Array sum </li></ul></ul><ul><li>Example 2 </li></ul><ul><ul><li>Quadratic equation solution </li></ul></ul><ul><li>Example 3 </li></ul><ul><ul><li>Array sum --- Inline version </li></ul></ul>Last slide

×