Factored out common parts of shifter

This commit is contained in:
David Harris 2021-12-18 10:01:12 -08:00
parent 53baf3e787
commit eed2765033

View File

@ -31,40 +31,28 @@ module shifter (
input logic right, arith, w64, input logic right, arith, w64,
output logic [`XLEN-1:0] y); output logic [`XLEN-1:0] y);
localparam BITS = $clog2(`XLEN);
logic [2*`XLEN-2:0] z, zshift;
logic [BITS-1:0] amttrunc, offset;
// The best shifter architecture differs based on `XLEN. // The best shifter architecture differs based on `XLEN.
// for RV32, only 32-bit shifts are needed. These are // for RV32, only 32-bit shifts are needed. These are
// most efficiently implemented with a funnel shifter. // most efficiently implemented with a funnel shifter.
// For RV64, 32 and 64-bit shifts are needed, with sign // For RV64, 32 and 64-bit shifts are needed, with sign
// extension. // extension.
// funnel shifter input (see CMOS VLSI Design 4e Section 11.8.1, note Table 11.11 shift types wrong)
generate generate
if (`XLEN==32) begin:shifter if (`XLEN==32) begin:shifter // RV32
// funnel shifter (see CMOS VLSI Design 4e Section 11.8.1, note Table 11.11 shift types wrong) always_comb // funnel mux
logic [62:0] z, zshift;
logic [4:0] offset;
// funnel input
always_comb
if (right) if (right)
if (arith) z = {{31{a[31]}}, a}; if (arith) z = {{31{a[31]}}, a};
else z = {31'b0, a}; else z = {31'b0, a};
else z = {a, 31'b0}; else z = {a, 31'b0};
assign amttrunc = amt[4:0]; // shift amount
// shift amount
assign offset = right ? amt[4:0] : ~amt[4:0];
// funnel operation
assign zshift = z >> offset;
assign y = zshift[31:0];
end else begin:shifter // RV64 end else begin:shifter // RV64
// funnel shifter followed by masking always_comb // funnel mux
// research idea: investigate shifter designs for mixed 32/64-bit shifts
logic [126:0] z, zshift;
logic [31:0] ylower, yupper;
logic [5:0] offset, amt6;
// funnel input
always_comb
if (w64) begin // 32-bit shifts if (w64) begin // 32-bit shifts
if (right) if (right)
if (arith) z = {64'b0, {31{a[31]}}, a[31:0]}; if (arith) z = {64'b0, {31{a[31]}}, a[31:0]};
@ -76,16 +64,16 @@ module shifter (
else z = {63'b0, a}; else z = {63'b0, a};
else z = {a, 63'b0}; else z = {a, 63'b0};
end end
assign amttrunc = w64 ? {1'b0, amt[4:0]} : amt[5:0]; // 32 or 64-bit shift
// shift amount
assign amt6 = w64 ? {1'b0, amt[4:0]} : amt[5:0]; // 32 or 64-bit shift
assign offset = right ? amt6 : ~amt6;
// funnel operation
assign zshift = z >> offset;
assign y = zshift[63:0];
end end
endgenerate endgenerate
// opposite offset for right shfits
assign offset = right ? amttrunc : ~amttrunc;
// funnel operation
assign zshift = z >> offset;
assign y = zshift[`XLEN-1:0];
endmodule endmodule