The x87 FPU Lecture 18 Wed, Mar 23, 2005.

Slides:



Advertisements
Similar presentations
Chapter 2: Data Manipulation
Advertisements

Gursharan Singh Tatla Math Co-Processor Nov-10 Gursharan Singh Tatla
Comp Sci Floating Point Arithmetic 1 Ch. 10 Floating Point Unit.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Microprocessors The MIPS Architecture (Floating Point Instruction Set) Mar 26th, 2002.
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)
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:
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.
FLOATING POINT ARITHMETIC. TOPICS Binary representation of floating point Numbers Computer representation of floating point numbers Floating point instructions.
The x87 FPU Lecture 19 Fri, Mar 26, 2004.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
The x86 Instruction Set Lecture 16 Mon, Mar 14, 2005.
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 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.
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.
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.
© 2015 Pearson Education Limited 2015 Quiz in last 15 minutes Midterm 1 is next Sunday Assignment 1 due today at 4pm Assignment 2 will be up today; due.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
Chapter 14: The Arithmetic Coprocessor, MMX, and SIMID Technologies.
Presented by, C.Balasubramaniam, Lect / CSE ESEC
Assembly language.
Overview of Instruction Set Architectures
Computer Organization
The Java Virtual Machine (JVM)
Part of the Assembler Language Programmers Toolbox
Chapter 12 Variables and Operators
CS216: Program and Data Representation
Lecture on Microcomputer
A Closer Look at Instruction Set Architectures
Chapter 6 Floating Point
Arithmetic for Computers
Computer Organization and Assembly Language (COAL)
Chapter 10 The Stack.
MMX Multi Media eXtensions
Chapter 12 Variables and Operators
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture
CS170 Computer Organization and Architecture I
Subject Name: Microprocessors Subject Code:10EC46 Department: Electronics and Communication Date: /21/2018.
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
Processor Organization and Architecture
68000 Architecture, Data Types and Addressing Modes
ECEG-3202 Computer Architecture and Organization
ECEG-3202 Computer Architecture and Organization
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22
Instruction Set Principles
ECE 352 Digital System Fundamentals
Computer Architecture and System Programming Laboratory
CPU Structure CPU must:
CS501 Advanced Computer Architecture
Computer Organization and Assembly Language
Computer Architecture and System Programming Laboratory
Presentation transcript:

The x87 FPU Lecture 18 Wed, Mar 23, 2005

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 5.678 9.876 5.432 100.0 st(4) st(3) st(2) st(1) st(0) 79 Top

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

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

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 operation.

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 wanted to, we could create a special square-root operator, say #. Then the source code a = #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)).