forked from Github_Repos/cvw
Implemented on-the-fly conversion for unsigned numbers
This commit is contained in:
parent
19a759d405
commit
3301d7c52a
@ -85,14 +85,14 @@ module srt #(parameter Nf=52) (
|
|||||||
|
|
||||||
// Partial Product Generation
|
// Partial Product Generation
|
||||||
csa csa(WS, WC, Dsel, qp, WSA, WCA);
|
csa csa(WS, WC, Dsel, qp, WSA, WCA);
|
||||||
|
|
||||||
|
otfc2 otfc2(clk, Start, qp, qz, qm, QuotOTFC);
|
||||||
|
|
||||||
expcalc expcalc(.XExp, .YExp, .calcExp);
|
expcalc expcalc(.XExp, .YExp, .calcExp);
|
||||||
|
|
||||||
signcalc signcalc(.XSign, .YSign, .calcSign);
|
signcalc signcalc(.XSign, .YSign, .calcSign);
|
||||||
|
|
||||||
srtpostproc postproc(rp, rm, Quot);
|
srtpostproc postproc(rp, rm, Quot);
|
||||||
|
|
||||||
otfc otfc(qp, qz, qm, Quot, QuotOTFC);
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
module srtpostproc #(parameter N=52) (
|
module srtpostproc #(parameter N=52) (
|
||||||
@ -216,13 +216,46 @@ endmodule
|
|||||||
// otfc //
|
// otfc //
|
||||||
//////////
|
//////////
|
||||||
|
|
||||||
module otfc #(parameter N=52) (
|
module otfc2 #(parameter N=52) (
|
||||||
|
input logic clk,
|
||||||
|
input logic Start,
|
||||||
input logic qp, qz, qm,
|
input logic qp, qz, qm,
|
||||||
input logic [N-1:0] Quot,
|
output logic [N-1:0] r
|
||||||
output logic [N-1:0] QuotOTFC
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assign QuotOTFC = Quot;
|
// The on-the-fly converter transfers the quotient
|
||||||
|
// bits to the quotient as they come.
|
||||||
|
//
|
||||||
|
// This code follows the psuedocode presented in the
|
||||||
|
// floating point chapter of the book. Right now,
|
||||||
|
// it is written for Radix-2 division.
|
||||||
|
//
|
||||||
|
// QM is Q-1. It allows us to write negative bits
|
||||||
|
// without using a costly CPA.
|
||||||
|
logic [N+2:0] Q, QM, QNext, QMNext;
|
||||||
|
// QR and QMR are the shifted versions of Q and QM.
|
||||||
|
// They are treated as [N-1:r] size signals, and
|
||||||
|
// discard the r most significant bits of Q and QM.
|
||||||
|
logic [N+1:0] QR, QMR;
|
||||||
|
|
||||||
|
flopr #(N+3) Qreg(clk, Start, QNext, Q);
|
||||||
|
flopr #(N+3) QMreg(clk, Start, QMNext, QM);
|
||||||
|
|
||||||
|
always_comb begin
|
||||||
|
QR = Q[N+1:0];
|
||||||
|
QMR = QM[N+1:0]; // Shift Q and QM
|
||||||
|
if (qp) begin
|
||||||
|
QNext = {QR, 1'b1};
|
||||||
|
QMNext = {QR, 1'b0};
|
||||||
|
end else if (qz) begin
|
||||||
|
QNext = {QR, 1'b0};
|
||||||
|
QMNext = {QMR, 1'b1};
|
||||||
|
end else begin // If qp and qz are not true, then qm is
|
||||||
|
QNext = {QMR, 1'b1};
|
||||||
|
QMNext = {QMR, 1'b0};
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assign r = Q[54] ? Q[53:2] : Q[52:1];
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ module testbench;
|
|||||||
begin
|
begin
|
||||||
errors = errors+1;
|
errors = errors+1;
|
||||||
$display("OTFC is %h, should be %h\n", rOTFC, r);
|
$display("OTFC is %h, should be %h\n", rOTFC, r);
|
||||||
$display("failed/n");
|
$display("failed\n");
|
||||||
$stop;
|
// $stop;
|
||||||
end
|
end
|
||||||
if (afrac === 52'hxxxxxxxxxxxxx)
|
if (afrac === 52'hxxxxxxxxxxxxx)
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user