/* -------------------------------------------------------------------- -- -- -- Copyright©2002 by the Institute of Electrical and Electronics Engineers, Inc. -- Three Park Avenue -- New York, NY 10016-5997, USA -- All rights reserved. -- -- This document is an unapproved draft of a proposed IEEE Standard. As such, -- this document is subject to change. USE AT YOUR OWN RISK! Because this -- is an unapproved draft, this document must not be utilized for any -- conformance/compliance purposes. Permission is hereby granted for IEEE -- Standards Committee participants to reproduce this document for purposes -- of IEEE standardization activities only. Prior to submitting this document -- to another standards development organization for standardization -- activities, permission must first be obtained from the Manager, Standards -- Licensing and Contracts, IEEE Standards Activities Department. Other -- entities seeking permission to reproduce this document, in whole or in -- part, must obtain permission from the Manager, Standards Licensing and -- Contracts, IEEE Standard Activities Department. -- -- IEEE Standards Activities Department -- Standards Licensing and Contracts -- 445 Hoes Lane, P.O. Box 1331 -- Piscataway, NJ 08855-1331, USA -- -- Title : fphdl32_real_functions.inc < IEEE std # 1076.3 > -- -- Developers: VHDL Synthesis working group, PAR 1076.3 -- -- Purpose : Functions for real based 32 bit floating point -- -- Limitation: -- -- -------------------------------------------------------------------- -- Last Modified $Date: 2003-01-15 09:50:54-05 $ -- $Id: fphdl32_real_functions.inc,v 1.1 2003-01-15 09:50:54-05 bishop Exp $ -- $Log: fphdl32_real_functions.inc,v $ -- Revision 1.1 2003-01-15 09:50:54-05 bishop -- Initial revision -- -- -------------------------------------------------------------------- */ // by Kurt Baty `define fp_one_width 32 `define fp_one_exponent_width 8 `define fp_one_fraction_width 23 `define fp_one_round_style 0 `define fp_one_ieee_extend 1 `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_fixed_convert_functions.inc" `include "fphdl64_real_functions_base.inc" function [`fp_one_width-1:0] abs; // absolute number input [`fp_one_width-1:0] arg; abs = fp_two_to_fp_one(absolute(fp_one_to_fp_two(arg))); endfunction // abs function [`fp_one_width-1:0] neg; // unary negative input [`fp_one_width-1:0] arg; neg = fp_two_to_fp_one(negative(fp_one_to_fp_two(arg))); endfunction // neg function [`fp_one_width-1:0] add; // addition (l + r) input [`fp_one_width-1: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*`fp_one_width-1:0] add_c; // complex add input [`fp_one_width-1: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 [`fp_one_width-1:0] sub; // subtraction (l - r) input [`fp_one_width-1: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*`fp_one_width-1:0] sub_c; // complex subtraction input [`fp_one_width-1: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 [`fp_one_width-1:0] mult; // multiplation (l * r) input [`fp_one_width-1: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*`fp_one_width-1:0] mult_c; // complex multiplicaiton input [`fp_one_width-1: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 [`fp_one_width-1:0] div; // division (l / r) input [`fp_one_width-1: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*`fp_one_width-1:0] div_c; // complex division input [`fp_one_width-1: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 [`fp_one_width-1:0] rem; // remainder input [`fp_one_width-1: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 [`fp_one_width-1:0] sqrt; // square root input [`fp_one_width-1:0] arg; sqrt = fp_two_to_fp_one(square_root(fp_one_to_fp_two(arg))); endfunction // sqrt function [`fp_one_width-1:0] log; // log input [31:0] base; // integer input [`fp_one_width-1:0] arg; log = fp_two_to_fp_one(logarithm(base, fp_one_to_fp_two(arg))); endfunction // log function [`fp_one_width-1:0] ln; // ln input [`fp_one_width-1:0] arg; ln = fp_two_to_fp_one(natural_log(fp_one_to_fp_two(arg))); endfunction // ln function [`fp_one_width-1:0] pow_fp; // l**r, where l and r are fp input [`fp_one_width-1: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 [`fp_one_width-1:0] pow; // l**r, where l is fp and r is integer input [`fp_one_width-1: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 [`fp_one_width-1:0] e; // the constant e input nothing; e = fp_two_to_fp_one(e64(nothing)); endfunction // e function [`fp_one_width-1:0] pi; // the constant pi input nothing; pi = fp_two_to_fp_one(pi64(nothing)); endfunction // pi function [`fp_one_width-1:0] sin; // sin input [`fp_one_width-1:0] arg; sin = fp_two_to_fp_one(sine(fp_one_to_fp_two(arg))); endfunction // sin function [`fp_one_width-1:0] cos; // cos input [`fp_one_width-1:0] arg; cos = fp_two_to_fp_one(cosine(fp_one_to_fp_two(arg))); endfunction // cos function [`fp_one_width-1:0] tan; // tan input [`fp_one_width-1:0] arg; tan = fp_two_to_fp_one(tangent(fp_one_to_fp_two(arg))); endfunction // tan function [`fp_one_width-1:0] arcsin; // arcsin input [`fp_one_width-1:0] arg; arcsin = fp_two_to_fp_one(arc_sine(fp_one_to_fp_two(arg))); endfunction // arcsin function [`fp_one_width-1:0] arccos; // arccos input [`fp_one_width-1:0] arg; arccos = fp_two_to_fp_one(arc_cosine(fp_one_to_fp_two(arg))); endfunction // arccos function [`fp_one_width-1:0] arctan; // arctan input [`fp_one_width-1:0] arg; arctan = fp_two_to_fp_one(arc_tangent(fp_one_to_fp_two(arg))); endfunction // arctan function equ; // = input [`fp_one_width-1:0] l, r; equ = equal(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // equ function not_equ; // != input [`fp_one_width-1: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 [`fp_one_width-1: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 [`fp_one_width-1: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 [`fp_one_width-1:0] l, r; gt = greater_than(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // gt function lt; // < input [`fp_one_width-1:0] l, r; lt = less_than(fp_one_to_fp_two(l),fp_one_to_fp_two(r)); endfunction // lt function [`fp_one_width-1:0] integer_to_fp32; // integer input, fp output input [31:0] arg; // integer integer_to_fp32 = fp_two_to_fp_one(integer_to_fp64_func(arg)); endfunction // integer_to_fp32 /* function [`fp_one_width-1:0] real_to_fp32; // real input, fp output input [`fp_one_width-1:0] arg; // Verilog real number endfunction // real_to_fp32 use: assign res = fp_two_to_fp_one($realtobits(arg)); */ function [`fp_one_width-1:0] fp32_to_integer; // fp to integer input [`fp_one_width-1:0] arg; // floating point fp32_to_integer = fp64_to_integer_func(fp_one_to_fp_two(arg)); endfunction // fp32_to_integer /* function [`fp_one_width-1:0] fp32_to_real; // fp to real input [`fp_one_width-1:0] arg; // floating point endfunction // fp32_to_real use: assign res = $bitstoreal(fp_one_to_fp_two(arg)); */ function [`fp_one_width-1:0] Copysign; // copies sign of x to y input [`fp_one_width-1: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 [`fp_one_width-1:0] Scalb; // multiplies y by 2**n (where n is an integer) input [`fp_one_width-1: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 [`fp_one_width-1:0] Logb; // returns the log (base 2) of arg input [`fp_one_width-1:0] arg; Logb = 0; // Logb = fp_two_to_fp_one(logb2(fp_one_to_fp_two(arg))); endfunction // Logb function [`fp_one_width-1:0] Nextafter; // Gives you the next logical number after x input [`fp_one_width-1: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 [`fp_one_width-1: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 [`fp_one_width-1: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 [`fp_one_width-1:0] x, y; Unordered = 0; // Unordered = Unordered_func(fp_one_to_fp_two(x),fp_one_to_fp_two(y)); endfunction // Unordered