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
|
// ||
|
// ||
|
//
|
//
|
// fpRound.v
|
// fpRound.v
|
Line 33... |
Line 33... |
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 94... |
Line 94... |
|
|
assign so = i[MSB+3];
|
assign so = i[MSB+3];
|
assign xo = rounded[MSB:FMSB+2];
|
assign xo = rounded[MSB:FMSB+2];
|
|
|
always @(rnd or xo or carry or dn or rounded or mo1)
|
always @(rnd or xo or carry or dn or rounded or mo1)
|
casex({rnd,&xo,carry,dn})
|
casez({rnd,&xo,carry,dn})
|
4'b0xx0: mo = mo1[FMSB+2:2]; // not rounding, not denormalized, => hide MSB
|
4'b0??0: mo = mo1[FMSB+2:2]; // not rounding, not denormalized, => hide MSB
|
4'b0xx1: mo = mo1[FMSB+3:3]; // not rounding, denormalized
|
4'b0??1: mo = mo1[FMSB+3:3]; // not rounding, denormalized
|
4'b1000: mo = rounded[FMSB :0]; // exponent didn't change, number was normalized, => hide MSB
|
4'b1000: mo = rounded[FMSB :0]; // exponent didn't change, number was normalized, => hide MSB
|
4'b1001: mo = rounded[FMSB+1:1]; // exponent didn't change, but number was denormalized, => retain MSB
|
4'b1001: mo = rounded[FMSB+1:1]; // exponent didn't change, but number was denormalized, => retain MSB
|
4'b1010: mo = rounded[FMSB+1:1]; // exponent incremented (new MSB generated), number was normalized, => hide 'extra (FMSB+2)' MSB
|
4'b1010: mo = rounded[FMSB+1:1]; // exponent incremented (new MSB generated), number was normalized, => hide 'extra (FMSB+2)' MSB
|
4'b1011: mo = rounded[FMSB+1:1]; // exponent incremented (new MSB generated), number was denormalized, number became normalized, => hide 'extra (FMSB+2)' MSB
|
4'b1011: mo = rounded[FMSB+1:1]; // exponent incremented (new MSB generated), number was denormalized, number became normalized, => hide 'extra (FMSB+2)' MSB
|
4'b11xx: mo = 0; // number became infinite, no need to check carry etc., rnd would be zero if input was NaN or infinite
|
4'b11??: mo = 0; // number became infinite, no need to check carry etc., rnd would be zero if input was NaN or infinite
|
endcase
|
endcase
|
|
|
endmodule
|
endmodule
|
|
|
|
|
Line 117... |
Line 117... |
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;
|