URL
https://opencores.org/ocsvn/ft816float/ft816float/trunk
Subversion Repositories ft816float
[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [DFPTrunc96.sv] - Rev 89
Compare with Previous | Blame | View Log
// ============================================================================// __// \\__/ o\ (C) 2019-2021 Robert Finch, Waterloo// \ __ / All rights reserved.// \/_// robfinch<remove>@finitron.ca// ||//// DFPTrunc96.sv// - convert floating point to integer (chop off fractional bits)// - single cycle latency floating point unit// - IEEE 754 representation////// BSD 3-Clause License// Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are met://// 1. Redistributions of source code must retain the above copyright notice, this// list of conditions and the following disclaimer.//// 2. Redistributions in binary form must reproduce the above copyright notice,// this list of conditions and the following disclaimer in the documentation// and/or other materials provided with the distribution.//// 3. Neither the name of the copyright holder nor the names of its// contributors may be used to endorse or promote products derived from// this software without specific prior written permission.//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.//// ============================================================================import DFPPkg::*;module DFPTrunc96(clk, ce, i, o, overflow);parameter N=25; // number of sig. digitsinput clk;input ce;input DFP96 i;output DFP96 o;output reg overflow;integer n;DFP96U maxInt;DFP96U iu, ou;DFPUnpack96 u01 (i, iu);DFPPack96 u02 (ou, o);assign maxInt.sign = 1'b0;assign maxInt.exp = 12'hBFE;assign maxInt.sig = 100'h9999999999999999999999999;// maximum unsigned integer valuewire [11:0] zeroXp = 12'h5FF; // simple constant - value of exp for zero// Decompose fp valuereg sgn; // signreg [11:0] exp;reg [N*4-1:0] man;reg [N*4-1:0] mask;wire [12:0] shamt = (N - 1) - (exp - zeroXp);genvar g;generate begin : gMaskfor (g = 0; g < N; g = g +1)always_combmask[g*4+3:g*4] = (g >= shamt) ? 4'hF : 4'h0;endendgeneratealways_combsgn = iu.sign;always_combexp = iu.exp;always_combif (exp > zeroXp + (N-1))man = iu.sig;elseman = iu.sig & mask;always_ff @(posedge clk)if (ce) beginif (exp < zeroXp) beginou <= 'd0;ou.sign <= sgn; // retain signendelse beginou.sign <= sgn;ou.exp <= exp;ou.sig <= man;endendalways_comboverflow <= 1'b0;endmodule
