Download Floating Point Operations and Hardware in Computer Organization and Programming and more Quizzes Computer Architecture and Organization in PDF only on Docsity!
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
Lecture 8: Floating Point
Dragan Mirkovic
Department of Computer Science
University of Houston
Announcements
- Quiz #5 on Thursday:
- Arrays and strings (Ch. 10 and 17)
- Today we will start talking about the floating
point operations and the associated hardware
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
Introduction
- A FP numbers constitute a discrete subset of the continuum of real numbers.
- A floating point calculations are very important in many applications - Scientific and engineering applications in particular. - Mflop performance measurement unit.
- A logically separate part of the CPU is dedicated to the manipulation of the FP numbers: Floating-Point Unit (FPU) - Old CPUs used to have a separate (optional) chip. - Starting with Pentium FPU is on the same chip as the rest of the hardware
FPU Data
- The FPU manipulates five forms of data:
- Short floating point (32-bit, float in C/C++)
- Long floating point (64-bit, double in C/C++)
- Integer (16-bit, short int in C/C++)
- Long integer (32-bit, int in C/C++)
- BCD (Binary Coded Decimal), a form which is close to an integer in ASCII format and is used for translating floating point numbers to and from ASCII. It is 80 bits long.
- Inside the FPU, all numbers are converted to a sixth form: - Extended floating-point (80-bit)
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
FP Number Representation
- The sign-magnitude representation is used for the whole number: x and –x differ only in the sign bit.
- The sign of the exponent uses a bias which is 1023 for long fp numbers, and the exponent must lie in the range
− 1023 ≤exponent≤ 1024
- Hence, , which fits into 11 bits.
- Since
- The other bounds can be obtained in the similar fashion.
0 ≤ exp ≤ 2047
1023 308
log 2 10 3. 3219 2 2. 225 10
≅ ⇒ −^ ≅ × −
Exponent Representation
Extended 15 16383
Long 11 1023
Short 8 127
Exponent range
Exponent bias
Exponent length
Format
− 1022 ≤exp≤ 1023
− 126 ≤exp≤ 127
− 16382 ≤exp≤ 16383
- The range of the biased exponent is between 1 and 2 l^ – 2, where l is the length of the exponent.
- Exponent values and are reserved for
special encodings
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
Range of FP Numbers
Extended 19
Long 15
Short 7
Decimal Range digits of precision
Format
1_._ 18 × 10 −^38 ≤ x ≤ 3. 4 × 1038
23 × 10 −^308 ≤ x ≤ 1. 79 × 10308
37 × 10 −^4932 ≤ x ≤ 1. 18 × 104932
- Precision does not guarantee the accuracy but it is a necessary condition for it
- Accuracy is always less than or equal to the precision
Examples
00800000 L0 REAL4 1.1754944E-38;Min short fp 7F7FFFFF L1 REAL4 3.4028235E38; Max short fp 0010000000000000 L2 REAL8 2.2250738585072015E-308; Min long fp 7FEFFFFFFFFFFFFF L3 REAL8 1.7976931348623158E+308; Max long fp
- The hexadecimal encoding for minimum and maximum floating point numbers in REAL4 and REAL8 formats
- The hexadecimal encoding for minimum and maximum floating point numbers in extended format
00018000000000000000 L4 REAL10 3.3621031431120935065E-4932; 7FFEFFFFFFFFFFFFFFFF L5 REAL10 1.1897314953572317650E+4932;
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
Denormalizing
- Denormalizing a floating-point binary number reverses the normalizing process.
- Shift the binary point until the exponent is zero.
- If the exponent is positive n , shift the binary point n positions to the right
- If the exponent is negative n , shift the binary point n positions to the left, filling leading zeros if necessary.
- Examples:
1110.1 1.1101 x 2 3 .000101 1.01 x 2 -
1010001. 1.010001 x 2 6
Examples
mov eax, A
- Single-Precision Bit Encodings
- biased exponent range: 1 – 254 (00000001 - 11111110)
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
Declaring FP Numbers
- For short (32-bit) FP numbers use DD or REAL4 declarations
- For long (64-bit) FP numbers use DQ or REAL8 declarations
- For extended (80-bit) floats use DT or REAL10 declarations
- Examples: A DD -1.375; A negative short fp B REAL4 54.0E23; A positive short fp D DD -1234; A negative long int D1 DD -1234.; A negative short fp E DQ -1.375; A negative long fp F DT -1.375; A negative extended fp G REAL10 1.375; A positive extended fp
Hexadecimal encodings
0000 .DATA 0000 BFB00000 A DD -1.375; A negative short fp 0004 688EEFD3 B REAL4 54.0E23; A positive short fp 0008 FFFFFB2E D DD -1234; A negative long int 000C C49A4000 D1 DD -1234.; A negative short fp 0010 BFF6000000000000 E DQ -1.375; A negative long fp 0018 BFFFB000000000000000 F DT -1.375; A neg. extended fp 0022 3FFFB000000000000000 G REAL10 1.375; A pos. extended fp 0040 00800000 L0 REAL4 1.1754944E-38;Min short fp 0044 7F7FFFFF L1 REAL4 3.4028235E38; Max short fp
1 01111111 011 0000 0000 0000 0000 0000
Sign bit = 1
Biased exponent = 127
Significand = 1/4 + 1/8 = 0.
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
Specific Encodings
- Values often encountered in floating-point operations
- Bit positions marked with the letter x can be either 1 or 0.
- QNaN is a quiet NaN, and SNaN is a signalling NaN.
IA-32 FP Architecture
- The original Intel 8086 processor was designed to handle only integer arithmetic.
- Problem for floating-point-intensive applications
- Emulation of floating-point arithmetic through software - Severe performance penalty - Intel sold a separate floating-point coprocessor chip named the 8087, and upgraded it along with each processor generation.
- Starting with the 80486, it was integrated into the main CPU and renamed as the Floating-Point Unit (FPU).
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
FPU Data Registers
- The FPU has eight 80-bit registers arranged in the form of a register stack.
- A 3-bit field named TOP in the FPU status word marks the top of the stack.
- In the example, TOP equals binary 011, identifying R3 as the top of the stack.
- This stack location is also known as ST(0) (or simply ST).
FPU Special Registers
- The FPU has six special- purpose registers - A 10-bit opcode register - A 16-bit control register - A 16-bit status registers - A 16-bit tag word register - A 48-bit last instruction pointer register - A 48-bit last data (operand) pointer register
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
FPU Load Instructions
- FPU Load (Push): fld mem32 or mem64; short or long fp load fld ST(n); load from another stack entry fild mem16 or mem32; int or long load fbld mem80; BCD load
- FPU Load (Push) Constants: fld1 ; load 1 fldz ; load zero fldpi ; load fldl2t ; load log 210 fldl2e ; load log 2 e fldlg2 ; load log 10 2 fldln2 ; load log (^) e 2
FPU Store [and pop] ST
- FPU Store [and pop] Instructions: fst[p] mem32 or mem64; store [and pop] ST fst[p] ST(n); copy [then pop] ST to ST(n) fist[p] mem16 or mem32; store [and pop] ST as int fbstp mem80; store [and pop] ST as BCD ; no non-popping version of fbstp
D. Mirkovic, COSC 2410: Computer Organization and Programming, Spring 2004
The FPU Arithmetic
- There are six basic FPU instruction formats:
The FPU Instructions…
- Operands surrounded by braces {...} are
implied operands and are not explicitly coded.
- ST denotes ST(0)
- The operation may be one of the following:
ADD Add source to destination SUB Subtract source from destination SUBR Subtract destination from source MUL Multiply source by destination DIV Divide destination by source DIVR Divide source by destination