Coping with Fixed Point

Similar documents
This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Numerical Matrix Analysis

Systems I: Computer Organization and Architecture

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Numbering Systems. InThisAppendix...

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

Floating Point Fused Add-Subtract and Fused Dot-Product Units

CHAPTER 5 Round-off errors

The string of digits in the binary number system represents the quantity

CS321. Introduction to Numerical Methods

FLOATING-POINT ARITHMETIC IN AMD PROCESSORS MICHAEL SCHULTE AMD RESEARCH JUNE 2015

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

DNA Data and Program Representation. Alexandre David

Chapter 7 - Roots, Radicals, and Complex Numbers

CSI 333 Lecture 1 Number Systems

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Lecture 2. Binary and Hexadecimal Numbers

COMPSCI 210. Binary Fractions. Agenda & Reading

Base Conversion written by Cathy Saxton

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

Lecture 11: Number Systems

Number Systems and Radix Conversion

Attention: This material is copyright Chris Hecker. All rights reserved.

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

22S:295 Seminar in Applied Statistics High Performance Computing in Statistics

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Q-Format number representation. Lecture 5 Fixed Point vs Floating Point. How to store Q30 number to 16-bit memory? Q-format notation.

3D GRAPHICS OPTIMIZATIONS FOR ARM ARCHITECTURE

HOMEWORK # 2 SOLUTIO

Precision & Performance: Floating Point and IEEE 754 Compliance for NVIDIA GPUs

Fast Arithmetic Coding (FastAC) Implementations

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Number Representation

Programming languages C

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti

SIMPLIFYING SQUARE ROOTS

Chapter 4 -- Decimals

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Simplification of Radical Expressions

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

Negative Integer Exponents

Binary Numbering Systems

Instruction Set Architecture (ISA)

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

Floating Point Arithmetic Chapter 14

TMS320C67x FastRTS Library Programmer s Reference

A High-Performance 8-Tap FIR Filter Using Logarithmic Number System

The programming language C. sws1 1

3.1. RATIONAL EXPRESSIONS

Zero: If P is a polynomial and if c is a number such that P (c) = 0 then c is a zero of P.

A Programming Language for Processor Based Embedded Systems

Chapter 2. Binary Values and Number Systems

ARM Microprocessor and ARM-Based Microcontrollers

Some Functions Computable with a Fused-mac

Chapter 7D The Java Virtual Machine

Floating-point control in the Intel compiler and libraries or Why doesn t my application always give the expected answer?

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

COWLEY COUNTY COMMUNITY COLLEGE REVIEW GUIDE Compass Algebra Level 2

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-12: ARM

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

PREPARATION FOR MATH TESTING at CityLab Academy

A Static Analyzer for Large Safety-Critical Software. Considered Programs and Semantics. Automatic Program Verification by Abstract Interpretation

Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster

Radicals - Square Roots

0.8 Rational Expressions and Equations

Intel 64 and IA-32 Architectures Software Developer s Manual

Next Generation GPU Architecture Code-named Fermi

Notes on Assembly Language

NEON. Support in Compilation Tools. Development Article. Copyright 2009 ARM Limited. All rights reserved. DHT 0004A (ID081609)

NUMBER SYSTEMS. William Stallings

Exponents and Radicals

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Supplemental Worksheet Problems To Accompany: The Pre-Algebra Tutor: Volume 1 Section 1 Real Numbers

Performance Optimization and Debug Tools for mobile games with PlayCanvas

High-Performance Modular Multiplication on the Cell Processor

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Caml Virtual Machine File & data formats Document version: 1.4

MBA Jump Start Program

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Greatest Common Factor (GCF) Factoring

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

6.087 Lecture 2 January 12, 2010

ARM Architecture. ARM history. Why ARM? ARM Ltd developed by Acorn computers. Computer Organization and Assembly Languages Yung-Yu Chuang

Algebra and Geometry Review (61 topics, no due date)

Fast Logarithms on a Floating-Point Device

Transcription:

Coping with Fixed Point Mik BRY CEO mbry@apoje.com Copyright Khronos Group, 2004 - Page 1

Overview Fixed Point theory and history Floating Point to Fixed Point Maintain accuracy avoid overflows and optimization tricks Effective use of Fixed Point in OpenGL ES Copyright Khronos Group, 2004 - Page 2

Fixed Point theory and history Widely used in software 3D Fixed Form Fast and simple to implement Copyright Khronos Group, 2004 - Page 3

Widely used in software 3D Fixed Point number is represented by a real number in an integer format with an imaginary radix point separating the integer and fractional part. Prior to HW 3D, fixed point was widely used since the beginning of realtime 3D. But in small handheld devices, we need to go back to a constrained world where we have to take care of limited memory, tiny screen. And also on certain targets avoids floating computings. Copyright Khronos Group, 2004 - Page 4

Fixed Form used in OpenGL ES Signed format : s15.16 used in OpenGL ES GLFixed = number*2^16 GLFixed = number<<16 #define FNUM int // Convert from int to fixed number #define INT2FNUM(x) x<<16 // Convert from fixed math to int #define FNUM2INT(x) x>>16 Copyright Khronos Group, 2004 - Page 5

Fast and simple to implement Basic math operations Adding/Sub : same as int opts FNUM a = INT2FNUM(1); FNUM b = INT2FNUM(2); a += b; Multiply/div (avoid it see later) #define FMUL(x,y) (x*y) >>16 #define FDIV(x,y)(x/y)>>16 Comparisons same as int excepting zero compare Copyright Khronos Group, 2004 - Page 6

Floating Point to Fixed Point Floats format : standardized Maths errors support Convert Fixed and Float numbers Copyright Khronos Group, 2004 - Page 7

Floats format Floating format is now the commonly used number format for 3D operations. Instead of always multiply by a fixed exponent as in Fixed Point, It uses Exponent: Float a = mantissa*2^(exponent-127) Copyright Khronos Group, 2004 - Page 8

So : Float = mantissa*2^(exponent-127) Fixed = number*2^16 Copyright Khronos Group, 2004 - Page 9

Representation errors support Floats IEEE Standard has a full range of exception handling Floats support for NaN and infinite Overflow and Underflow are checked Copyright Khronos Group, 2004 - Page 10

Convert Fixed and float numbers In preprocessing and constants vars it is transparent #define FNUM_PI (int)(3.14f*65536) // 2^16=65536 Simple implementation, not fast at all: Float to Fixed: fixednum = (int)(floatnum*65536 Fixed to Float: floatnum = ((float)fixednum)/65536 Without Floating support at all in C compiler it is a little bit more tricky Copyright Khronos Group, 2004 - Page 11

Effective use of Fixed Point in OpenGL ES Why Fixed Points in OpenGL ES CL? ARM chipset : no floating point support Easy to implements in embedded systems But not as perfect as Floating math so 2 OpenGL ES profiles Copyright Khronos Group, 2004 - Page 12

ARM architecture Designed for low power consumption so : No floating point support in mainstream ARM7 ARM9 cores No divide support in ARM7 Small cache memory L1 and no L2 Copyright Khronos Group, 2004 - Page 13

Easy to implements So Fixed Points fit perfectly to ARM cores No needs for DSP or FPU Caution of Divide support And cache memory Copyright Khronos Group, 2004 - Page 14

OpenGL ES support for Fixed Math Common Lite Profile is a strict fixed point implementation GLFixed : a 32 bits integer Clampx : GL Commands mapping using fixed math: x instead of f glclearcolorx(0, 0, 0, 0); OES_Fixed_Point extension Copyright Khronos Group, 2004 - Page 15

Maintain accuracy and overflows and optimization tricks Accuracy and range Overflow underflow Avoiding pitfalls Optimization tricks Copyright Khronos Group, 2004 - Page 16

Accuracy and Range A fixed point number has a limited integer range. It is not possible to represent very large and very small numbers. integer range in GLFixed : -32768 < integer part < 32768 (2^15) Fractionnal accuracy : 0,0000152587890625 // 1/(2^16) A fixed point number has limited accuracy. You must choose small numbers and inputs a normalize data as possible. Copyright Khronos Group, 2004 - Page 17

Overflow underflow Overflow - An "overflow" will occur when the result of a arithmetic operation is too large to fit into the fixed representation of a fixed point number a = 0x7FFF << 16 b = 0x20 << 16 a += b // An overflow Underflow When you used a not enough accurate value for fraction, like in trigo maths But in fixed point no exception handling Using 64 intermediate numbers but speed consuming Copyright Khronos Group, 2004 - Page 18

Optimization tricks Trigonometric operations Using LookupTable best with 1024 bytes size first quadrant and s8:24 for avoiding underflow. Square operations Using logarithm functions LUT are too big for small cache Use other fixed formats range s24:8 for larger numbers and convert to GLFixed: Fixed24_8Num = glfixednum>>8 // You lost some precision but higher integer range If (Fixed24_8Num&0x7F000000!= 0) error // to big number Else glfixednum = Fixed24_8Num<<8 // convert to GLFixed Copyright Khronos Group, 2004 - Page 19

Avoiding pitfalls Overflow Integer Range Also divide errors (try to not use it) Copyright Khronos Group, 2004 - Page 20

Fixed Point in OpenGL ES In all Profile Easy to implements in using same methods as floating ones and using GLFixed Take care of pitfalls and use small numbers Perfect for limited devices with small memory and screen and a simple ARM processor. Copyright Khronos Group, 2004 - Page 21

Questions? Mik BRY mbry@apoje.com Copyright Khronos Group, 2004 - Page 22