upsilon/firmware/rtl/control_loop/mul_const.v

66 lines
1.4 KiB
Coq
Raw Normal View History

2022-10-28 17:31:23 -04:00
module mul_const #(
parameter CONSTS_WHOLE = 8,
parameter CONSTS_FRAC = 40,
2022-11-11 21:57:58 -05:00
`define CONSTS_WID (CONSTS_WHOLE + CONSTS_FRAC)
2022-10-28 17:31:23 -04:00
parameter IN_WHOLE = CONSTS_WHOLE,
parameter IN_FRAC = CONSTS_FRAC,
2022-11-11 21:57:58 -05:00
`define IN_WID (IN_WHOLE + IN_FRAC)
parameter OUT_WHOLE = 20,
parameter OUT_FRAC = 40
`define OUT_WID (OUT_WHOLE + OUT_FRAC)
2022-10-28 17:31:23 -04:00
) (
input clk,
2022-11-11 21:57:58 -05:00
input signed [`IN_WID-1:0] inp,
input signed [`CONSTS_WID-1:0] const_in,
2022-10-28 17:31:23 -04:00
input arm,
2022-11-11 21:57:58 -05:00
output signed [`OUT_WID-1:0] outp,
2022-10-28 17:31:23 -04:00
output finished
);
2022-11-11 21:57:58 -05:00
`define UNSAT_WID (`CONSTS_WID + `IN_WID)
wire signed [`UNSAT_WID-1:0] unsat;
2022-10-28 17:31:23 -04:00
boothmul #(
2022-11-11 21:57:58 -05:00
.A1_LEN(`CONSTS_WID),
.A2_LEN(`IN_WID)
2022-10-28 17:31:23 -04:00
) mul (
.clk(clk),
.arm(arm),
.a1(const_in),
.a2(inp),
.outn(unsat),
.fin(finished)
);
2022-11-11 21:57:58 -05:00
`define RIGHTTRUNC_WID (CONSTS_WHOLE + IN_WHOLE + OUT_FRAC)
`define UNSAT_FRAC (CONSTS_FRAC + IN_FRAC)
wire signed [`RIGHTTRUNC_WID-1:0] rtrunc =
unsat[`UNSAT_WID-1:(`UNSAT_FRAC - OUT_FRAC)];
2022-10-28 17:31:23 -04:00
2022-11-11 21:57:58 -05:00
generate if (OUT_WHOLE < CONSTS_WHOLE + IN_WHOLE) begin
2022-10-28 17:31:23 -04:00
intsat #(
2022-11-11 21:57:58 -05:00
.IN_LEN(`RIGHTTRUNC_WID),
.LTRUNC(CONSTS_WHOLE + IN_WHOLE - OUT_WHOLE)
2022-10-28 17:31:23 -04:00
) sat (
.inp(rtrunc),
.outp(outp)
);
2022-11-11 21:57:58 -05:00
end else if (OUT_WHOLE == CONSTS_WHOLE + IN_WHOLE) begin
2022-10-28 17:31:23 -04:00
assign outp = rtrunc;
2022-11-11 21:57:58 -05:00
end else begin
assign outp[`RIGHTTRUNC_WID-1:0] = rtrunc;
assign outp[`OUT_WID-1:`RIGHTTRUNC_WID] = {
(`OUT_WID-`RIGHTTRUNC_WID){rtrunc[`RIGHTTRUNC_WID-1]}
};
2022-10-28 17:31:23 -04:00
end endgenerate
`ifdef VERILATOR
initial begin
$dumpfile("mul_const.fst");
$dumpvars();
end
`endif
endmodule