2021-01-15 04:37:51 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// shifter.sv
|
|
|
|
//
|
2023-02-25 01:33:47 +00:00
|
|
|
// Written: David_Harris@hmc.edu, Sarah.Harris@unlv.edu, Kevin Kim <kekim@hmc.edu>
|
2023-01-17 14:02:26 +00:00
|
|
|
// Created: 9 January 2021
|
2023-02-06 17:55:37 +00:00
|
|
|
// Modified: 6 February 2023
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
|
|
|
// Purpose: RISC-V 32/64 bit shifter
|
|
|
|
//
|
2023-01-12 12:35:44 +00:00
|
|
|
// Documentation: RISC-V System on Chip Design Chapter 4 (Figure 4.5, Table 4.3)
|
|
|
|
//
|
2023-01-11 23:15:08 +00:00
|
|
|
// A component of the CORE-V-WALLY configurable RISC-V project.
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file
|
|
|
|
// except in compliance with the License, or, at your option, the Apache License version 2.0. You
|
|
|
|
// may obtain a copy of the License at
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// https://solderpad.org/licenses/SHL-2.1/
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, any work distributed under the
|
|
|
|
// License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
2022-01-07 12:58:40 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
`include "wally-config.vh"
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2023-03-02 19:45:32 +00:00
|
|
|
module shifter (
|
2023-03-24 13:49:26 +00:00
|
|
|
input logic [`XLEN-1:0] A, // shift Source
|
2023-02-06 17:55:37 +00:00
|
|
|
input logic [`LOG_XLEN-1:0] Amt, // Shift amount
|
2023-03-07 18:57:06 +00:00
|
|
|
input logic Right, Rotate, W64, Sign, // Shift right, rotate signals
|
2023-02-06 17:55:37 +00:00
|
|
|
output logic [`XLEN-1:0] Y); // Shifted result
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2023-02-06 17:55:37 +00:00
|
|
|
logic [2*`XLEN-2:0] z, zshift; // Input to funnel shifter, shifted amount before truncated to 32 or 64 bits
|
2023-02-25 01:33:47 +00:00
|
|
|
logic [`LOG_XLEN-1:0] amttrunc, offset; // Shift amount adjusted for RV64, right-shift amount
|
2021-12-18 18:01:12 +00:00
|
|
|
|
2023-02-25 01:33:47 +00:00
|
|
|
if (`ZBB_SUPPORTED) begin: rotfunnel
|
|
|
|
if (`XLEN==32) begin // rv32 with rotates
|
2023-02-06 17:55:37 +00:00
|
|
|
always_comb // funnel mux
|
2023-02-25 01:33:47 +00:00
|
|
|
case({Right, Rotate})
|
2023-03-24 13:49:26 +00:00
|
|
|
2'b00: z = {A[31:0], 31'b0};
|
|
|
|
2'b01: z = {A[31:0], A[31:1]};
|
|
|
|
2'b10: z = {{31{Sign}}, A[31:0]};
|
|
|
|
2'b11: z = {A[30:0], A};
|
2023-02-25 01:33:47 +00:00
|
|
|
endcase
|
2023-02-06 17:55:37 +00:00
|
|
|
assign amttrunc = Amt; // shift amount
|
2023-02-25 01:33:47 +00:00
|
|
|
end else begin // rv64 with rotates
|
2023-03-24 13:49:26 +00:00
|
|
|
// shifter rotate source select mux
|
|
|
|
logic [`XLEN-1:0] RotA; // rotate source
|
|
|
|
mux2 #(`XLEN) rotmux(A, {A[31:0], A[31:0]}, W64, RotA); // W64 rotatons
|
2023-02-06 17:55:37 +00:00
|
|
|
always_comb // funnel mux
|
2023-02-25 01:33:47 +00:00
|
|
|
case ({Right, Rotate})
|
2023-03-24 13:49:26 +00:00
|
|
|
2'b00: z = {A[63:0],{63'b0}};
|
|
|
|
2'b01: z = {RotA, RotA[63:1]};
|
|
|
|
2'b10: z = {{63{Sign}}, A[63:0]};
|
|
|
|
2'b11: z = {RotA[62:0], RotA};
|
2023-02-25 01:33:47 +00:00
|
|
|
endcase
|
2023-02-06 17:55:37 +00:00
|
|
|
assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
|
|
|
|
end
|
2023-02-25 01:33:47 +00:00
|
|
|
end else begin: norotfunnel
|
2023-02-06 17:55:37 +00:00
|
|
|
if (`XLEN==32) begin:shifter // RV32
|
|
|
|
always_comb // funnel mux
|
2023-03-24 13:49:26 +00:00
|
|
|
if (Right) z = {{31{Sign}}, A[31:0]};
|
|
|
|
else z = {A[31:0], 31'b0};
|
2023-02-06 17:55:37 +00:00
|
|
|
assign amttrunc = Amt; // shift amount
|
|
|
|
end else begin:shifter // RV64
|
|
|
|
always_comb // funnel mux
|
2023-03-24 13:49:26 +00:00
|
|
|
if (Right) z = {{63{Sign}}, A[63:0]};
|
|
|
|
else z = {A[63:0], {63'b0}};
|
2023-02-06 17:55:37 +00:00
|
|
|
assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
|
|
|
|
end
|
|
|
|
end
|
2023-02-25 01:33:47 +00:00
|
|
|
|
2023-01-17 14:02:26 +00:00
|
|
|
// Opposite offset for right shifts
|
2021-12-18 18:25:40 +00:00
|
|
|
assign offset = Right ? amttrunc : ~amttrunc;
|
2021-12-18 18:01:12 +00:00
|
|
|
|
2023-01-17 14:02:26 +00:00
|
|
|
// Funnel operation
|
2023-02-25 01:33:47 +00:00
|
|
|
assign zshift = z >> offset;
|
2021-12-18 18:25:40 +00:00
|
|
|
assign Y = zshift[`XLEN-1:0];
|
2021-01-15 04:37:51 +00:00
|
|
|
endmodule
|
|
|
|
|
|
|
|
|