Floating-Point Arithmetic ELEC 418 Advanced Digital Systems Dr. Ron Hayne Images Courtesy of Thomson Engineering.

Slides:



Advertisements
Similar presentations
©2004 Brooks/Cole FIGURES FOR CHAPTER 20 VHDL FOR DIGITAL SYSTEM DESIGN Click the mouse to move to the next page. Use the ESC key to exit this chapter.
Advertisements

Sequential Design ELEC 311 Digital Logic and Circuits Dr. Ron Hayne
Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
Digital Logic with VHDL EE 230 Digital Systems Fall 2006 (10/17/2006)
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Datorteknik FloatingPoint bild 1 Floating point Number system corresponding to the decimal notation 1,837 * 10 significand exponent a great number of corresponding.
Major Numeric Data Types Unsigned Integers Signed Integer Alphanumeric Data – ASCII & UNICODE Floating Point Numbers.
COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (cont.) (Appendix A, Computer Architecture: A Quantitative.
Integer Arithmetic Floating Point Representation Floating Point Arithmetic Topics.
SM Charts and Microprogramming
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Number Systems II Prepared by Dr P Marais (Modified by D Burford)
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computer Architecture
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.
Figure 5.1 Conversion from decimal to binary. Table 5.1 Numbers in different systems.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
9.4 FLOATING-POINT REPRESENTATION
ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.
Integer & Floating Point Representations CDA 3101 Discussion Session 05.
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Design Examples ELEC 418 Advanced Digital Systems Dr. Ron Hayne Images Courtesy of Thomson Engineering.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as.
Number Representation and Arithmetic Circuits
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
Floating Point Arithmetic – Part I
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Floating Point Representations
Lecture 9: Floating Point
NxN Crossbar design for Barrel Shifter
Floating Point Number system corresponding to the decimal notation
CS 232: Computer Architecture II
William Stallings Computer Organization and Architecture 7th Edition
Luddy Harrison CS433G Spring 2007
Number Representations
Floating Point Arithmetic
How to represent real numbers
How to represent real numbers
ECEG-3202 Computer Architecture and Organization
Chapter 5 – Number Representation and Arithmetic Circuits
Overview Fractions & Sign Extension Floating Point Representations
Design of Networks for Arithmetic Operation
Number Representations
Floating Point Arithmetic
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

Floating-Point Arithmetic ELEC 418 Advanced Digital Systems Dr. Ron Hayne Images Courtesy of Thomson Engineering

418_072 IEEE 754 Floating-Point  Fraction Sign-Magnitude  IEEE Single Precision Format (32-bits)  IEEE Double Precision Format (64-bits)  Exponent Biased Notation

418_073 Special Cases

418_074 A Simple Floating-Point Format  N = F x 2 E Fraction 4-bit 2's Complement s.fff Range -1 to Exponent 4-bit 2's Complement eeee Range -8 to +7 Normalization Shift until sign bit and next bit are different Zero F = E = 1000 N = x 2 -8

418_075 Floating-Point Multiplication 1.Add exponents 2.Multiply fractions 3.If product is 0, adjust for proper 0 4.Normalize product fraction 5.Check for exponent overflow or underflow 6.Round product fraction

418_077 Floating-Point Hardware

418_078 Floating-Point Hardware

418_079 SM Chart

418_0710 VHDL Model library IEEE; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity FMUL is port(CLK, St: in std_logic; F1, E1, F2, E2: in std_logic_vector(3 downto 0); F: out std_logic_vector(6 downto 0); E: out std_logic_vector(4 downto 0); V, done: out std_logic); end FMUL;

418_0711 VHDL Model architecture BEHAVE of FMUL is signal A, B, C: std_logic_vector(3 downto 0);--F regs signal compout, addout: std_logic_vector(3 downto 0); alias M: std_logic is B(0); signal X, Y: std_logic_vector(4 downto 0); -- E regs signal Load, Adx, SM8, RSF, LSF: std_logic; -- Main signal AdSh, Sh, Cm, Mdone: std_logic; -- Mult signal PS1, NS1: integer range 0 to 3;-- Main state signal State, Nextstate: integer range 0 to 4;-- Mult

418_0712 VHDL Model begin main_control: process(PS1, St, Mdone, X, A) begin Load <= '0'; Adx <= '0'; NS1 <= 0; SM8 <= '0'; RSF <= '0'; LSF <= '0'; V <= '0'; done <= '0'; case PS1 is when 0 => if St = '1' then Load <= '1'; NS1 <= 1; end if; when 1 => Adx <= '1'; NS1 <= 2;

418_0713 VHDL Model when 2 => if Mdone = '1' then if A = 0 then -- FZ SM8 <= '1'; elsif A = 4 then -- FV RSF <= '1'; elsif A(2) = A(1) then -- not Fnorm LSF <= '1'; end if; NS1 <= 3; else NS1 <= 2; end if;

418_0714 VHDL Model when 3 => done <= '1'; if X(4) /= X(3) then -- EV V <= '1'; end if; if ST = '0' then NS1 <= 0; end if; end case; end process main_control;

418_0715 Multiplier Control

418_0716 VHDL Model mul2c: process(State, Adx, M) begin AdSh <= '0'; Sh <= '0'; Cm <= '0'; Mdone <= '0'; Nextstate <= 0; case State is when 0 => if Adx = '1' then if M = '1' then AdSh <= '1'; else Sh <= '1'; end if; Nextstate <= 1; end if;

418_0717 VHDL Model when 1 | 2 => if M = '1' then AdSh <= '1'; else Sh <= '1'; end if; Nextstate <= State + 1;

418_0718 VHDL Model when 3 => if M = '1' then Cm <= '1'; AdSh <= '1'; else Sh <='1'; end if; Nextstate <= 4; when 4 => Mdone <= '1'; Nextstate <= 0; end case; end process mul2c;

418_0719 Data Path

418_0720 VHDL Model compout <= not C when Cm = '1' else C; addout <= A + compout + Cm; datapath: process(CLK) begin if rising_edge(CLK) then PS1 <= NS1; State <= Nextstate; if Load = '1' then X <= E1(3) & E1; Y <= E2(3) & E2; A <= "0000"; B <= F2; C <= F1; end if;

418_0721 VHDL Model if ADX = '1' then X <= X + Y; end if; if SM8 = '1' then X <= "11000"; end if;

418_0722 VHDL Model if RSF = '1' then A <= '0' & A(3 downto 1); B <= A(0) & B(3 downto 1); X <= X + 1; end if; if LSF = '1' then A <= A(2 downto 0) & B(3); B <= B(2 downto 0) & '0'; X <= X - 1; end if;

418_0723 VHDL Model if AdSh = '1' then A <= compout(3) & addout(3 downto 1); B <= addout(0) & B(3 downto 1); end if; if Sh = '1' then A <= A(3) & A(3 downto 1); B <= A(0) & B(3 downto 1); end if; end process datapath; F <= A(2 downto 0) & B; E <= X; end BEHAVE;

418_0724 VHDL Simulation

418_0725 FPGA Implementation

418_0726 Floating-Point Addition 1.Compare exponents. If not equal, shift smaller fraction to right and add 1 to exponent (repeat). 2.Add fractions. 3.If result is 0, adjust for proper 0. 4.If fraction overflow, shift right and add 1. 5.If unnormalized, shift left and subtract 1 (repeat). 6.Check for exponent overflow. 7.Round fraction. If not normalized, go to step 4.

418_0727 Floating-Point Hardware  Comparator for exponents (step 1a)  Shift register (right), incrementer (step 1b)  ALU (adder) to add fractions (step 2)  Shifter (right/left), incrementer/decrementer (steps 4,5)  Overflow detector (step 6)  Rounding hardware (step 7)

418_0728 Floating-Point Adder * IEEE Format

418_0729 VHDL Model entity FPADD is port(CLK, St: in std_logic; done, ovf, unf: out std_logic; FPinput: in std_logic_vector(31 downto 0); FPsum: out std_logic_vector(31 downto 0)); end FPADD; architecture FPADDER of FPADD is signal F1, F2: std_logic_vector(25 downto 0); signal E1, E2: std_logic_vector(7 downto 0); signal S1, S2, FV, FU: std_logic; signal F1comp, F2comp: std_logic_vector(27 downto 0); signal Addout, Fsum: std_logic_vector(27 downto 0); signal State: integer range 0 to 6;

418_0730 VHDL Model begin F1comp <= not("00" & F1) + 1 when S1 = '1' else "00" & F1; F2comp <= not("00" & F2) + 1 when S2 = '1' else "00" & F2; Addout <= F1comp + F2comp; Fsum <= Addout when Addout(27) = '0' else not Addout + 1; FV <= Fsum(27) xor Fsum(26); FU <= not F1(25); FPsum <= S1 & E1 & F1(24 downto 2);

418_0731 VHDL Model process(CLK) begin if rising_edge(CLK) then case State is when 0 => if St = '1' then E1 <= FPinput(30 downto 23); S1 <= FPinput(31); F1(24 downto 0) <= FPinput(22 downto 0) & "00"; if FPinput = 0 then F1(25) <= '0'; else F1(25) <= '1'; end if; done <= '0'; ovf <= '0'; unf <= '0'; State <= 1; end if;

418_0732 VHDL Model when 1 => E2 <= FPinput(30 downto 23); S2 <= FPinput(31); F2(24 downto 0) <= FPinput(22 downto 0) & "00"; if FPinput = 0 then F2(25) <= '0'; else F2(25) <= '1'; end if; State <= 2;

418_0733 VHDL Model when 2 => if F1 = 0 or F2 = 0 then State <= 3; else if E1 = E2 then State <= 3; elsif E1 < E2 then F1 <= '0' & F1(25 downto 1); E1 <= E1 + 1; else F2 <= '0' & F2(25 downto 1); E2 <= E2 + 1; end if;

418_0734 VHDL Model when 3 => S1 <= Addout(27); if FV = '0' then F1 <= Fsum(25 downto 0); else F1 <= Fsum(26 downto 1); E1 <= E1 + 1; end if; State <= 4; when 4 => if F1 = 0 then E1 <= " "; State <= 6; else State <= 5; end if;

418_0735 VHDL Model when 5 => if E1 = 0 then unf <= '1'; State <= 6; elsif FU = '0' then State <= 6; else F1 <= F1(24 downto 0) & '0'; E1 <= E1 - 1; end if; when 6 => if E1 = 255 then ovf <= '1'; end if; done <= '1'; State <= 0; end case; end if; end process; end FPADDER;

418_0736 Summary  IEEE Floating-Point Formats  Simple Floating-Point Format  Floating-Point Multiplication  Floating-Point Addition