Fixed and Floating Point Packages

Similar documents
Floating point package user s guide By David Bishop (dbishop@vhdl.org)

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

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

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

VHDL Test Bench Tutorial

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

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

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

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

Introduction to Xilinx System Generator Part II. Evan Everett and Michael Wu ELEC Spring 2013

CHAPTER 5 Round-off errors

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

LAB #3 VHDL RECOGNITION AND GAL IC PROGRAMMING USING ALL-11 UNIVERSAL PROGRAMMER

The Designer's Guide to VHDL

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

Data Storage 3.1. Foundations of Computer Science Cengage Learning

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

SELECT INPUTS STROBE OUTPUTS

Step : Create Dependency Graph for Data Path Step b: 8-way Addition? So, the data operations are: 8 multiplications one 8-way addition Balanced binary

if-then else : 2-1 mux mux: process (A, B, Select) begin if (select= 1 ) then Z <= A; else Z <= B; end if; end process;

DNA Data and Program Representation. Alexandre David

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

Solution for Homework 2

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

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

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

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

Lecture 2. Binary and Hexadecimal Numbers

VHDL Reference Manual

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

The System Designer's Guide to VHDL-AMS

Numerical Matrix Analysis

Digital Design with Synthesizable VHDL

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

Computer Science 281 Binary and Hexadecimal Review

Quartus II Introduction for VHDL Users

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

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

The Answer to the 14 Most Frequently Asked Modbus Questions

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

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Start Active-HDL by double clicking on the Active-HDL Icon (windows).

VHDL GUIDELINES FOR SYNTHESIS

VHDL programmering H2

Digital Design with VHDL

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

Digital Systems Design. VGA Video Display Generation

Sources: On the Web: Slides will be available on:

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

Monday January 19th 2015 Title: "Transmathematics - a survey of recent results on division by zero" Facilitator: TheNumberNullity / James Anderson, UK

Implementation of Modified Booth Algorithm (Radix 4) and its Comparison with Booth Algorithm (Radix-2)

Java Interview Questions and Answers

12. A B C A B C A B C 1 A B C A B C A B C JK-FF NETr

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

Combinational-Circuit Building Blocks

CPE 462 VHDL: Simulation and Synthesis

Lecture 8: Binary Multiplication & Division

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

Using VHDL Abstract Data Types to Design a High Performance 3-D Graphics Pipeline. Thomas Tessier. Thomas Bishop. Timothy Davis.

Number Representation

DDS. 16-bit Direct Digital Synthesizer / Periodic waveform generator Rev Key Design Features. Block Diagram. Generic Parameters.

Hardware Implementation of the Stone Metamorphic Cipher

Systems I: Computer Organization and Architecture

Object Oriented Software Design

Digital Design and Synthesis INTRODUCTION

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

Using Xilinx ISE for VHDL Based Design

Customizing 16-bit floating point instructions on a NIOS II processor for FPGA image and media processing

Object Oriented Software Design

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

HDL Simulation Framework

An Example VHDL Application for the TM-4

2.2 Scientific Notation: Writing Large and Small Numbers

Numbering Systems. InThisAppendix...

EE361: Digital Computer Organization Course Syllabus

Implementation of Web-Server Using Altera DE2-70 FPGA Development Kit

Pemrograman Dasar. Basic Elements Of Java

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

TMS320C67x FastRTS Library Programmer s Reference

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

VB.NET Programming Fundamentals

THE EXACT DOT PRODUCT AS BASIC TOOL FOR LONG INTERVAL ARITHMETIC

Data Storage: Each time you create a variable in memory, a certain amount of memory is allocated for that variable based on its data type (or class).

Fractions and Linear Equations

What Every Computer Scientist Should Know About Floating-Point Arithmetic

Introduction to Functional Verification. Niels Burkhardt

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects.

HOMEWORK # 2 SOLUTIO

Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java

Coding Guidelines for Datapath Synthesis

The C Programming Language course syllabus associate level

A Programming Language for Processor Based Embedded Systems

Lab 1: Introduction to Xilinx ISE Tutorial

Getting Started Using Mentor Graphic s ModelSim

Instruction Set Architecture (ISA)

Binary Numbering Systems

Transcription:

Fixed and Floating Point Packages By Jim Lewis, VHDL Training David Bishop, Kodak MARLUG - Mid-Atlantic Region Local Users Group ANNUAL CONFERENCE - OCTOBER 12, 2006 Johns Hopkins University Applied Physics Lab Laurel, MD Fixed and Floating Point Packages Fixed Point Package & Types Format Sizing & Overloading Literals in Assignments and Expressions Quirks Floating Point Package & Types Format Sizing & Overloading Literals in Assignments and Expressions These packages are part of Accellera VHDL-2006 3.0 standard 2 Copyright 2006

Fixed Point Package With fixed point, there are parameters that need to be specified. In Accellera VHDL-2006 3.0 they are specified using generics: package ZZZ_fixed_pkg is new ieee.fixed_generic_pkg generic map ( fixed_round_style => IEEE.math_utility_pkg.fixed_round, fixed_overflow_style => IEEE.math_utility_pkg.fixed_saturate, fixed_guard_bits => 3, -- # of guard bits no_warning => false -- show warnings ); In the mean time, there is a temporary package fixed_pkg_c.vhd that uses constants and can be edited to be ZZZ_fixed_pkg. 3 Copyright 2006 Fixed Point Types Library YYY_math_lib ; use YYY_math_lib.ZZZ_fixed_pkg.all ; ufixed = unsigned fixed point type ufixed is array (integer range <>) of std_logic; sfixed = signed fixed point type sfixed is array (integer range <>) of std_logic; 4 Copyright 2006

Fixed Point Format constant A : ufixed(3 downto -3) := "0110100"; 3210-3 IIIIFFF 0110100 = 0110.100 = 6.5 Range is required to be downto Whole number is on the left and includes 0 index (3 downto 0) Fraction is to the right of the 0 index (-1 downto -3) Ok to be only a integer or only a fraction 5 Copyright 2006 Fixed Point is Full Precision Math signal A4_3, B4_3 : ufixed ( 3 downto -3 ) ; signal Y5_3 : ufixed ( 4 downto -3 ) ; Y5_3 <= A4_3 + B4_3 ; Integer portion of the result is one bit bigger than largest argument Note that in numeric_std, addition/subtraction is modulo math 6 Copyright 2006

Fixed Point Sizing Rules Operation A + B, A - B A * B A rem B Unsigned /, divide Unsigned mod Unsigned Reciprocal Signed /, divide Signed mod Signed Reciprocal Signed Abs(A) Signed -A Result Range Max(A'left, B'left)+1 downto Min(A'right, B'right) A'left + B'left+1 downto A'right + B'right Min(A'left, B left) downto Min(A'right, B right) A'left - B'right downto A'right - B'left -1 B'left downto Min(A'right, B'right) -A'right + 1 downto - A'left A'left - B'right+1 downto A'right - B'left Min(A'left, B'left) downto Min(A'right, B'right) -A'right downto -A'left -1 A left + 1 downto A right A left + 1 downto A right 7 Copyright 2006 Overloading Operation Arithmetic + - * / rem mod abs = /= > < >= <= Shift sll srl sla srl rol ror Ufixed Result ufixed op ufixed ufixed op real real op ufixed ufixed op natural natural op ufixed ufixed op integer Sfixed Result sfixed op sfixed sfixed op real real op sfixed sfixed op integer integer op sfixed sfixed op integer Logic and or xor nand nor xnor ufixed op ufixed sfixed op sfixed Notes: Size rules for integer assume that it is fixed'left downto 0 Size rules for real assume that it is fixed'range 8 Copyright 2006

Literals in Assignments signal A4 : ufixed (3 downto -3) ; -- String Literal A4 <= "0110100" ; -- 6.5 -- Real and/or Integer Literal A4 <= to_ufixed( 6.5, A4 ) ; A4 <= to_ufixed( 6.5, 3, -3 ) ; -- sized by A4 -- pass indicies To_ufixed Size of result based on range of an argument (such as A4) or by passing the indicies (3, -3) Overloaded to accept either real or integer numbers Type real and integer limited the precision of the literal 9 Copyright 2006 Literals in Expressions Issue: a string literal used in an expression has range based on the direction of the base type and left index (integer'low) signal A4 : ufixed (3 downto -3) ; signal Y5 : ufixed (4 downto -3) ; -- Y5 <= A4 + "0110100" ; -- illegal, -- ^^indicies are integer'low to Solutions subtype ufixed4_3 is ufixed (3 downto -3) ; signal A4, B4 : ufixed4_3 ; signal Y5 : ufixed (4 downto -3) ; Y5 <= A4 + ufixed4_3'("0110100") ; Y5 <= A4 + 6.5 ; -- overloading Y5 <= A4 + 6 ; 10 Copyright 2006

Quirks: Accumulator Size of result needs to match size of one of the inputs signal A4 : ufixed (3 downto -3) ; signal Y7 : ufixed (6 downto -3) ; -- Y7 <= Y7 + A4 ; -- illegal, result too big -- Solution, resize the result Y7 <= resize ( arg => Y7 + A4, size_res => Y7, overflow_style => fixed_saturate, -- fixed_wrap round_style => fixed_round -- fixed_truncate ); 11 Copyright 2006 Fixed Point Conversions To_ufixed To_sfixed Resize to_real to_integer to_unsigned to_signed to_slv integer, real, unsigned, sfixed, std_logic_vector to ufixed integer, real, signed, ufixed, std_logic_vector to sfixed ufixed to ufixed or sfixed to sfixed both with potential rounding ufixed or sfixed to real (scalar) ufixed or sfixed to integer (scalar) ufixed to unsigned (array) sfixed to signed (array) ufixed or sfixed to slv (array) for top level ports 12 Copyright 2006

Floating Point Package With floating point, there are parameters that need to be specified. In Accellera VHDL-2006 3.0 they are specified using generics: package ZZZ_float_pkg is new ieee.fixed_generic_pkg generic map ( float_exponent_width => 8, -- default 'high float_fraction_width => 23, -- default 'low float_round_style => IEEE.math_utility_pkg.round_nearest, float_denormalize => true, -- IEEE extended fp float_check_error => true, -- NAN & overflow float_guard_bits => 3, -- # of guard bits no_warning => false -- show warnings ); In the mean time, there is a temporary package float_pkg_c.vhd that uses constants and can be edited to be ZZZ_float_pkg. 13 Copyright 2006 Floating Point Types Library YYY_math_lib ; use YYY_math_lib.ZZZ_float_pkg.all ; Main type is unconstrained: type float is array (integer range <>) of std_logic; Package also defines subtypes: IEEE 754 Single Precision subtype float32 is float( 8 downto -23); IEEE 754 Double Precision subtype float64 is float(11 downto -52); IEEE 854 Extended Precision subtype float128 is float(15 downto -112); 14 Copyright 2006

Floating Point Format signal A, B, Y : float (8 downto -23) ; 8 76543210 12345678901234567890123 S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF E = Exponent is biased by 127 F = Fraction has an implied 1 in leftmost bit value = 2**(E-127) * (1 + F) 0 10000001 10100000000000000000000 = +1 * 2**(129-127) * (1.0 + 0.5 + 0.125) = +1 * 2**2 * (1.625) = 6.5 Range is required to be downto Sign Bit = A'left = bit 8 (0 = positive, 1 = negative) Exponent = range A'left - 1 downto 0 = 7 downto 0 Mantissa = range -1 downto A'right = -1 downto -23 Sign, Exponent and Mantissa are always present 15 Copyright 2006 Special Numbers Zero (Positive 0 = Negative 0) 0 00000000 00000000000000000000000 -- Positive 1 00000000 00000000000000000000000 -- Negative Infinity 0 11111111 00000000000000000000000 -- Positive 1 11111111 00000000000000000000000 -- Negative NAN - Not A Number 1 11111111 00000000000000000000001 Exponent with all 0 is reserved for zero and denormal numbers Exponent with all 1 is reserved for infinity and NAN 16 Copyright 2006

Range of Values Large positive number (Exponent of all 1 is reserved) 0 11111110 00000000000000000000000 = +1 * 2**(254-127) * (1.0 + 0) = 2**(127) Smallest positive number without denormals 0 00000001 00000000000000000000000 = +1 * 2**(1-127) * (1.0 + 0) = 2**(-126) Extended small numbers = Denormals, but only when enabled 0 00000000 10000000000000000000000 = +1 * 2**(1-127) * (0 + 0.5) = +1 * 2**(-126) * 2**(-1) = 2 **(-127) 17 Copyright 2006 Floating Point Types signal A32, B32, Y32 : float (8 downto -23) ; Y32 <= A32 + B32 ; Floating point result will have the maximum exponent and maximum mantissa of its input arguments. Also need to specify: Rounding Default = round_nearest round_nearest, round_zero, round_inf, round_neginf Denormals: On / Off Default = on = true Check NAN and Overflow Default = on = true Guard Bits: Extra bits for rounding. Default = 3 18 Copyright 2006

Overloading Operation Arithmetic + - * / rem mod abs = /= > < >= <= Logic and or xor nand nor xnor Float Result float op float float op real real op float float op integer integer op float float op float Notes: Integers and reals are converted to a float that is the same size as the float argument 19 Copyright 2006 Literals in Assignments signal A_fp32 : float32 ; -- String Literal A_fp32 <= "01000000110100000000000000000000" ; -- 6.5 -- Real and/or Integer Literal A_fp32 <= to_float(6.5, A_fp32); -- size using A_fp32 A_fp32 <= to_float(6.5, 8, -32); -- pass indicies To_float Needs to size the result based on range of an argument (such as A_fp32) or by passing the indicies (8, -32) Overloaded to accept either integers or real numbers Note the required precision of type real and integer is limited by the language 20 Copyright 2006

Literals in Expressions Issue: a string literal used in an expression has range based on the direction of the base type and left index (integer'low) signal A, Y : float32 ; -- Y <= A + "01000000110100000000000000000000"; -- ill -- ^^ range integer'low to... Solutions signal A, Y : float32 ; Y <= A + float32'("01000000110100000000000000000000"); Y <= A + 6.5 ; Y <= A + 6 ; -- overloading -- overloading 21 Copyright 2006 Floating Point Conversions To_float Resize to_real to_integer to_sfixed to_ufixed to_unsigned to_signed to_slv integer, real, ufixed, sfixed, signed, unsigned, and std_logic_vector to float float to float with potential rounding, float to real (scalar) float to integer (scalar) float to sfixed (array) float to ufixed (array) float to unsigned (array) float to signed (array) float to slv (array) for top level ports 22 Copyright 2006

Going Further Until vendors implement Accellera VHDL-2006 3.0, download math_utility_pkg.vhd, fixed_pkg_c.vhd, and float_pkg_c.vhd from: http://vhdl.org/vhdl-200x/vhdl-200x-ft/packages/files.html Current methodology Create a library named, YYY_math_lib, where YYY = project or company Copy fixed_pkg_c to ZZZ_fixed_pkg and float_pkg_c to ZZZ_float_pkg Set the constants to appropriate values Compile into the library For different settings, make additional copies of the packages With package generics (see Accellera VHDL-2006 3.0 standard), package instantiations replace copies of a package with constants 23 Copyright 2006 & VHDL Standards At, we are committed to see that VHDL is updated to incorporate the good features/concepts from other HDL/HVL languages such as SystemVerilog, E (specman), and Vera. At, we invest 100's of hours each year working on VHDL's standards Support VHDL's standards efforts by: Encouraging your EDA vendor(s) to support VHDL standards, Participating in VHDL standards working groups, and / or Purchasing your VHDL training from

VHDL Training Comprehensive VHDL Introduction 4 Days http://www.synthworks.com/comprehensive_vhdl_introduction.htm A design and verification engineer's introduction to VHDL syntax, RTL coding, and testbenches. Students get VHDL hardware experience with our FPGA based lab board. VHDL Testbenches and Verification 3 days http://www.synthworks.com/vhdl_testbench_verification.htm Learn to simplify writing tests by creating transaction-based testbenches. Intermediate VHDL Coding for Synthesis 2 Days http://www.synthworks.com/intermediate_vhdl_synthesis.htm Learn RTL (hardware) coding styles that produce better, faster, and smaller logic. Advanced VHDL Coding for Synthesis 2 Days http://www.synthworks.com/advanced_vhdl_synthesis.htm Learn to avoid RTL coding issues, problem solving techniques, and advanced VHDL constructs. For additional courses see: http://www.synthworks.com