// by Kurt Baty /* //these parameters need to be declared before this include file parameter exponent_width = ?; //length of FP exponent parameter fraction_width = ?; //length of FP fraction parameter round_style = 0; //rounding option = round_nearest parameter ieee_extend = 1; //Use IEEE extended FP = true //`include "fphdl_real_functions.inc" */ `define fp_two_exponent_width 11 `define fp_two_fraction_width 52 `define fp_two_round_style 0 `define fp_two_ieee_extend 1 `include "fphdl_convert_functions.inc" `include "fphdl64_real_functions_base.inc" function [exponent_width+fraction_width:0] abs; // absolute number input [exponent_width+fraction_width:0] arg; abs = fp_two_to_fp_one(absolute(fp_one_to_fp_two(arg))); endfunction // abs function [exponent_width+fraction_width:0] neg; // unary negative input [exponent_width+fraction_width:0] arg; neg = fp_two_to_fp_one(negative(fp_one_to_fp_two(arg))); endfunction // neg function [exponent_width+fraction_width:0] add; // addition (l + r) input [exponent_width+fraction_width:0] l, r; add = fp_two_to_fp_one(addition(fp_one_to_fp_two(l),fp_one_to_fp_two(r))); endfunction // add function [2*exponent_width+fraction_width+1:0] add_c; // complex add input [exponent_width+fraction_width:0] l_r, l_i, r_r, r_i; reg [63:0] res_r,res_i; begin {res_r,res_i} = complex_add(fp_one_to_fp_two(l_r), fp_one_to_fp_two(l_i), fp_one_to_fp_two(r_r), fp_one_to_fp_two(r_i)); add_c = {fp_two_to_fp_one(res_r),fp_two_to_fp_one(res_i)}; end endfunction // add_c function [exponent_width+fraction_width:0] sub; // subtraction (l - r) input [exponent_width+fraction_width:0] l, r; sub = fp_two_to_fp_one(subtract(fp_one_to_fp_two(l),fp_one_to_fp_two(r))); endfunction // sub function [2*exponent_width+fraction_width+1:0] sub_c; // complex subtraction input [exponent_width+fraction_width:0] l_r, l_i, r_r, r_i; reg [63:0] res_r,res_i; begin {res_r,res_i} = complex_subtract(fp_one_to_fp_two(l_r), fp_one_to_fp_two(l_i), fp_one_to_fp_two(r_r), fp_one_to_fp_two(r_i)); sub_c = {fp_two_to_fp_one(res_r),fp_two_to_fp_one(res_i)}; end endfunction // sub_c function [exponent_width+fraction_width:0] mult; // multiplation (l * r) input [exponent_width+fraction_width:0] l, r; mult = fp_two_to_fp_one(multiply(fp_one_to_fp_two(l),fp_one_to_fp_two(r))); endfunction // mult function [2*exponent_width+fraction_width+1:0] mult_c; // complex multiplicaiton input [exponent_width+fraction_width:0] l_r, l_i, r_r, r_i; reg [63:0] res_r,res_i; begin {res_r,res_i} = complex_multiply(fp_one_to_fp_two(l_r), fp_one_to_fp_two(l_i), fp_one_to_fp_two(r_r), fp_one_to_fp_two(r_i)); mult_c = {fp_two_to_fp_one(res_r),fp_two_to_fp_one(res_i)}; end endfunction // mult_c function [exponent_width+fraction_width:0] div; // division (l / r) input [exponent_width+fraction_width:0] l, r; div = fp_two_to_fp_one(divide(fp_one_to_fp_two(l),fp_one_to_fp_two(r))); endfunction // div function [2*exponent_width+fraction_width+1:0] div_c; // complex division input [exponent_width+fraction_width:0] l_r, l_i, r_r, r_i; reg [63:0] res_r,res_i; begin {res_r,res_i} = complex_divide(fp_one_to_fp_two(l_r), fp_one_to_fp_two(l_i), fp_one_to_fp_two(r_r), fp_one_to_fp_two(r_i)); div_c = {fp_two_to_fp_one(res_r),fp_two_to_fp_one(res_i)}; end endfunction // div_c function [exponent_width+fraction_width:0] rem; // remainder input [exponent_width+fraction_width:0] l, r; rem = fp_two_to_fp_one(remainder(fp_one_to_fp_two(l),fp_one_to_fp_two(r))); endfunction // rem function [exponent_width+fraction_width:0] sqrt; // square root input [exponent_width+fraction_width:0] arg; sqrt = fp_two_to_fp_one(square_root(fp_one_to_fp_two(arg))); endfunction // sqrt function [exponent_width+fraction_width:0] log; // log input [31:0] base; // integer input [exponent_width+fraction_width:0] arg; log = fp_two_to_fp_one(logarithm(base, fp_one_to_fp_two(arg))); endfunction // log function [exponent_width+fraction_width:0] ln; // ln input [exponent_width+fraction_width:0] arg; ln = fp_two_to_fp_one(natural_log(fp_one_to_fp_two(arg))); endfunction // ln function [exponent_width+fraction_width:0] pow_fp; // l**r, where l and r are fp input [exponent_width+fraction_width:0] l, r; pow_fp = fp_two_to_fp_one(power_of_fp(fp_one_to_fp_two(l),fp_one_to_fp_two(r))); endfunction // pow_fp function [exponent_width+fraction_width:0] pow; // l**r, where l is fp and r is integer input [exponent_width+fraction_width:0] l; input [31:0] r; // integer pow = fp_two_to_fp_one(power_of(fp_one_to_fp_two(l),r)); endfunction // pow function [exponent_width+fraction_width:0] e; // the constant e input nothing; e = fp_two_to_fp_one(e64(nothing)); endfunction // e function [exponent_width+fraction_width:0] pi; // the constant pi input nothing; pi = fp_two_to_fp_one(pi64(nothing)); endfunction // pi function [exponent_width+fraction_width:0] sin; // sin input [exponent_width+fraction_width:0] arg; sin = fp_two_to_fp_one(sine(fp_one_to_fp_two(arg))); endfunction // sin function [exponent_width+fraction_width:0] cos; // cos input [exponent_width+fraction_width:0] arg; cos = fp_two_to_fp_one(cosine(fp_one_to_fp_two(arg))); endfunction // cos function [exponent_width+fraction_width:0] tan; // tan input [exponent_width+fraction_width:0] arg; tan = fp_two_to_fp_one(tangent(fp_one_to_fp_two(arg))); endfunction // tan function [exponent_width+fraction_width:0] arcsin; // arcsin input [exponent_width+fraction_width:0] arg; arcsin = fp_two_to_fp_one(arc_sine(fp_one_to_fp_two(arg))); endfunction // arcsin function [exponent_width+fraction_width:0] arccos; // arccos input [exponent_width+fraction_width:0] arg; arccos = fp_two_to_fp_one(arc_cosine(fp_one_to_fp_two(arg))); endfunction // arccos function [exponent_width+fraction_width:0] arctan; // arctan input [exponent_width+fraction_width:0] arg; arctan = fp_two_to_fp_one(arc_tangent(fp_one_to_fp_two(arg))); endfunction // arctan function equ; // = input [exponent_width+fraction_width:0] l, r; equ = equal(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // equ function not_equ; // != input [exponent_width+fraction_width:0] l, r; not_equ = not_equal(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // not_equ function gteq; // >= input [exponent_width+fraction_width:0] l, r; gteq = greater_than_or_equal(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // gteq function lteq; // <= input [exponent_width+fraction_width:0] l, r; lteq = less_than_or_equal(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // lteq function gt; // > input [exponent_width+fraction_width:0] l, r; gt = greater_than(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // gt function lt; // < input [exponent_width+fraction_width:0] l, r; lt = less_than(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // lt function [exponent_width+fraction_width:0] integer_to_fp; // integer input, fp output input [31:0] arg; // integer integer_to_fp = fp_two_to_fp_one(integer_to_fp64_func(arg)); endfunction // integer_to_fp /* function [exponent_width+fraction_width:0] real_to_fp; // real input, fp output input [exponent_width+fraction_width:0] arg; // Verilog real number endfunction // real_to_fp use: assign res = fp_two_to_fp_one($realtobits(arg)); */ function [exponent_width+fraction_width:0] fp_to_integer; // fp to integer input [exponent_width+fraction_width:0] arg; // floating point fp_to_integer = fp64_to_integer_func(fp_one_to_fp_two(arg)); endfunction // fp_to_integer /* function [exponent_width+fraction_width:0] fp_to_real; // fp to real input [exponent_width+fraction_width:0] arg; // floating point endfunction // fp_to_real use: assign res = $bitstoreal(fp_one_to_fp_two(arg)); */ function [exponent_width+fraction_width:0] Copysign; // copies sign of x to y input [exponent_width+fraction_width:0] x, y; Copysign = 0; // Copysign = fp_two_to_fp_one(Copysign_func(fp_one_to_fp_two(x),fp_one_to_fp_two(y))); endfunction // Copysign function [exponent_width+fraction_width:0] Scalb; // multiplies y by 2**n (where n is an integer) input [exponent_width+fraction_width:0] y; input [31:0] n; // integer Scalb = 0; // Scalb = fp_two_to_fp_one(Scale_by(fp_one_to_fp_two(y),n)); endfunction // Scalb function [exponent_width+fraction_width:0] Logb; // returns the log (base 2) of arg input [exponent_width+fraction_width:0] arg; Logb = 0; // Logb = fp_two_to_fp_one(logb2(fp_one_to_fp_two(arg))); endfunction // Logb function [exponent_width+fraction_width:0] Nextafter; // Gives you the next logical number after x input [exponent_width+fraction_width:0] x, y; Nextafter = 0; // Nextafter = fp_two_to_fp_one(Nextafter_func(fp_one_to_fp_two(x),fp_one_to_fp_two(y))); endfunction // Nextafter function Finite; // returns "1" if x is not infinity. input [exponent_width+fraction_width:0] x; Finite = 0; // Finite = Finite_func(fp_one_to_fp_two(x)); endfunction // Finite function Isnan; // returns "1" is x in any type of NAN input [exponent_width+fraction_width:0] x; Isnan = 0; // Isnan = Isnan_func(fp_one_to_fp_two(x)); endfunction // Isnan function Unordered; // returns "1" if x or y is a NAN. input [exponent_width+fraction_width:0] x, y; Unordered = 0; // Unordered = Unordered_func(fp_one_to_fp_two(x),fp_one_to_fp_two(y)); endfunction // Unordered