The x87 FPU Lecture 19 Fri, Mar 26, 2004.

Slides:



Advertisements
Similar presentations
Chapter 2: Data Manipulation
Advertisements

Set 16 FLOATING POINT ARITHMETIC. TOPICS Binary representation of floating point Numbers Computer representation of floating point numbers Floating point.
Gursharan Singh Tatla Math Co-Processor Nov-10 Gursharan Singh Tatla
Comp Sci Floating Point Arithmetic 1 Ch. 10 Floating Point Unit.
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Computer Organization and Architecture
Computer Organization and Architecture
Instruction Set Architecture & Design
Microprocessors The MIPS Architecture (Floating Point Instruction Set) Mar 26th, 2002.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
4/6/08Prof. Hilfinger CS164 Lecture 291 Code Generation Lecture 29 (based on slides by R. Bodik)
Outline Floating point arithmetic 80x87 Floating Point Unit.
QuadCore Team – DLX ISA David Bild Greg Bok Jake Czyz Brandon Keao.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Assembly Language for x86 Processors 6th Edition
Programming Models CT213 – Computing Systems Organization.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
CS-2710 Dr. Mark L. Hornick 1 Defining and calling procedures (subroutines) in assembly And using the Stack.
Machine Instruction Characteristics
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 10 Department of Computer Science and Software Engineering University of.
Floating Point Arithmetic
Computer Organization CS224 Fall 2012 Lesson 21. FP Example: °F to °C  C code: float f2c (float fahr) { return ((5.0/9.0)*(fahr )); } fahr in $f12,
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
FLOATING POINT ARITHMETIC. TOPICS Binary representation of floating point Numbers Computer representation of floating point numbers Floating point instructions.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
CSC 235 Computer Organization. Computer Organizaton ä Top_Level Structure ä The von-Neumann Machine ä Stack Machine ä Accumulator Machine ä Load/Store.
The x86 Instruction Set Lecture 16 Mon, Mar 14, 2005.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
EEL5708/Bölöni Lec 8.1 9/19/03 September, 2003 Lotzi Bölöni Fall 2003 EEL 5708 High Performance Computer Architecture Lecture 5 Intel 80x86.
Computer Organization Rabie A. Ramadan Lecture 3.
Assembly Language for x86 Processors 7th Edition
COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE Lecture 21 & 22 Processor Organization Register Organization Course Instructor: Engr. Aisha Danish.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Chapter 3 Arithmetic for Computers CprE 381 Computer Organization and Assembly Level Programming, Fall 2012 Revised from original slides provided by MKP.
Real Numbers SignExponentMantissa.
Real Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2006/12/11.
Chapter 2 Data Manipulation © 2007 Pearson Addison-Wesley. All rights reserved.
Instruction Sets: Characteristics and Functions  Software and Hardware interface Machine Instruction Characteristics Types of Operands Types of Operations.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Programming Model CS 333 Sam Houston State University Dr. Tim McGuire.
o History of Floating Point o Defining Floating Point Arithmetic o Floating Point Representation o Floating Point Format o Floating Point Precisions o.
Subword Parallellism Graphics and audio applications can take advantage of performing simultaneous operations on short vectors – Example: 128-bit adder:
ECE291 Computer Engineering II Lecture 11 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Chapter 14: The Arithmetic Coprocessor, MMX, and SIMID Technologies.
Computer Organization
The Java Virtual Machine (JVM)
Part of the Assembler Language Programmers Toolbox
CS216: Program and Data Representation
A Closer Look at Instruction Set Architectures
A Closer Look at Instruction Set Architectures: Expanding Opcodes
Chapter 10 The Stack.
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture
Using the 80x87 Math Chip in Assembly
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
Lecture 30 (based on slides by R. Bodik)
The University of Adelaide, School of Computer Science
Fundamentals of Computer Organisation & Architecture
The x87 FPU Lecture 18 Wed, Mar 23, 2005.
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22
Computer Architecture and System Programming Laboratory
CPU Structure CPU must:
Computer Organization and Assembly Language
Computer Architecture and System Programming Laboratory
Presentation transcript:

The x87 FPU Lecture 19 Fri, Mar 26, 2004

Reading Read Chapter 8: Programming with the x87 Floating-Point Unit of the Intel Developer’s Manual, Vol. 1.

Floating-Point Data Types The x87 Floating Point Unit (FPU) recognizes three floating-point types. float – single precision, 32 bits. double – double precision, 64 bits. long double – double extended precision, 80 bits. We will use the type double in our compiler.

The x87 FPU Architecture The FPU has 8 general purpose 80-bit (double extended-precision) registers. They are labeled st(0), st(1), …, st(7). They are organized as a stack, with st(0) on top. Typically, floating-point operations pop values off the stack and push results onto the stack. Many instructions allow us to access any position in the stack.

The FPU Stack Register st(0) is always on top of the stack. 1.234 79 st(4) 1.234 st(3) 5.678 st(2) 9.876 st(1) 5.432 Top st(0) 100.0

The FPU Stack When we push, it refers to the next register. 1.234 79 st(5) 1.234 st(4) 5.678 st(3) 9.876 Grows Downward st(2) 5.432 st(1) 100.0 Top st(0) 999.9

The FPU Stack When we pop, it refers to the previous register. 1.234 79 st(4) 1.234 st(3) 5.678 st(2) 9.876 Shrinks Upward st(1) 5.432 Top st(0) 100.0

The FPU Status Register The 16-bit status register contains a number of bit fields that are set by floating-point instructions, including a 3-bit field TOP that points to the top of the FPU stack. TOP holds a value from 0 to 7. We will have use later for the bit fields C0, C1, C2, and C3, which are condition codes containing information about the most recent floating-point comparison.

The FPU Control Word The 16-bit control word contains a number of bit fields, including A 2-bit field PC that controls precision. A 2-bit field RC that controls rounding.

The PC field The PC settings The default is double extended-precision. 00 = single precision. 10 = double precision. 11 = double extended-precision. The default is double extended-precision.

The RC Field The RC settings The default is round to nearest. 01 = Round down (towards –). 10 = Round up (towards +). 11 = Round towards zero. The default is round to nearest. Therefore, when we convert a double to an int, the value will be rounded, not truncated.

The x87 Instruction Set We will be interested in three categories of instruction. Data transfer. Basic arithmetic. Comparisons. Other categories are Transcendental instructions (trig, exponential, and logarithmic functions). Loading constants (0, 1, , log2 10, etc.)

The x87 Instruction Set Many FPU instructions come in two versions. The basic instruction: Fxxx. The same instruction, followed by popping the FPU stack: FxxxP.

Data Transfer – Load fld src Examples Push the floating-poing value at src onto the FPU stack. The operand src may be A memory address. An FPU register st(i). Note that it cannot be a (non-FPU) register. Examples fld avg fld (%esp)

Data Transfer – Load fild src Examples Convert the integer at src to double extended-precision and push it onto the FPU stack. The operand src is a memory address. Examples fild count fild (%esp)

Data Transfer – Store fst dst Example Transfer the value at st(0) to dst. The operand dst may be A memory address. An FPU register st(i). Example fst avg The instruction fstp is the same, except that it also pops the value off of the FPU stack.

Data Transfer – Store fist dst Example Transfer the value at st(0) to dst and convert it to an integer. The operand dst is a memory address. Example fist (%esp) The instruction fistp is the same, except that it also pops the value off of the FPU stack.

Arithmetic – Add To add two floating-point numbers, we will use the faddp instruction. faddp will Add st(0) to st(1) and store the result in st(1). st(1)  st(1) + st(0) Pop the FPU stack, thereby removing st(0) and bringing st(1) to the top of the stack (st(0)). There are several other versions of fadd – see the manual.

Arithmetic – Multiply To multiply two floating-point numbers, we will use the fmulp instruction. fmulp will Multiply st(1) by st(0) and store the result in st(1). st(1)  st(1)  st(0) Pop the FPU stack. There are several other versions of fmul – see the manual.

Arithmetic – Subtract To subtract two floating-point numbers, we will use the fsubrp instruction. fsubrp will Subtract st(0) from st(1) and store the result in st(1) st(1)  st(1) – st(0) Pop the FPU stack. There are several other versions of fsub – see the manual.

Arithmetic – Subtract The Intel manual describes fsubp and fsubrp as follows. fsubp st(1)  st(1) – st(0); Pop stack. Machine code DEE9. fsubrp st(1)  st(0) – st(1); Pop stack. Machine code DEE1. However, the gnu assembler will reverse their meanings.

Arithmetic – Divide To divide two floating-point numbers, we will use the fdivrp instruction. fdivrp will Divide st(1) by st(0) and store the result in st(1) st(1)  st(1) / st(0) Pop the FPU stack. There are several other versions of fdiv – see the manual.

Arithmetic – Divide The Intel manual describes fdivp and fdivr as st(1)  st(1) / st(0); Pop stack. Machine code DEF9. fdivrp st(1)  st(0) / st(1); Pop stack. Machine code DEF1. However, the gnu assembler will reverse their meanings.

Arithmetic – Square Root There is a square-root instruction fsqrt. If we want to, we can create a special square-root operator, say #sqrt#. Then the source code a = #sqrt# b; would be interpreted as “assign to a the square root of b.” No function call would be required.

Transcendental Functions The same is true of the following transcendental functions. fsin: st(0)  sin(st(0)). fcos: st(0)  cos(st(0)). fptan: st(0)  1.0, st(1)  tan(st(0)). fpatan: st(0)  arctan(st(1)/st(0)). fsincos: st(0)  cos(st(0)), st(1)  sin(st(0)).