⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 float_pkg_c.vhdl

📁 something i got you may find this useful
💻 VHDL
📖 第 1 页 / 共 5 页
字号:
-- ---------------------------------------------------------------------- "float_pkg" package contains functions for floating point math.-- Please see the documentation for the floating point package.-- This package should be compiled into "ieee_proposed" and used as follows:-- use ieee.std_logic_1164.all;-- use ieee.numeric_std.all;-- use ieee_proposed.math_utility.all;-- use ieee_proposed.fixed_pkg.all;-- use ieee_proposed.float_pkg.all;----  This verison is designed to work with the VHDL-2002 compilers.  Please--  note the "%%%" comments.  These are where we diverge from the--  VHDL-200X LRM.---- ---------------------------------------------------------------------- Version    : $Revision: 1.7 $-- Date       : $Date: 2007-02-28 10:25:01-05 $-- --------------------------------------------------------------------use STD.TEXTIO.all;library IEEE;use IEEE.STD_LOGIC_1164.all;use IEEE.NUMERIC_STD.all;library ieee_proposed;use ieee_proposed.math_utility_pkg.all;use ieee_proposed.fixed_pkg.all;package float_pkg is-- generic (    -- Defaults for sizing routines, when you do a "to_float" this will be    -- the default size.  Example float32 would be 8 and 23 (8 downto -23)    constant float_exponent_width : NATURAL    := 8;    constant float_fraction_width : NATURAL    := 23;    -- Rounding algorithm, "round_nearest" is default, other valid values    -- are "round_zero" (truncation), "round_inf" (round up), and    -- "round_neginf" (round down)    constant float_round_style    : round_type := round_nearest;    -- Denormal numbers (very small numbers near zero) true or false    constant float_denormalize    : BOOLEAN    := true;    -- Turns on NAN processing (invalid numbers and overflow) true of false    constant float_check_error    : BOOLEAN    := true;    -- Guard bits are added to the bottom of every operation for rounding.    -- any natural number (including 0) are valid.    constant float_guard_bits     : NATURAL    := 3;    -- If TRUE, then turn off warnings on "X" propagation    constant no_warning           : BOOLEAN    := (false    );  -- Author David Bishop (dbishop@vhdl.org)  constant CopyRightNotice : STRING :=    "Copyright 2006 by IEEE. All rights reserved.";  -- Note that the size of the vector is not defined here, but in  -- the package which calls this one.  type UNRESOLVED_float is array (INTEGER range <>) of STD_ULOGIC;  -- main type  subtype U_float is UNRESOLVED_float;  subtype float is UNRESOLVED_float;  -----------------------------------------------------------------------------  -- Use the float type to define your own floating point numbers.  -- There must be a negative index or the packages will error out.  -- Minimum supported is "subtype float7 is float (3 downto -3);"  -- "subtype float16 is float (6 downto -9);" is probably the smallest  -- practical one to use.  -----------------------------------------------------------------------------  -- IEEE 754 single precision  subtype UNRESOLVED_float32 is UNRESOLVED_float (8 downto -23);--  alias U_float32 is UNRESOLVED_float32;  subtype U_float32 is UNRESOLVED_float32;  subtype float32 is float (8 downto -23);  -----------------------------------------------------------------------------  -- IEEE-754 single precision floating point.  This is a "float"  -- in C, and a FLOAT in Fortran.  The exponent is 8 bits wide, and  -- the fraction is 23 bits wide.  This format can hold roughly 7 decimal  -- digits.  Infinity is 2**127 = 1.7E38 in this number system.  -- The bit representation is as follows:  -- 1 09876543 21098765432109876543210  -- 8 76543210 12345678901234567890123  -- 0 00000000 00000000000000000000000  -- 8 7      0 -1                  -23  -- +/-   exp.  fraction  -----------------------------------------------------------------------------  -- IEEE 754 double precision  subtype UNRESOLVED_float64 is UNRESOLVED_float (11 downto -52);--  alias U_float64 is UNRESOLVED_float64;  subtype U_float64 is UNRESOLVED_float64;  subtype float64 is float (11 downto -52);  -----------------------------------------------------------------------------  -- IEEE-754 double precision floating point.  This is a "double float"  -- in C, and a FLOAT*8 in Fortran.  The exponent is 11 bits wide, and  -- the fraction is 52 bits wide.  This format can hold roughly 15 decimal  -- digits.  Infinity is 2**2047 in this number system.  -- The bit representation is as follows:  --  3 21098765432 1098765432109876543210987654321098765432109876543210  --  1 09876543210 1234567890123456789012345678901234567890123456789012  --  S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF  -- 11 10        0 -1                                               -52  -- +/-  exponent    fraction  -----------------------------------------------------------------------------  -- IEEE 854 & C extended precision  subtype UNRESOLVED_float128 is UNRESOLVED_float (15 downto -112);--  alias U_float128 is UNRESOLVED_float128;  subtype U_float128 is UNRESOLVED_float128;  subtype float128 is float (15 downto -112);  -----------------------------------------------------------------------------  -- The 128 bit floating point number is "long double" in C (on  -- some systems this is a 70 bit floating point number) and FLOAT*32  -- in Fortran.  The exponent is 15 bits wide and the fraction is 112  -- bits wide. This number can handle approximately 33 decimal digits.  -- Infinity is 2**32,767 in this number system.  -----------------------------------------------------------------------------  -- purpose: Checks for a valid floating point number  type valid_fpstate is (nan,           -- Signaling NaN (C FP_NAN)                         quiet_nan,     -- Quiet NaN (C FP_NAN)                         neg_inf,       -- Negative infinity (C FP_INFINITE)                         neg_normal,    -- negative normalized nonzero                         neg_denormal,  -- negative denormalized (FP_SUBNORMAL)                         neg_zero,      -- -0 (C FP_ZERO)                         pos_zero,      -- +0 (C FP_ZERO)                         pos_denormal,  -- Positive denormalized (FP_SUBNORMAL)                         pos_normal,    -- positive normalized nonzero                         pos_inf,       -- positive infinity                         isx);          -- at least one input is unknown  -- This deferred constant will tell you if the package body is synthesizable  -- or implemented as real numbers.  constant fphdlsynth_or_real : BOOLEAN;  -- deferred constant  -- Returns the class which X falls into  function Classfp (    x           : UNRESOLVED_float;              -- floating point input    check_error : BOOLEAN := float_check_error)  -- check for errors    return valid_fpstate;  -- Arithmetic functions, these operators do not require parameters.  function "abs" (arg : UNRESOLVED_float) return UNRESOLVED_float;  function "-"   (arg : UNRESOLVED_float) return UNRESOLVED_float;  -- These allows the base math functions to use the default values  -- of their parameters.  Thus they do full IEEE floating point.  function "+"   (l, r : UNRESOLVED_float) return UNRESOLVED_float;  function "-"   (l, r : UNRESOLVED_float) return UNRESOLVED_float;  function "*"   (l, r : UNRESOLVED_float) return UNRESOLVED_float;  function "/"   (l, r : UNRESOLVED_float) return UNRESOLVED_float;  function "rem" (l, r : UNRESOLVED_float) return UNRESOLVED_float;  function "mod" (l, r : UNRESOLVED_float) return UNRESOLVED_float;  -- Basic parameter list  -- round_style - Selects the rounding algorithm to use  -- guard - extra bits added to the end if the operation to add precision  -- check_error - When "false" turns off NAN and overflow checks  -- denormalize - When "false" turns off denormal number processing  function add (    l, r                 : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  function subtract (    l, r                 : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  function multiply (    l, r                 : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  function divide (    l, r                 : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  function remainder (    l, r                 : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  function modulo (    l, r                 : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  -- reciprocal  function reciprocal (    arg                  : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  function dividebyp2 (    l, r                 : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  -- Multiply accumulate  result = l*r + c  function mac (    l, r, c              : UNRESOLVED_float;  -- floating point input    constant round_style : round_type := float_round_style;  -- rounding option    constant guard       : NATURAL    := float_guard_bits;  -- number of guard bits    constant check_error : BOOLEAN    := float_check_error;  -- check for errors    constant denormalize : BOOLEAN    := float_denormalize)  -- Use IEEE extended FP    return UNRESOLVED_float;  -- Square root (all 754 based implementations need this)  function sqrt (    arg                  : UNRESOLVED_float;       -- floating point input    constant round_style : round_type := float_round_style;    constant guard       : NATURAL    := float_guard_bits;    constant check_error : BOOLEAN    := float_check_error;    constant denormalize : BOOLEAN    := float_denormalize)    return UNRESOLVED_float;  function Is_Negative (arg : UNRESOLVED_float) return BOOLEAN;  -----------------------------------------------------------------------------  -- compare functions  -- =, /=, >=, <=, <, >, maximum, minimum  function eq (                               -- equal =    l, r                 : UNRESOLVED_float;  -- floating point input    constant check_error : BOOLEAN := float_check_error;    constant denormalize : BOOLEAN := float_denormalize)    return BOOLEAN;  function ne (                               -- not equal /=    l, r                 : UNRESOLVED_float;  -- floating point input    constant check_error : BOOLEAN := float_check_error;    constant denormalize : BOOLEAN := float_denormalize)    return BOOLEAN;  function lt (                               -- less than <    l, r                 : UNRESOLVED_float;  -- floating point input    constant check_error : BOOLEAN := float_check_error;    constant denormalize : BOOLEAN := float_denormalize)    return BOOLEAN;  function gt (                               -- greater than >    l, r                 : UNRESOLVED_float;  -- floating point input    constant check_error : BOOLEAN := float_check_error;    constant denormalize : BOOLEAN := float_denormalize)    return BOOLEAN;  function le (                               -- less than or equal to <=    l, r                 : UNRESOLVED_float;  -- floating point input    constant check_error : BOOLEAN := float_check_error;    constant denormalize : BOOLEAN := float_denormalize)    return BOOLEAN;  function ge (                               -- greater than or equal to >=    l, r                 : UNRESOLVED_float;  -- floating point input    constant check_error : BOOLEAN := float_check_error;    constant denormalize : BOOLEAN := float_denormalize)    return BOOLEAN;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -