2022-12-26 16:45:43 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// fdivsqrtpreproc.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu, me@KatherineParry.com, cturek@hmc.edu
|
|
|
|
// Modified:13 January 2022
|
|
|
|
//
|
|
|
|
// Purpose: Combined Divide and Square Root Floating Point and Integer Unit
|
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
2022-12-26 16:45:43 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2022-12-26 16:45:43 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file
|
|
|
|
// except in compliance with the License, or, at your option, the Apache License version 2.0. You
|
|
|
|
// may obtain a copy of the License at
|
2022-12-26 16:45:43 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// https://solderpad.org/licenses/SHL-2.1/
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, any work distributed under the
|
|
|
|
// License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
2022-12-26 16:45:43 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module fdivsqrtexpcalc(
|
|
|
|
input logic [`FMTBITS-1:0] Fmt,
|
|
|
|
input logic [`NE-1:0] Xe, Ye,
|
|
|
|
input logic Sqrt,
|
2022-12-29 16:02:44 +00:00
|
|
|
input logic XZero,
|
2022-12-26 16:45:43 +00:00
|
|
|
input logic [`DIVBLEN:0] ell, m,
|
|
|
|
output logic [`NE+1:0] Qe
|
|
|
|
);
|
|
|
|
logic [`NE-2:0] Bias;
|
|
|
|
logic [`NE+1:0] SXExp;
|
|
|
|
logic [`NE+1:0] SExp;
|
|
|
|
logic [`NE+1:0] DExp;
|
|
|
|
|
|
|
|
if (`FPSIZES == 1) begin
|
|
|
|
assign Bias = (`NE-1)'(`BIAS);
|
|
|
|
|
|
|
|
end else if (`FPSIZES == 2) begin
|
|
|
|
assign Bias = Fmt ? (`NE-1)'(`BIAS) : (`NE-1)'(`BIAS1);
|
|
|
|
|
|
|
|
end else if (`FPSIZES == 3) begin
|
|
|
|
always_comb
|
|
|
|
case (Fmt)
|
|
|
|
`FMT: Bias = (`NE-1)'(`BIAS);
|
|
|
|
`FMT1: Bias = (`NE-1)'(`BIAS1);
|
|
|
|
`FMT2: Bias = (`NE-1)'(`BIAS2);
|
|
|
|
default: Bias = 'x;
|
|
|
|
endcase
|
|
|
|
|
|
|
|
end else if (`FPSIZES == 4) begin
|
|
|
|
always_comb
|
|
|
|
case (Fmt)
|
|
|
|
2'h3: Bias = (`NE-1)'(`Q_BIAS);
|
|
|
|
2'h1: Bias = (`NE-1)'(`D_BIAS);
|
|
|
|
2'h0: Bias = (`NE-1)'(`S_BIAS);
|
|
|
|
2'h2: Bias = (`NE-1)'(`H_BIAS);
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
assign SXExp = {2'b0, Xe} - {{(`NE+1-`DIVBLEN){1'b0}}, ell} - (`NE+2)'(`BIAS);
|
|
|
|
assign SExp = {SXExp[`NE+1], SXExp[`NE+1:1]} + {2'b0, Bias};
|
2022-12-31 02:41:40 +00:00
|
|
|
|
2023-01-06 16:35:23 +00:00
|
|
|
// correct exponent for Subnormalized input's normalization shifts
|
2022-12-29 16:02:44 +00:00
|
|
|
assign DExp = ({2'b0, Xe} - {{(`NE+1-`DIVBLEN){1'b0}}, ell} - {2'b0, Ye} + {{(`NE+1-`DIVBLEN){1'b0}}, m} + {3'b0, Bias}) & {`NE+2{~XZero}};
|
2022-12-26 16:45:43 +00:00
|
|
|
assign Qe = Sqrt ? SExp : DExp;
|
|
|
|
endmodule
|