2022-06-23 23:01:30 +00:00
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module divshiftcalc(
|
|
|
|
input logic [`DIVLEN+2:0] Quot,
|
2022-06-24 19:41:40 +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-24 19:41:40 +00:00
|
|
|
output logic [`NE+1:0] CorrDivExp
|
2022-06-23 23:01:30 +00:00
|
|
|
);
|
2022-06-24 21:02:50 +00:00
|
|
|
logic ResDenorm;
|
|
|
|
logic [`NE+1:0] DenormShift;
|
|
|
|
logic [`NE+1:0] NormShift;
|
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
|
|
|
|
assign ResDenorm = DivCalcExpM[`NE+1]|(~|DivCalcExpM[`NE+1:1]&~(DivCalcExpM[0]&Quot[`DIVLEN+2]));
|
|
|
|
// if the result is denormalized
|
|
|
|
// 00000000x.xxxxxx... Exp = DivCalcExp
|
|
|
|
// .00000000xxxxxxx... >> NF+1 Exp = DivCalcExp+NF+1
|
|
|
|
// .000xxxxxxxxxxxx... << DivCalcExp+NF+1 Exp = 0
|
|
|
|
// .0000xxxxxxxxxxx... >> 1 Exp = 1
|
|
|
|
// Left shift amount = DivCalcExp+NF+1-1
|
|
|
|
assign DenormShift = (`NE+2)'(`NF)+DivCalcExpM;
|
|
|
|
// if the result is denormalized
|
|
|
|
// 00000000x.xxxxxx... Exp = DivCalcExp
|
|
|
|
// .00000000xxxxxxx... >> NF+1 Exp = DivCalcExp+NF+1
|
|
|
|
// 00000000x.xxxxxx... << NF+1 Exp = DivCalcExp
|
|
|
|
// 00000000xx.xxxxx... << 1? Exp = DivCalcExp-1
|
|
|
|
// Left shift amount = NF+1 plus 1 if normalization required
|
|
|
|
assign NormShift = (`NE+2)'(`NF+1) + {(`NE+1)'(0), ~Quot[`DIVLEN+2]};
|
2022-06-27 17:04:51 +00:00
|
|
|
// if the shift amount is negitive then dont shift (keep sticky bit)
|
|
|
|
assign DivShiftAmt = ResDenorm ? DenormShift[$clog2(`NORMSHIFTSZ)-1:0]&{$clog2(`NORMSHIFTSZ){~DenormShift[`NE+1]}} : NormShift[$clog2(`NORMSHIFTSZ)-1:0];
|
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
|
|
|
// the quotent is in the range [.5,2)
|
|
|
|
// if the quotent < 1 and not denormal then subtract 1 to account for the normalization shift
|
2022-06-24 21:02:50 +00:00
|
|
|
assign CorrDivExp = (ResDenorm&~DenormShift[`NE+1]) ? (`NE+2)'(0) : DivCalcExpM - {(`NE+1)'(0), ~Quot[`DIVLEN+2]};
|
2022-06-23 23:01:30 +00:00
|
|
|
|
|
|
|
endmodule
|