📄 fixed_pkg_c.vhdl
字号:
-- ---------------------------------------------------------------------- "fixed_pkg_c.vhdl" package contains functions for fixed point math.-- Please see the documentation for the fixed 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_pkg.all;-- use ieee_proposed.fixed_pkg.all;---- This verison is designed to work with the VHDL-2002 compilers -- synthesis tools. Please note the "%%%" comments. These are where we-- diverge from the VHDL-200X LRM.-- ---------------------------------------------------------------------- Version : $Revision: 1.11 $-- Date : $Date: 2006-12-22 14:55:19-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;package fixed_pkg is-- generic ( -- Rounding routine to use in fixed point, fixed_round or fixed_truncate constant fixed_round_style : fixed_round_style_type := fixed_round; -- Overflow routine to use in fixed point, fixed_saturate or fixed_wrap constant fixed_overflow_style : fixed_overflow_style_type := fixed_saturate; -- Extra bits used in divide routines constant fixed_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."; -- base Unsigned fixed point type, downto direction assumed type UNRESOLVED_ufixed is array (INTEGER range <>) of STD_ULOGIC; -- base Signed fixed point type, downto direction assumed type UNRESOLVED_sfixed is array (INTEGER range <>) of STD_ULOGIC; subtype U_ufixed is UNRESOLVED_ufixed; subtype U_sfixed is UNRESOLVED_sfixed; subtype ufixed is UNRESOLVED_ufixed; subtype sfixed is UNRESOLVED_sfixed; --=========================================================================== -- Arithmetic Operators: --=========================================================================== -- Absolute value, 2's complement -- abs sfixed(a downto b) = sfixed(a+1 downto b) function "abs" (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- Negation, 2's complement -- - sfixed(a downto b) = sfixed(a+1 downto b) function "-" (arg : UNRESOLVED_sfixed)return UNRESOLVED_sfixed; -- Addition -- ufixed(a downto b) + ufixed(c downto d) -- = ufixed(maximum(a,c)+1 downto minimum(b,d)) function "+" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- sfixed(a downto b) + sfixed(c downto d) -- = sfixed(maximum(a,c)+1 downto minimum(b,d)) function "+" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- Subtraction -- ufixed(a downto b) - ufixed(c downto d) -- = ufixed(maximum(a,c)+1 downto minimum(b,d)) function "-" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- sfixed(a downto b) - sfixed(c downto d) -- = sfixed(maximum(a,c)+1 downto minimum(b,d)) function "-" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- Multiplication -- ufixed(a downto b) * ufixed(c downto d) = ufixed(a+c+1 downto b+d) function "*" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- sfixed(a downto b) * sfixed(c downto d) = sfixed(a+c+1 downto b+d) function "*" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- Division -- ufixed(a downto b) / ufixed(c downto d) = ufixed(a-d downto b-c-1) function "/" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- sfixed(a downto b) / sfixed(c downto d) = sfixed(a-d+1 downto b-c) function "/" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- Remainder -- ufixed (a downto b) rem ufixed (c downto d) -- = ufixed (minimum(a,c) downto minimum(b,d)) function "rem" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- sfixed (a downto b) rem sfixed (c downto d) -- = sfixed (minimum(a,c) downto minimum(b,d)) function "rem" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- Modulo -- ufixed (a downto b) mod ufixed (c downto d) -- = ufixed (minimum(a,c) downto minimum(b, d)) function "mod" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- sfixed (a downto b) mod sfixed (c downto d) -- = sfixed (c downto minimum(b, d)) function "mod" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; ---------------------------------------------------------------------------- -- In these routines the "real" or "natural" (integer) -- are converted into a fixed point number and then the operation is -- performed. It is assumed that the array will be large enough. -- If the input is "real" then the real number is converted into a fixed of -- the same size as the fixed point input. If the number is an "integer" -- then it is converted into fixed with the range (l'high downto 0). ---------------------------------------------------------------------------- -- ufixed(a downto b) + ufixed(a downto b) = ufixed(a+1 downto b) function "+" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; -- ufixed(c downto d) + ufixed(c downto d) = ufixed(c+1 downto d) function "+" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed(a downto b) + ufixed(a downto 0) = ufixed(a+1 downto minimum(0,b)) function "+" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; -- ufixed(a downto 0) + ufixed(c downto d) = ufixed(c+1 downto minimum(0,d)) function "+" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed(a downto b) - ufixed(a downto b) = ufixed(a+1 downto b) function "-" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; -- ufixed(c downto d) - ufixed(c downto d) = ufixed(c+1 downto d) function "-" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed(a downto b) - ufixed(a downto 0) = ufixed(a+1 downto minimum(0,b)) function "-" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; -- ufixed(a downto 0) + ufixed(c downto d) = ufixed(c+1 downto minimum(0,d)) function "-" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed(a downto b) * ufixed(a downto b) = ufixed(2a+1 downto 2b) function "*" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; -- ufixed(c downto d) * ufixed(c downto d) = ufixed(2c+1 downto 2d) function "*" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed (a downto b) * ufixed (a downto 0) = ufixed (2a+1 downto b) function "*" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; -- ufixed (a downto b) * ufixed (a downto 0) = ufixed (2a+1 downto b) function "*" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed(a downto b) / ufixed(a downto b) = ufixed(a-b downto b-a-1) function "/" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; -- ufixed(a downto b) / ufixed(a downto b) = ufixed(a-b downto b-a-1) function "/" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed(a downto b) / ufixed(a downto 0) = ufixed(a downto b-a-1) function "/" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; -- ufixed(c downto 0) / ufixed(c downto d) = ufixed(c-d downto -c-1) function "/" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed (a downto b) rem ufixed (a downto b) = ufixed (a downto b) function "rem" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; -- ufixed (c downto d) rem ufixed (c downto d) = ufixed (c downto d) function "rem" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed (a downto b) rem ufixed (a downto 0) = ufixed (a downto minimum(b,0)) function "rem" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; -- ufixed (c downto 0) rem ufixed (c downto d) = ufixed (c downto minimum(d,0)) function "rem" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed (a downto b) mod ufixed (a downto b) = ufixed (a downto b) function "mod" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; -- ufixed (c downto d) mod ufixed (c downto d) = ufixed (c downto d) function "mod" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- ufixed (a downto b) mod ufixed (a downto 0) = ufixed (a downto minimum(b,0)) function "mod" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; -- ufixed (c downto 0) mod ufixed (c downto d) = ufixed (c downto minimum(d,0)) function "mod" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; -- sfixed(a downto b) + sfixed(a downto b) = sfixed(a+1 downto b) function "+" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; -- sfixed(c downto d) + sfixed(c downto d) = sfixed(c+1 downto d) function "+" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed(a downto b) + sfixed(a downto 0) = sfixed(a+1 downto minimum(0,b)) function "+" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; -- sfixed(c downto 0) + sfixed(c downto d) = sfixed(c+1 downto minimum(0,d)) function "+" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed(a downto b) - sfixed(a downto b) = sfixed(a+1 downto b) function "-" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; -- sfixed(c downto d) - sfixed(c downto d) = sfixed(c+1 downto d) function "-" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed(a downto b) - sfixed(a downto 0) = sfixed(a+1 downto minimum(0,b)) function "-" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; -- sfixed(c downto 0) - sfixed(c downto d) = sfixed(c+1 downto minimum(0,d)) function "-" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed(a downto b) * sfixed(a downto b) = sfixed(2a+1 downto 2b) function "*" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; -- sfixed(c downto d) * sfixed(c downto d) = sfixed(2c+1 downto 2d) function "*" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed(a downto b) * sfixed(a downto 0) = sfixed(2a+1 downto b) function "*" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; -- sfixed(c downto 0) * sfixed(c downto d) = sfixed(2c+1 downto d) function "*" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed(a downto b) / sfixed(a downto b) = sfixed(a-b+1 downto b-a) function "/" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; -- sfixed(c downto d) / sfixed(c downto d) = sfixed(c-d+1 downto d-c) function "/" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed(a downto b) / sfixed(a downto 0) = sfixed(a+1 downto b-a) function "/" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; -- sfixed(c downto 0) / sfixed(c downto d) = sfixed(c-d+1 downto -c) function "/" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed (a downto b) rem sfixed (a downto b) = sfixed (a downto b) function "rem" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; -- sfixed (c downto d) rem sfixed (c downto d) = sfixed (c downto d) function "rem" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed (a downto b) rem sfixed (a downto 0) = sfixed (a downto minimum(b,0)) function "rem" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; -- sfixed (c downto 0) rem sfixed (c downto d) = sfixed (c downto minimum(d,0)) function "rem" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed (a downto b) mod sfixed (a downto b) = sfixed (a downto b) function "mod" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; -- sfixed (c downto d) mod sfixed (c downto d) = sfixed (c downto d) function "mod" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- sfixed (a downto b) mod sfixed (a downto 0) = sfixed (a downto minimum(b,0)) function "mod" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; -- sfixed (c downto 0) mod sfixed (c downto d) = sfixed (c downto minimum(d,0)) function "mod" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; -- This version of divide gives the user more control -- ufixed(a downto b) / ufixed(c downto d) = ufixed(a-d downto b-c-1) function divide ( l, r : UNRESOLVED_ufixed; constant round_style : fixed_round_style_type := fixed_round_style; constant guard_bits : NATURAL := fixed_guard_bits) return UNRESOLVED_ufixed; -- This version of divide gives the user more control -- sfixed(a downto b) / sfixed(c downto d) = sfixed(a-d+1 downto b-c) function divide ( l, r : UNRESOLVED_sfixed; constant round_style : fixed_round_style_type := fixed_round_style; constant guard_bits : NATURAL := fixed_guard_bits) return UNRESOLVED_sfixed; -- These functions return 1/X
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -