Compiler Exploitation of Decimal Floating-Point Hardware Ian McIntosh, Ivan Sham IBM Toronto Lab.

Slides:



Advertisements
Similar presentations
Zhongkai Chen. Gonzalez-Navarro, S. ; Tsen, C. ; Schulte, M. ; Univ. of Malaga, Malaga This paper appears in: Signals, Systems and Computers, ACSSC.
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1.
Floating Point Numbers
COMP3221: Microprocessors and Embedded Systems Lecture 14: Floating Point Numbers Lecturer: Hui Wu Session 2, 2004.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Microsoft Excel 2007 Bug Mikko Heinonen
1  2004 Morgan Kaufmann Publishers Chapter Three.
Floating-Point and High-Level Languages Programming Languages Spring 2004.
1 Module 2: Floating-Point Representation. 2 Floating Point Numbers ■ Significant x base exponent ■ Example:
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Floating point variables of different lengths. Trade-off: accuracy vs. memory space Recall that the computer can combine adjacent bytes in the RAM memory.
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Information Representation (Level ISA3) Floating point numbers.
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
Computer Science 111 Fundamentals of Programming I Number Systems.
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computing Systems Basic arithmetic for computers.
ECE232: Hardware Organization and Design
College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361:
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
S. Rawat I.I.T. Kanpur. Floating-point representation IEEE numbers are stored using a kind of scientific notation. ± mantissa * 2 exponent We can represent.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /14/2013 Lecture 16: Floating Point Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Computer Science Engineering B.E.(4 th sem) c omputer system organization Topic-Floating and decimal arithmetic S ubmitted to– Prof. Shweta Agrawal Submitted.
9.4 FLOATING-POINT REPRESENTATION
Abdullah Aldahami ( ) March 12, Introduction 2. Background 3. Proposed Multiplier Design a.System Overview b.Fixed Point Multiplier.
CSC 221 Computer Organization and Assembly Language
Floating Point Arithmetic
Floating Point Representation for non-integral numbers – Including very small and very large numbers Like scientific notation – –2.34 × –
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
Floating Point Numbers Representation, Operations, and Accuracy CS223 Digital Design.
CSE 351 Number Representation & Operators Section 2 October 8, 2015.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
IT11004: Data Representation and Organization Floating Point Representation.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
CHAPTER 5: Representing Numerical Data
Floating Point Representations
Lecture 6. Fixed and Floating Point Numbers
Computer Architecture & Operations I
Integer Division.
Chapter 4 – Fundamental Data Types
Topics IEEE Floating Point Standard Rounding Floating Point Operations
Tokens in C Keywords Identifiers Constants
Numbers in a Computer Unsigned integers Signed magnitude
Instructor: David Ferry
CS 232: Computer Architecture II
Floating-Point and High-Level Languages
CHAPTER 4: Representing Integer Data
Chapter 6 Floating Point
Arithmetic for Computers
Data Structures Mohammed Thajeel To the second year students
Data Representation Data Types Complements Fixed Point Representation
EE 445S Real-Time Digital Signal Processing Lab Spring 2014
Computer Arithmetic Multiplication, Floating Point
Lectures on Numerical Methods
Introduction to Microprocessor Programming
CS 105 “Tour of the Black Holes of Computing!”
Computer Organization and Assembly Language
Presentation transcript:

Compiler Exploitation of Decimal Floating-Point Hardware Ian McIntosh, Ivan Sham IBM Toronto Lab

Why do we need Decimal Floating Point? Microsoft® Office Excel 2003

…Why do we need Decimal Floating Point? public static double calculateTotal(double price, double taxRate) { return price * ( taxRate); }... System.out.println("Total: $" + calculateTotal(7.0, 0.015)); Output -> Total: $

Outline IEEE Decimal Floating Point (DFP) C/C++ and DFP Java and DFP

What is IEEE Decimal Floating Point? Type NameSizePrecisionExponent Range decimal32 32 bits 4 bytes 7 digits single -101 to +90 decimal64 64 bits 8 bytes 16 digits double -398 to +369 decimal bits 16 bytes 34 digits quad to +6111

What is Decimal Floating Point? Values use base 10 digits –Alternative to Binary Floating Point Digits continuation Exponent continuation Combination field Sign Sign bit Combination field – encodes the first two bits of the exponent and the leftmost digit (BCD) Exponent continuation – encodes the remaining biased exponent bits Digits continuation – encodes the remaining digits in DPD 3-digit block form -1/

Why should we use DFP? Pervasive –Decimal arithmetic is almost universal outside computers More accurate for decimal numbers – Can represent “important” numbers exactly Programming trend –IEEE 754, IEEE 854, IEEE 754R, IEEE

Why should we use DFP? Easier to convert to/from strings –Great for working with databases Performance –More on this later

Why avoid using DFP? It’s new and different Not all languages include DFP Limited support by other vendors Software implementations can be slow Incompatible formats (DPD and BID) Current IBM hardware is in most cases slower than binary floating point (BFP)

DFP at IBM Hardware –POWER6 and Z10 Microcode in Z9 –One DFP functional unit Non-pipelined Software –XL C, XL C++, gcc, PL/I –IBM® Developer Kit for Java™ 6

C Example – Without DFP double calculateTotal(double price, double taxRate) { return price * ( taxRate); }... printf ("Total: $%19.16f\n", calculateTotal(7.0, 0.015)); Output -> Total: $

C Example – With DFP _Decimal64 calculateTotal(_Decimal64 price, _Decimal64 taxRate) { return price * (1.00dd + taxRate); }... printf ("Total: $%19.16Df\n", calculateTotal(7.0dd, 0.015dd)); Output -> Total: $

C / C++ DFP C / C ++ Type Name C ++ Class Name Literal Suffix C printf / scanf Format Modifier Library Function Suffix _Decimal32 decimal32 dfHDd32 _Decimal64 decimal64 ddDd64 _Decimal128 decimal128 dlDDd128

C / C++ DFP – Approaches C syntaxEasiest and most natural. On AIX can be compiled to either use POWER 6 DFP instructions or call decNumber library. On z/OS uses DFP instructions. DFPAL libraryAutomatically adapts to either using DFP instructions or calling decNumber. decNumber libraryVery portable library. decFloat libraryNewer and often faster library. decNumber++ libraryC ++ DFP class library.

C/C++ DFP Performance – Product and Sum In a loop:a[i] += b[i] * c[i]; noopt-O2-O3 C syntax using decNumber library (Baseline) 1.26x faster than noopt 2x faster than noopt C syntax using DFP instructions 27x faster than software 1.82x faster than noopt 39x faster than software 4.37x faster than noopt 59x faster than software Measured by Tommy Wong, Toronto Lab xlc for AIX version 9 on POWER 6

C/C++ DFP Performance – C telco Benchmark DFPAL* calls using decNumber(Baseline) decNumber calls1.92x faster DFPAL* calls using DFP instructions2.56x faster C syntax using DFP instructions4.4x faster Measured by Tommy Tse, Beaverton xlc for AIX version 9 on POWER 6 using -O2 * DFPAL automatically adapts to either using DFP instructions or calling decNumber.

Decimal Floating Point in Java IBM Developer Kit for Java 6 64 bit DFP via BigDecimal class library POWER 6 server or Z10 mainframe

BigDecimal Class Library arbitrary-precision signed decimal numbers –an arbitrary precision integer unscaled value –32-bit integer scale Supports all basic arithmetic operations Complete control over precision and rounding behavior Unscaled value: Scale: 5

BigDecimal and DFP BigDecimal can represent arbitrary significance but 64-bit DFP restricted to 16 digits BigDecimal represents 32-bit exponent, 64-bit DFP restricted to 10 bits Values that cannot be represented as DFP DFP values that can be represented values Set of all BigDecimal objects

BigDecimal Representation Problem Want to: –Use DFP representation –Avoid software re-try BigDecimal a = new BigDecimal(" ", MathContext.DECIMAL64); BigDecimal b = new BigDecimal(" ", MathContext.DECIMAL64); BigDecimal c = a.add(b); Fits in 64 bit DFP Precision overflow 64

Hysteresis Mechanism Choose best representation automatically –Base on history of operations Use counter and threshold –Bias towards DFP representation Division, string construction, unaligned addition –Bias towards software representation Compare, integer constructions BigDecimal constructors check counter

JIT Compiler Optimization Detects DFP hardware support –Replaces checks in java code with constant –Disables hysteresis mechanism when no DFP Inject DFP instructions –Load operands from BigDecimal Objects –Set rounding mode (if necessary) –Perform DFP operation –Reset rounding mode (if necessary) –Check result validity –Store result into BigDecimal Object

Example – Java / BigDecimal public static BigDecimal calculateTotal( BigDecimal price, BigDecimal taxRate) { return price.multiply(taxRate.add(BigDecimal.ONE)); }... System.out.println("Total: $" + calculateTotal( new BigDecimal(“7.00”), new BigDecimal(“0.015”)); Output -> Total: $7.1050

Microbenchmark results HW DFP Speed up Unaligned Addition 5.05x Aligned Multiplication 3.03x Aligned Division 2.23x Half Even Rounding 1.45x String based construction 2.08x zLinux on Z10 using Java 6 SR2

Performance Improvement - Telco z/OS on Z10 using Java6 SR1

Summary Use DFP –Control over precision and rounding behaviour –Accuracy for decimal numbers –Programming trend High performance for suitable workloads –DFP hardware can greatly improve performance –4x (2x) speedup was measured on C (Java) for Telco

Thank you! IBM Toronto Software Lab Ian McIntosh Ivan Sham

Resources General Decimal Arithematic – Decimal floating-point in Java 6: Best practices – let/ContentHandler/whitepaper/power/java6_sdk/best_pra cticehttps:// let/ContentHandler/whitepaper/power/java6_sdk/best_pra ctice

Java command line options -Xdfpbd –Disables the hysteresis mechanism -Xnodfpbd –Disable DFP support and hysteresis mechanism

Hysteresis Mechanism Performance Multi-threaded transaction base benchmark –Workload does not use MathContext64 zLinux on Z10 using Java 6 SR2

Java Telco Performance on POWER6 AIX on POWER6 using Java 6