OpenCores
URL https://opencores.org/ocsvn/ft816float/ft816float/trunk

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog/] [fpNormalize.v] - Diff between revs 8 and 10

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 8 Rev 10
Line 1... Line 1...
`timescale 1ns / 1ps
`timescale 1ns / 1ps
// ============================================================================
// ============================================================================
//        __
//        __
//   \\__/ o\    (C) 2006-2016  Robert Finch, Waterloo
//   \\__/ o\    (C) 2006-2018  Robert Finch, Waterloo
//    \  __ /    All rights reserved.
//    \  __ /    All rights reserved.
//     \/_//     robfinch<remove>@finitron.ca
//     \/_//     robfinch<remove>@finitron.ca
//       ||
//       ||
//
//
//      fpNormalize.v
//      fpNormalize.v
Line 46... Line 46...
localparam EMSB = WID==128 ? 14 :
localparam EMSB = WID==128 ? 14 :
                  WID==96 ? 14 :
                  WID==96 ? 14 :
                  WID==80 ? 14 :
                  WID==80 ? 14 :
                  WID==64 ? 10 :
                  WID==64 ? 10 :
                                  WID==52 ? 10 :
                                  WID==52 ? 10 :
                                  WID==48 ? 10 :
                                  WID==48 ? 11 :
                                  WID==44 ? 10 :
                                  WID==44 ? 10 :
                                  WID==42 ? 10 :
                                  WID==42 ? 10 :
                                  WID==40 ?  9 :
                                  WID==40 ?  9 :
                                  WID==32 ?  7 :
                                  WID==32 ?  7 :
                                  WID==24 ?  6 : 4;
                                  WID==24 ?  6 : 4;
localparam FMSB = WID==128 ? 111 :
localparam FMSB = WID==128 ? 111 :
                  WID==96 ? 79 :
                  WID==96 ? 79 :
                  WID==80 ? 63 :
                  WID==80 ? 63 :
                  WID==64 ? 51 :
                  WID==64 ? 51 :
                                  WID==52 ? 39 :
                                  WID==52 ? 39 :
                                  WID==48 ? 35 :
                                  WID==48 ? 34 :
                                  WID==44 ? 31 :
                                  WID==44 ? 31 :
                                  WID==42 ? 29 :
                                  WID==42 ? 29 :
                                  WID==40 ? 28 :
                                  WID==40 ? 28 :
                                  WID==32 ? 22 :
                                  WID==32 ? 22 :
                                  WID==24 ? 15 : 9;
                                  WID==24 ? 15 : 9;
Line 96... Line 96...
wire rbit =  i[FMSB-1];
wire rbit =  i[FMSB-1];
wire sbit = |i[FMSB-2:0];
wire sbit = |i[FMSB-2:0];
// shift mantissa left by one to reduce to a single whole digit
// shift mantissa left by one to reduce to a single whole digit
// if there is no exponent increment
// if there is no exponent increment
wire [FMSB+4:0] mo;
wire [FMSB+4:0] mo;
wire [FMSB+4:0] mo1 = xInf1 & incExp1 ? 0 :
wire [FMSB+4:0] mo1 = (xInf1 & incExp1) ? 0 :
        incExp1 ? {i[FX:FMSB+2],gbit,rbit,sbit} :               // reduce mantissa size
        incExp1 ? {i[FX:FMSB+2],gbit,rbit,sbit} :               // reduce mantissa size
                         {i[FX-1:FMSB+1],gbit,rbit,sbit};       // reduce mantissa size
                         {i[FX-1:FMSB+1],gbit,rbit,sbit};       // reduce mantissa size
wire [FMSB+3:0] mo2;
wire [FMSB+3:0] mo2;
wire [7:0] leadingZeros2;
wire [7:0] leadingZeros2;
 
 
generate
generate
begin
begin
if (WID==32)
if (WID==32) begin
cntlz32Reg clz0 (.clk(clk), .ce(ce), .i({mo1,5'b0}), .o(leadingZeros2) );
cntlz32Reg clz0 (.clk(clk), .ce(ce), .i({mo1,5'b0}), .o(leadingZeros2) );
 
assign leadingZeros2[7:6] = 2'b00;
 
end
else if (WID==128)
else if (WID==128)
cntlz128Reg clz0 (.clk(clk), .ce(ce), .i({mo1,12'b0}), .o(leadingZeros2) );
cntlz128Reg clz0 (.clk(clk), .ce(ce), .i({mo1,12'b0}), .o(leadingZeros2) );
else if (WID==96)
else if (WID==96)
cntlz96Reg clz0 (.clk(clk), .ce(ce), .i({mo1,12'b0}), .o(leadingZeros2) );
cntlz96Reg clz0 (.clk(clk), .ce(ce), .i({mo1,12'b0}), .o(leadingZeros2) );
else if (WID==80)
else if (WID==80)
Line 122... Line 124...
// compensate for leadingZeros delay
// compensate for leadingZeros delay
wire xInf2;
wire xInf2;
delay1 #(EMSB+1) d2(.clk(clk), .ce(ce), .i(xo1), .o(xo2) );
delay1 #(EMSB+1) d2(.clk(clk), .ce(ce), .i(xo1), .o(xo2) );
delay1 #(1)      d3(.clk(clk), .ce(ce), .i(xInf1), .o(xInf2) );
delay1 #(1)      d3(.clk(clk), .ce(ce), .i(xInf1), .o(xInf2) );
 
 
 
 
// If the exponent underflowed, then the shift direction must be to the
// If the exponent underflowed, then the shift direction must be to the
// right regardless of mantissa bits; the number is denormalized.
// right regardless of mantissa bits; the number is denormalized.
// Otherwise the shift direction must be to the left.
// Otherwise the shift direction must be to the left.
wire rightOrLeft2;      // 0=left,1=right
wire rightOrLeft2;      // 0=left,1=right
delay1 #(1) d8(.clk(clk), .ce(ce), .i(under), .o(rightOrLeft2) );
delay1 #(1) d8(.clk(clk), .ce(ce), .i(under), .o(rightOrLeft2) );
Line 135... Line 138...
 
 
// compute amount to shift right
// compute amount to shift right
// at infinity the exponent can't be incremented, so we can't shift right
// at infinity the exponent can't be incremented, so we can't shift right
// otherwise it was an underflow situation so the exponent was negative
// otherwise it was an underflow situation so the exponent was negative
// shift amount needs to be negated for shift register
// shift amount needs to be negated for shift register
wire [7:0] rshiftAmt2 = xInf2 ? 0 : -xo2 > FMSB+3 ? FMSB+4 : FMSB+4+xo2;  // xo2 is negative !
wire [7:0] rshiftAmt2 = xInf2 ? 0 : (($unsigned(-xo2) > $unsigned(FMSB+3)) ? FMSB+4 : -xo2);//FMSB+4+xo2; // xo2 is negative !
 
 
 
 
// sign
// sign
// the output sign is the same as the input sign
// the output sign is the same as the input sign
delay1 #(1)      d7(.clk(clk), .ce(ce), .i(so1), .o(so) );
delay1 #(1)      d7(.clk(clk), .ce(ce), .i(so1), .o(so) );
Line 158... Line 161...
wire [FMSB+3:0] mo2a;
wire [FMSB+3:0] mo2a;
//shiftAndMask #(FMSB+4) u1 (.op({rightOrLeft2,1'b0}), .a(mo2), .b(rightOrLeft2 ? lshiftAmt2 : rshiftAmt2), .mb(6'd0), .me(FMSB+3), .o(mo2a) );
//shiftAndMask #(FMSB+4) u1 (.op({rightOrLeft2,1'b0}), .a(mo2), .b(rightOrLeft2 ? lshiftAmt2 : rshiftAmt2), .mb(6'd0), .me(FMSB+3), .o(mo2a) );
 
 
//      always @(posedge clk)
//      always @(posedge clk)
//              if (ce)
//              if (ce)
assign mo = rightOrLeft2 ? mo2 >> rshiftAmt2 : mo2 << lshiftAmt2;
assign mo = rightOrLeft2 ? (mo2 >> rshiftAmt2) : (mo2 << lshiftAmt2);
 
//always @(posedge clk)
 
//      $display("%c xo2=%d -xo2=%d rshift=%d >%d %d", rightOrLeft2 ? "r" : "l",xo2, -xo2, rshiftAmt2,($unsigned(-xo2) > $unsigned(FMSB+3)),FMSB+3);
assign o = {so,xo,mo[FMSB+4:1]};
assign o = {so,xo,mo[FMSB+4:1]};
 
 
endmodule
endmodule
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.