1 / 19

Floating point numbers Intel FP Processor

Floating point numbers Intel FP Processor. Real numbers and Floating Point. In scientific computing, need real numbers. Approximated in hardware using floating point. Human representation of FP usually decimal: Example 1 (dec): 1.5*10^2 In computers, use binary mantissa and exponent

aflinchum
Télécharger la présentation

Floating point numbers Intel FP Processor

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. Floating point numbers Intel FP Processor

  2. Real numbers and Floating Point In scientific computing, need real numbers. Approximated in hardware using floating point. Human representation of FP usually decimal: Example 1 (dec): 1.5*10^2 In computers, use binary mantissa and exponent Example 1 (bin): 1001011.0(b)*2^(1(b)) FP numbers usually NORMALIZED: Example 1 (bin, norm): 1.0010110 (b)*2^(111(b))

  3. Floating Point Representation Representation as: (-1)^s * m * 2^ e • s is the sign (1 bit) • m is the mantissa (# of bits: format dependent) • e is the exponent (# of bits: format dependent) There exist numerous FP formats, e.g. 32 bits (“float” in C), 64 bits (“double” in C), 80 bits, etc.

  4. Properties of FP Representation Caveat: most real numbers only APPROXIMATED by any FP format, requires care by programmers! Example: float x; for(x = 0; x != 0.1; x+= 0.01) { printf(“x = %g\n”, x); } /* This is actually an “infinite” loop!!! */

  5. x87 Floating-Point Unit (FPU) provides high-performance floating-point processing capabilities • floating-point, integer, and packed BCD integer data types • floating-point processing algorithms • exception handling • IEEE Standard 754 http://home.agh.edu.pl/~amrozek/x87.pdf

  6. x87 FPU represents a separate execution environment, consists of 8 data registers and the following special-purpose registers Value loaded from memory into x87 FPU data register is automatically converted into double extended-precision floating-point format

  7. IEEE 754 standard (80 bits) Memory address x Example: mov dword [n], 9 fild dword [n] fstp tword [x] RAM Sign bit = 0 Exponent = 11 b (+ 16383 dec “bias”) = 100 0000 0000 0010 b Mantissa = 1.001 Sgn | Exponent | Mantissa Bit position float-point number in x87 data registers stack

  8. x87 FPU instructions treat the eight x87 FPU data registers as a register stack The register number of the current top-of-stack register is stored in the TOP (stack TOP) field in the x87 FPU status word. Load operations decrement TOP by one and load a value into the new top-of-stack register, and store operations store the value from the current TOP register in memory and then increment TOP by one

  9. 16-bit x87 FPU status register indicates the current state of the x87 FPU 16-bit tag word indicates the contents of each the 8 registers in the x87 FPU data-register stack (one 2-bit tag per register). Each tag in tag word corresponds to a physical register. TOP pointer is used to associate tags with registers relative to ST(0).

  10. var1: dt 5.6 var2: dt 2.4 var3: dt 3.8 var4: dt 10.3 fldtword [var1] ; st0 = 5.6, TOP=4 fmultword [var2] ; st0=st0*2.4=13.44, TOP=4 fldtword [var3] ; st0=3.8, st1=13.44, TOP=3 fmultword [var4] ; st0=st0*10.3=39.14, st1=13.44, TOP=3 fadd st1 ; st0=st0+st1, st1=13.44, TOP=3 gdb command to see stack data registers: tui reg float

  11. x87 FPU recognizes and operates on the following seven data types: single-precision floating point, double-precision floating point, double extended-precision floating point, signed word integer, signed doubleword integer, signed quadword integer, and packed BCD decimal integers.

  12. FPU INSTRUCTIONS SET x87 FPU instruction set fall into ESC instructions. They have a common opcode format, where the first byte of the opcode is one of the numbers from D8H through DFH. Load constant instructions: push commonly used constants onto st0

  13. Data Transfer Instructions FLD Load Floating Point FILD Load Integer FBLD Load Packed Decimal FST Store Floating Point FIST Store Integer FSTP Store Floating Point and Pop FISTP Store Integer and Pop FBSTP Store Packed Decimal and Pop FXCH Exchange Register Contents FCMOVcc Conditional Move

  14. Basic Arithmetic Instructions Example of reverse instruction: Operands in memory can be in single-precision floating-point, double-precision floating-point, word-integer, or doubleword-integer format. They are converted to double extended-precision floating-point format automatically. The pop versions of instructions offer the option of popping the x87 FPU register stack following the arithmetic operation. These instructions operate on values in the ST(i) and ST(0) registers, store the result in the ST(i) register, and pop the ST(0) register.

  15. Trancendental Instructions FSIN Sine FCOS Cosine FSINCOS Sine and cosine FPTAN Tangent FPATAN Arctangent FYL2X Logarithm FYL2XP1 Logarithm epsilon F2XM1 Exponential FSCALE Scale Operands are always ST(0), and (if needed, as in FPATAN, F2XM1, FSCALE) ST(1). Results are placed in ST(0), and (if needed, as in FSINCOS) ST(1). Angles in trigonometric functions always in radians.

  16. Comparison Instructions FCOM/FCOMP/FCOMPP Compare floating point and set x87 FPU condition code flags. FUCOM/FUCOMP/FUCOMPP Unordered compare floating point and set x87 FPU condition code flags. FICOM/FICOMP Compare integer and set x87FPUcondition code flags. FCOMI/FCOMIP Compare floating point and set EFLAGS status flags. FUCOMI/FUCOMIP Unordered compare floating point and set EFLAGS status flags. FTST Test (compare floating point with 0.0). FXAM Examine.

  17. Control Instructions FINIT/FNINIT instructions initialize the x87 FPU and its internal registers to default values. Stack overflow and underflow exceptions Stack overflow — an instruction attempts to load a non-empty x87 FPU register from memory. A non-empty register is defined as a register containing a zero (tag value of 01), a valid value (tag value of 00), or a special value (tag value of 10). Stack underflow — an instruction references an empty x87 FPU register as a source operand, including attempting to write the contents of an empty register to memory. An empty register has a tag value of 11.

  18. Example: Motion in 2D fsincos ; Compute vectors in y and x fld dword [distance] fmulp ; Multiply by distance to get dy fld dword [y_loc] faddp fstp dword [y_loc] fld dword [distance] fmulp; ; Multiply by distance to get dx fld dword [x_loc] faddp fstp dword [x_loc] fld dword [ninety] ; Add 90.0 ; degrees to heading for next time. fadd dword [head] fstp dword [head] ret global x_loc global y_loc global head global distance global move_example section .data x_loc: dd 1.5 y_loc: dd -2.5 head: dd 45.0 ; Heading in degrees distance: dd 14.1 one_eighty: dd 180.0 ninety: dd 90.0 section .text move_example: finit fld dword [head] fldpi ; Convert heading into radians fmulp ; multiply by pi fld dword [one_eighty] fdivp ; and divide by 180.0

  19. Example: Motion in 2D (cont) #include <stdio.h<extern float x_loc, y_loc, head, a_step, d_step, distance;extern move_example( ); main( ) { inti; printf("x_loc=%g, y_loc=%g, heading=%g, distance=%g\n", x_loc, y_loc, head, distance); for(i=0; i < 4; i++) {move_example( ); printf("x_loc=%g, y_loc=%g, heading=%g, distance=%g\n", x_loc, y_loc, head, distance);}} ---------------------------------------------------------------------------------------------------------------------------------------------- x_loc=1.5, y_loc=-2.5, heading=45, distance=14.1 x_loc=11.4702, y_loc=7.47021, heading=135, distance=14.1 x_loc=21.4404, y_loc=-2.5, heading=225, distance=14.1 x_loc=11.4702, y_loc=-12.4702, heading=315, distance=14.1 x_loc=1.5, y_loc=-2.5, heading=405, distance=14.1

More Related