2022-06-23 23:01:30 +00:00
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module divshiftcalc(
|
|
|
|
input logic [`DIVLEN+2:0] Quot,
|
2022-07-07 23:01:33 +00:00
|
|
|
input logic [`FMTBITS-1:0] Fmt,
|
2022-06-27 20:43:55 +00:00
|
|
|
input logic [$clog2(`DIVLEN/2+3)-1:0] EarlyTermShiftDiv2M,
|
2022-07-07 23:01:33 +00:00
|
|
|
input logic [`NE+1:0] DivCalcExpM,
|
2022-06-23 23:01:30 +00:00
|
|
|
output logic [$clog2(`NORMSHIFTSZ)-1:0] DivShiftAmt,
|
2022-06-24 21:02:50 +00:00
|
|
|
output logic [`NORMSHIFTSZ-1:0] DivShiftIn,
|
2022-06-28 00:16:22 +00:00
|
|
|
output logic DivResDenorm,
|
|
|
|
output logic [`NE+1:0] DivDenormShift
|
2022-06-23 23:01:30 +00:00
|
|
|
);
|
2022-06-24 21:02:50 +00:00
|
|
|
logic [`NE+1:0] NormShift;
|
2022-07-03 19:26:22 +00:00
|
|
|
logic [`NE+1:0] Nf;
|
2022-06-25 00:04:53 +00:00
|
|
|
|
|
|
|
// is the result denromalized
|
|
|
|
// if the exponent is 1 then the result needs to be normalized then the result is denormalizes
|
2022-06-28 00:16:22 +00:00
|
|
|
assign DivResDenorm = DivCalcExpM[`NE+1]|(~|DivCalcExpM[`NE+1:0]);
|
2022-06-27 20:43:55 +00:00
|
|
|
// select the proper fraction lengnth
|
2022-07-07 23:01:33 +00:00
|
|
|
// if (`FPSIZES == 1) begin
|
|
|
|
// assign Nf = (`NE+2)'(`NF);
|
2022-06-27 20:43:55 +00:00
|
|
|
|
2022-07-07 23:01:33 +00:00
|
|
|
// end else if (`FPSIZES == 2) begin
|
|
|
|
// assign Nf = Fmt ? (`NE+2)'(`NF) : (`NE+2)'(`NF1);
|
2022-06-27 20:43:55 +00:00
|
|
|
|
2022-07-07 23:01:33 +00:00
|
|
|
// end else if (`FPSIZES == 3) begin
|
|
|
|
// always_comb
|
|
|
|
// case (Fmt)
|
|
|
|
// `FMT: Nf = (`NE+2)'(`NF);
|
|
|
|
// `FMT1: Nf = (`NE+2)'(`NF1);
|
|
|
|
// `FMT2: Nf = (`NE+2)'(`NF2);
|
|
|
|
// default: Nf = 1'bx;
|
|
|
|
// endcase
|
|
|
|
// end else if (`FPSIZES == 4) begin
|
|
|
|
// always_comb
|
|
|
|
// case (Fmt)
|
|
|
|
// 2'h3: Nf = (`NE+2)'(`Q_NF);
|
|
|
|
// 2'h1: Nf = (`NE+2)'(`D_NF);
|
|
|
|
// 2'h0: Nf = (`NE+2)'(`S_NF);
|
|
|
|
// 2'h2: Nf = (`NE+2)'(`H_NF);
|
|
|
|
// endcase
|
|
|
|
// end
|
2022-06-25 00:04:53 +00:00
|
|
|
// if the result is denormalized
|
2022-07-07 23:01:33 +00:00
|
|
|
// 00000000x.xxxxxx... Exp = DivCalcExpM
|
|
|
|
// .00000000xxxxxxx... >> NF+1 Exp = DivCalcExpM+NF+1
|
|
|
|
// .00xxxxxxxxxxxxx... << DivCalcExpM+NF+1 Exp = +1
|
2022-06-25 00:04:53 +00:00
|
|
|
// .0000xxxxxxxxxxx... >> 1 Exp = 1
|
2022-07-07 23:01:33 +00:00
|
|
|
// Left shift amount = DivCalcExpM+NF+1-1
|
|
|
|
assign DivDenormShift = (`NE+2)'(`NF)+DivCalcExpM;
|
2022-06-27 20:43:55 +00:00
|
|
|
// if the result is normalized
|
2022-07-07 23:01:33 +00:00
|
|
|
// 00000000x.xxxxxx... Exp = DivCalcExpM
|
|
|
|
// .00000000xxxxxxx... >> NF+1 Exp = DivCalcExpM+NF+1
|
|
|
|
// 00000000.xxxxxxx... << NF Exp = DivCalcExpM+1
|
|
|
|
// 00000000x.xxxxxx... << NF Exp = DivCalcExpM (extra shift done afterwards)
|
|
|
|
// 00000000xx.xxxxx... << 1? Exp = DivCalcExpM-1 (determined after)
|
2022-06-28 00:16:22 +00:00
|
|
|
// inital Left shift amount = NF
|
2022-07-07 23:01:33 +00:00
|
|
|
assign NormShift = (`NE+2)'(`NF);
|
2022-06-27 17:04:51 +00:00
|
|
|
// if the shift amount is negitive then dont shift (keep sticky bit)
|
2022-06-28 00:16:22 +00:00
|
|
|
assign DivShiftAmt = (DivResDenorm ? DivDenormShift[$clog2(`NORMSHIFTSZ)-1:0]&{$clog2(`NORMSHIFTSZ){~DivDenormShift[`NE+1]}} : NormShift[$clog2(`NORMSHIFTSZ)-1:0])+{{$clog2(`NORMSHIFTSZ)-$clog2(`DIVLEN/2+3)-1{1'b0}}, EarlyTermShiftDiv2M&{$clog2(`DIVLEN/2+3){~DivDenormShift[`NE+1]}}, 1'b0};
|
2022-06-24 21:02:50 +00:00
|
|
|
|
2022-06-25 01:42:23 +00:00
|
|
|
// *** may be able to reduce shifter size
|
|
|
|
assign DivShiftIn = {{`NF{1'b0}}, Quot[`DIVLEN+2:0], {`NORMSHIFTSZ-`DIVLEN-3-`NF{1'b0}}};
|
2022-06-23 23:01:30 +00:00
|
|
|
|
|
|
|
endmodule
|