library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.numeric_std.all;
|
use ieee.numeric_std.all;
|
|
|
package fp_generic is
|
package fp_generic is
|
|
|
subtype fp_type is std_logic_vector(31 downto 0);
|
subtype fp_type is std_logic_vector(31 downto 0);
|
subtype fp_sign_type is std_logic;
|
subtype fp_sign_type is std_logic;
|
subtype fp_exp_type is unsigned(7 downto 0);
|
subtype fp_exp_type is unsigned(7 downto 0);
|
subtype fp_mantissa_type is unsigned(23 downto 0);
|
subtype fp_mantissa_type is unsigned(23 downto 0);
|
subtype fp_long_mantissa_type is unsigned(47 downto 0);
|
subtype fp_long_mantissa_type is unsigned(47 downto 0);
|
|
|
subtype fp_error_type is std_logic_vector(5 downto 0);
|
subtype fp_error_type is std_logic_vector(5 downto 0);
|
constant FP_ERR_INVALID:fp_error_type:="000001";
|
constant FP_ERR_INVALID:fp_error_type:="000001";
|
constant FP_ERR_DIVBYZERO:fp_error_type:="000100";
|
constant FP_ERR_DIVBYZERO:fp_error_type:="000100";
|
constant FP_ERR_OVERFLOW:fp_error_type:="001000";
|
constant FP_ERR_OVERFLOW:fp_error_type:="001000";
|
constant FP_ERR_UNDERFLOW:fp_error_type:="010000";
|
constant FP_ERR_UNDERFLOW:fp_error_type:="010000";
|
constant FP_ERR_INEXACT:fp_error_type:="100000";
|
constant FP_ERR_INEXACT:fp_error_type:="100000";
|
|
|
function fp_sign(fp:fp_type) return fp_sign_type;
|
function fp_sign(fp:fp_type) return fp_sign_type;
|
function fp_exp(fp:fp_type) return fp_exp_type;
|
function fp_exp(fp:fp_type) return fp_exp_type;
|
function fp_mantissa(fp:fp_type) return fp_mantissa_type;
|
function fp_mantissa(fp:fp_type) return fp_mantissa_type;
|
|
|
function fp_is_normal(fp:fp_type) return boolean;
|
function fp_is_normal(fp:fp_type) return boolean;
|
function fp_is_zero(fp:fp_type) return boolean;
|
function fp_is_zero(fp:fp_type) return boolean;
|
function fp_is_subnormal(fp:fp_type) return boolean;
|
function fp_is_subnormal(fp:fp_type) return boolean;
|
function fp_is_infinite(fp:fp_type) return boolean;
|
function fp_is_infinite(fp:fp_type) return boolean;
|
function fp_is_nan(fp:fp_type) return boolean;
|
function fp_is_nan(fp:fp_type) return boolean;
|
function fp_is_signalling(fp:fp_type) return boolean;
|
function fp_is_signalling(fp:fp_type) return boolean;
|
function fp_is_quiet(fp:fp_type) return boolean;
|
function fp_is_quiet(fp:fp_type) return boolean;
|
|
function fp_is_positive(fp:fp_type) return boolean;
|
|
function fp_is_negative(fp:fp_type) return boolean;
|
|
|
end package;
|
end package;
|
|
|
package body fp_generic is
|
package body fp_generic is
|
|
|
function fp_sign(fp:fp_type) return fp_sign_type is
|
function fp_sign(fp:fp_type) return fp_sign_type is
|
begin
|
begin
|
return fp(31);
|
return fp(31);
|
end function fp_sign;
|
end function fp_sign;
|
|
|
function fp_exp(fp:fp_type) return fp_exp_type is
|
function fp_exp(fp:fp_type) return fp_exp_type is
|
begin
|
begin
|
return(resize((unsigned(fp) srl 23),8));
|
return(resize((unsigned(fp) srl 23),8));
|
end function fp_exp;
|
end function fp_exp;
|
|
|
function fp_mantissa(fp:fp_type) return fp_mantissa_type is
|
function fp_mantissa(fp:fp_type) return fp_mantissa_type is
|
begin
|
begin
|
return(fp_mantissa_type("1"&fp(22 downto 0))); -- Prepend implied '1' bit of IEEE-754 mantissa in order to return a 24 bit entity
|
return(fp_mantissa_type("1"&fp(22 downto 0))); -- Prepend implied '1' bit of IEEE-754 mantissa in order to return a 24 bit entity
|
end function fp_mantissa;
|
end function fp_mantissa;
|
|
|
function fp_exp_is_min(exp:fp_exp_type) return boolean is
|
function fp_exp_is_min(exp:fp_exp_type) return boolean is
|
begin
|
begin
|
return (exp=0);
|
return (exp=0);
|
end function fp_exp_is_min;
|
end function fp_exp_is_min;
|
|
|
function fp_exp_is_max(exp:fp_exp_type) return boolean is
|
function fp_exp_is_max(exp:fp_exp_type) return boolean is
|
begin
|
begin
|
return (exp=255);
|
return (exp=255);
|
end function fp_exp_is_max;
|
end function fp_exp_is_max;
|
|
|
function fp_is_normal(fp:fp_type) return boolean is
|
function fp_is_normal(fp:fp_type) return boolean is
|
variable exp:fp_exp_type;
|
variable exp:fp_exp_type;
|
begin
|
begin
|
exp:=fp_exp(fp);
|
exp:=fp_exp(fp);
|
|
|
return not fp_exp_is_min(exp) and not fp_exp_is_max(exp);
|
return not fp_exp_is_min(exp) and not fp_exp_is_max(exp);
|
end function fp_is_normal;
|
end function fp_is_normal;
|
|
|
function fp_is_zero(fp:fp_type) return boolean is
|
function fp_is_zero(fp:fp_type) return boolean is
|
begin
|
begin
|
return (fp_exp(fp)=0) and (fp_mantissa(fp)=0);
|
return (fp_exp(fp)=0) and (fp_mantissa(fp)(fp_mantissa_type'high-1 downto 0)=0);
|
end function fp_is_zero;
|
end function fp_is_zero;
|
|
|
function fp_is_subnormal(fp:fp_type) return boolean is
|
function fp_is_subnormal(fp:fp_type) return boolean is
|
begin
|
begin
|
return (fp_exp(fp)=0) and (fp_mantissa(fp)/=0);
|
return (fp_exp(fp)=0) and (fp_mantissa(fp)(fp_mantissa_type'high-1 downto 0)/=0);
|
end function fp_is_subnormal;
|
end function fp_is_subnormal;
|
|
|
function fp_is_infinite(fp:fp_type) return boolean is
|
function fp_is_infinite(fp:fp_type) return boolean is
|
begin
|
begin
|
return (fp_exp_is_max(fp_exp(fp))) and (fp_mantissa(fp)=0);
|
return (fp_exp_is_max(fp_exp(fp))) and (fp_mantissa(fp)(fp_mantissa_type'high-1 downto 0)=0);
|
end function fp_is_infinite;
|
end function fp_is_infinite;
|
|
|
function fp_is_nan(fp:fp_type) return boolean is
|
function fp_is_nan(fp:fp_type) return boolean is
|
begin
|
begin
|
return (fp_exp_is_max(fp_exp(fp))) and (fp_mantissa(fp)/=0);
|
return (fp_exp_is_max(fp_exp(fp))) and (fp_mantissa(fp)(fp_mantissa_type'high-1 downto 0)/=0);
|
end function fp_is_nan;
|
end function fp_is_nan;
|
|
|
function fp_is_signalling(fp:fp_type) return boolean is
|
function fp_is_signalling(fp:fp_type) return boolean is
|
begin
|
begin
|
return fp_is_nan(fp) and fp_mantissa(fp)(22)='0';
|
return fp_is_nan(fp) and fp_mantissa(fp)(fp_mantissa_type'high-1)='0';
|
end function fp_is_signalling;
|
end function fp_is_signalling;
|
|
|
function fp_is_quiet(fp:fp_type) return boolean is
|
function fp_is_quiet(fp:fp_type) return boolean is
|
begin
|
begin
|
return fp_is_nan(fp) and fp_mantissa(fp)(22)='1';
|
return fp_is_nan(fp) and fp_mantissa(fp)(fp_mantissa_type'high-1)='1';
|
end function fp_is_quiet;
|
end function fp_is_quiet;
|
|
|
|
function fp_is_positive(fp:fp_type) return boolean is
|
|
begin
|
|
return (fp_sign(fp)='0');
|
|
end function fp_is_positive;
|
|
|
|
function fp_is_negative(fp:fp_type) return boolean is
|
|
begin
|
|
return (fp_sign(fp)='1');
|
|
end function fp_is_negative;
|
|
|
end package body fp_generic;
|
end package body fp_generic;
|
|
|