2022-09-07 13:12:23 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// fdivsqrtpostproc.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu, me@KatherineParry.com, Cedar Turek
|
|
|
|
// Modified:13 January 2022
|
|
|
|
//
|
|
|
|
// Purpose: Combined Divide and Square Root Floating Point and Integer Unit
|
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
|
|
|
// MIT LICENSE
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
// software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
|
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
|
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
// substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
|
|
// OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module fdivsqrtpostproc(
|
2022-09-07 13:42:37 +00:00
|
|
|
input logic [`DIVb+3:0] WS, WC,
|
2022-09-07 13:12:23 +00:00
|
|
|
input logic [`DIVN-2:0] D, // U0.N-1
|
2022-09-07 14:00:13 +00:00
|
|
|
input logic [`DIVb:0] FirstS, FirstSM, FirstQ, FirstQM,
|
2022-09-07 13:12:23 +00:00
|
|
|
input logic [`DIVb-1:0] FirstC,
|
|
|
|
input logic [`DIVCOPIES-1:0] qn,
|
2022-09-07 13:42:37 +00:00
|
|
|
input logic SqrtM,
|
2022-09-07 14:00:13 +00:00
|
|
|
output logic [`DIVb-(`RADIX/4):0] QmM,
|
2022-09-07 13:42:37 +00:00
|
|
|
output logic WZero,
|
2022-09-07 14:00:13 +00:00
|
|
|
output logic DivSM
|
2022-09-07 13:12:23 +00:00
|
|
|
);
|
|
|
|
|
2022-09-07 13:42:37 +00:00
|
|
|
logic [`DIVb+3:0] W;
|
2022-09-07 14:00:13 +00:00
|
|
|
logic NegSticky;
|
2022-09-07 13:42:37 +00:00
|
|
|
|
|
|
|
// check for early termination on an exact result. If the result is not exact, the sticky should be set
|
|
|
|
if (`RADIX == 2) begin
|
|
|
|
logic [`DIVb+3:0] FZero;
|
|
|
|
logic [`DIVb+2:0] FirstK;
|
|
|
|
assign FirstK = ({3'b111, FirstC<<1} & ~({3'b111, FirstC<<1} << 1));
|
|
|
|
assign FZero = SqrtM ? {FirstSM[`DIVb], FirstSM, 2'b0} | {FirstK,1'b0} : {3'b1,D,{`DIVb-`DIVN+2{1'b0}}};
|
|
|
|
assign WZero = ((WS^WC)=={WS[`DIVb+2:0]|WC[`DIVb+2:0], 1'b0})|(((WS+WC+FZero)==0)&qn[`DIVCOPIES-1]);
|
|
|
|
end else begin
|
|
|
|
assign WZero = ((WS^WC)=={WS[`DIVb+2:0]|WC[`DIVb+2:0], 1'b0});
|
|
|
|
end
|
|
|
|
assign DivSM = ~WZero;
|
|
|
|
|
|
|
|
// Determine if sticky bit is negative
|
|
|
|
assign W = WC+WS;
|
|
|
|
assign NegSticky = W[`DIVb+3];
|
2022-09-07 13:12:23 +00:00
|
|
|
|
2022-09-07 14:00:13 +00:00
|
|
|
// division takes the result from the next cycle, which is shifted to the left one more time so the square root also needs to be shifted
|
|
|
|
always_comb
|
|
|
|
if(SqrtM) // sqrt ouputs in the range (1, .5]
|
|
|
|
if(NegSticky) QmM = {FirstSM[`DIVb-1-(`RADIX/4):0], 1'b0};
|
|
|
|
else QmM = {FirstS[`DIVb-1-(`RADIX/4):0], 1'b0};
|
|
|
|
else
|
|
|
|
if(NegSticky) QmM = FirstQM[`DIVb-(`RADIX/4):0];
|
|
|
|
else QmM = FirstQ[`DIVb-(`RADIX/4):0];
|
|
|
|
|
2022-09-07 13:12:23 +00:00
|
|
|
endmodule
|