mirror of
				https://github.com/openhwgroup/cvw
				synced 2025-02-11 06:05:49 +00:00 
			
		
		
		
	removed old shifter
This commit is contained in:
		
							parent
							
								
									9d119d1312
								
							
						
					
					
						commit
						c7050ada78
					
				@ -85,7 +85,7 @@ module alu #(parameter WIDTH=32) (
 | 
				
			|||||||
    // Pre-Shift Mux
 | 
					    // Pre-Shift Mux
 | 
				
			||||||
    always_comb
 | 
					    always_comb
 | 
				
			||||||
      case (Funct3[2:1] & {2{BSelect[3]}})
 | 
					      case (Funct3[2:1] & {2{BSelect[3]}})
 | 
				
			||||||
        2'b00: CondShiftA = shA[63:0];
 | 
					        2'b00: CondShiftA = shA[WIDTH-1:0];
 | 
				
			||||||
        2'b01: CondShiftA = {shA[WIDTH-2:0],{1'b0}};   // sh1add
 | 
					        2'b01: CondShiftA = {shA[WIDTH-2:0],{1'b0}};   // sh1add
 | 
				
			||||||
        2'b10: CondShiftA = {shA[WIDTH-3:0],{2'b00}};  // sh2add
 | 
					        2'b10: CondShiftA = {shA[WIDTH-3:0],{2'b00}};  // sh2add
 | 
				
			||||||
        2'b11: CondShiftA = {shA[WIDTH-4:0],{3'b000}}; // sh3add
 | 
					        2'b11: CondShiftA = {shA[WIDTH-4:0],{3'b000}}; // sh3add
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
///////////////////////////////////////////
 | 
					///////////////////////////////////////////
 | 
				
			||||||
// shifter.sv
 | 
					// shifter.sv
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Written: David_Harris@hmc.edu, Sarah.Harris@unlv.edu, kekim@hmc.edu
 | 
					// Written: David_Harris@hmc.edu, Sarah.Harris@unlv.edu, Kevin Kim <kekim@hmc.edu>
 | 
				
			||||||
// Created: 9 January 2021
 | 
					// Created: 9 January 2021
 | 
				
			||||||
// Modified: 6 February 2023
 | 
					// Modified: 6 February 2023
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
@ -29,111 +29,56 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
`include "wally-config.vh"
 | 
					`include "wally-config.vh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module shifter (
 | 
					module shifternew (
 | 
				
			||||||
  input  logic [`XLEN-1:0]     A,                           // Source
 | 
					  input  logic [`XLEN:0]     shA,                           // shift Source
 | 
				
			||||||
 | 
					  input  logic [`XLEN-1:0]   rotA,                          // rotate source
 | 
				
			||||||
  input  logic [`LOG_XLEN-1:0] Amt,                         // Shift amount
 | 
					  input  logic [`LOG_XLEN-1:0] Amt,                         // Shift amount
 | 
				
			||||||
  input  logic                 Right, Arith, W64, Rotate,   // Shift right, arithmetic, RV64 W-type shift
 | 
					  input  logic                 Right, Rotate, W64,          // Shift right, rotate signals
 | 
				
			||||||
  output logic [`XLEN-1:0]     Y);                          // Shifted result
 | 
					  output logic [`XLEN-1:0]     Y);                          // Shifted result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logic [2*`XLEN-2:0]      z, zshift;                       // Input to funnel shifter, shifted amount before truncated to 32 or 64 bits
 | 
					  logic [2*`XLEN-2:0]      z, zshift;                       // Input to funnel shifter, shifted amount before truncated to 32 or 64 bits
 | 
				
			||||||
  logic [`LOG_XLEN-1:0]    amttrunc, offset, CondOffsetTrunc;                // Shift amount adjusted for RV64, right-shift amount
 | 
					  logic [`LOG_XLEN-1:0]    amttrunc, offset;                // Shift amount adjusted for RV64, right-shift amount
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Handle left and right shifts with a funnel shifter.
 | 
					
 | 
				
			||||||
  // For RV32, only 32-bit shifts are needed.   
 | 
					  if (`ZBB_SUPPORTED) begin: rotfunnel
 | 
				
			||||||
  // For RV64, 32- and 64-bit shifts are needed, with sign extension.
 | 
					    if (`XLEN==32) begin // rv32 with rotates
 | 
				
			||||||
  /*
 | 
					 | 
				
			||||||
  // Funnel shifter input (see CMOS VLSI Design 4e Section 11.8.1, note Table 11.11 shift types wrong)
 | 
					 | 
				
			||||||
  if (`XLEN==32) begin:shifter // RV32
 | 
					 | 
				
			||||||
      always_comb  // funnel mux
 | 
					      always_comb  // funnel mux
 | 
				
			||||||
      if (Right) 
 | 
					        case({Right, Rotate})
 | 
				
			||||||
        if (Arith) z = {{31{A[31]}}, A};
 | 
					          2'b00: z = {shA[31:0], 31'b0};
 | 
				
			||||||
        else       z = {31'b0, A};
 | 
					          2'b01: z = {rotA,rotA[31:1]};
 | 
				
			||||||
      else         z = {A, 31'b0};
 | 
					          2'b10: z = {{31{shA[32]}}, shA[31:0]};
 | 
				
			||||||
 | 
					          2'b11: z = {rotA[30:0],rotA};
 | 
				
			||||||
 | 
					        endcase
 | 
				
			||||||
      assign amttrunc = Amt; // shift amount
 | 
					      assign amttrunc = Amt; // shift amount
 | 
				
			||||||
  end else begin:shifter  // RV64
 | 
					    end else begin // rv64 with rotates
 | 
				
			||||||
      always_comb  // funnel mux
 | 
					      always_comb  // funnel mux
 | 
				
			||||||
      if (W64) begin // 32-bit shifts
 | 
					        case ({Right, Rotate})
 | 
				
			||||||
        if (Right)
 | 
					          2'b00: z = {shA[63:0],{63'b0}};
 | 
				
			||||||
          if (Arith) z = {64'b0, {31{A[31]}}, A[31:0]};
 | 
					          2'b01: z = {rotA, rotA[63:1]};
 | 
				
			||||||
          else       z = {95'b0, A[31:0]};
 | 
					          2'b10: z = {{63{shA[64]}},shA[63:0]};
 | 
				
			||||||
        else         z = {32'b0, A[31:0], 63'b0};
 | 
					          2'b11: z = {rotA[62:0],rotA[63:0]};
 | 
				
			||||||
      end else begin
 | 
					        endcase
 | 
				
			||||||
        if (Right)
 | 
					 | 
				
			||||||
          if (Arith) z = {{63{A[63]}}, A};
 | 
					 | 
				
			||||||
          else       z = {63'b0, A};
 | 
					 | 
				
			||||||
        else         z = {A, 63'b0};         
 | 
					 | 
				
			||||||
      end
 | 
					 | 
				
			||||||
      assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
 | 
					      assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  */
 | 
					  end else begin: norotfunnel
 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (`ZBB_SUPPORTED) begin: rotFunnel // HANDLES ROTATE
 | 
					 | 
				
			||||||
    if (`XLEN==32) begin:shifter // RV32
 | 
					    if (`XLEN==32) begin:shifter // RV32
 | 
				
			||||||
      always_comb  // funnel mux
 | 
					      always_comb  // funnel mux
 | 
				
			||||||
        if (Right) 
 | 
					        if (Right)  z = {{31{shA[32]}}, shA[31:0]};
 | 
				
			||||||
          if (Rotate)  z = {A[30:0], A[31:0]};                        //ror (rv32)
 | 
					        else        z = {shA[31:0], 31'b0};
 | 
				
			||||||
          else
 | 
					 | 
				
			||||||
            if (Arith) z = {{31{A[31]}}, A};
 | 
					 | 
				
			||||||
            else       z = {31'b0, A};
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
          if (Rotate)  z = {A[31:0], A[31:1]};                         //rol (rv32)
 | 
					 | 
				
			||||||
          else         z = {A, 31'b0};
 | 
					 | 
				
			||||||
      assign amttrunc = Amt; // shift amount
 | 
					      assign amttrunc = Amt; // shift amount
 | 
				
			||||||
    end else begin:shifter  // RV64
 | 
					    end else begin:shifter  // RV64
 | 
				
			||||||
      always_comb  // funnel mux
 | 
					      always_comb  // funnel mux
 | 
				
			||||||
        if (W64) begin // 32-bit shifts
 | 
					        if (Right)  z = {{63{shA[64]}},shA[63:0]};
 | 
				
			||||||
          if (Right)
 | 
					        else        z = {shA[63:0],{63'b0}};
 | 
				
			||||||
            if (Rotate)  z = {{64'b0},A[30:0],A[31:0]}; //rorw
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
              if (Arith) z = {64'b0, {31{A[31]}}, A[31:0]};
 | 
					 | 
				
			||||||
              else       z = {95'b0, A[31:0]};
 | 
					 | 
				
			||||||
          else         
 | 
					 | 
				
			||||||
            if (Rotate)  z = {{64'b0},A[31:0],A[31:1]}; //rolw
 | 
					 | 
				
			||||||
            else         z = {32'b0, A[31:0], 63'b0};
 | 
					 | 
				
			||||||
        end else begin
 | 
					 | 
				
			||||||
          if (Right)
 | 
					 | 
				
			||||||
            if (Rotate)  z = {A[62:0], A[63:0]};        //ror
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
              if (Arith) z = {{63{A[63]}}, A};
 | 
					 | 
				
			||||||
              else       z = {63'b0, A};
 | 
					 | 
				
			||||||
          else
 | 
					 | 
				
			||||||
            if (Rotate)  z = {A[63:0], A[63:1]};        //rol
 | 
					 | 
				
			||||||
            else         z = {A, 63'b0};         
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
      assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end else begin: norotFunnel
 | 
					 | 
				
			||||||
    if (`XLEN==32) begin:shifter // RV32
 | 
					 | 
				
			||||||
      always_comb  // funnel mux
 | 
					 | 
				
			||||||
        if (Right) 
 | 
					 | 
				
			||||||
          if (Arith) z = {{31{A[31]}}, A};
 | 
					 | 
				
			||||||
          else       z = {31'b0, A};
 | 
					 | 
				
			||||||
        else         z = {A, 31'b0};
 | 
					 | 
				
			||||||
      assign amttrunc = Amt; // shift amount
 | 
					 | 
				
			||||||
    end else begin:shifter  // RV64
 | 
					 | 
				
			||||||
      always_comb  // funnel mux
 | 
					 | 
				
			||||||
        if (W64) begin // 32-bit shifts
 | 
					 | 
				
			||||||
          if (Right)
 | 
					 | 
				
			||||||
            if (Arith) z = {64'b0, {31{A[31]}}, A[31:0]};
 | 
					 | 
				
			||||||
            else       z = {95'b0, A[31:0]};
 | 
					 | 
				
			||||||
          else         z = {32'b0, A[31:0], 63'b0};
 | 
					 | 
				
			||||||
        end else begin
 | 
					 | 
				
			||||||
          if (Right)
 | 
					 | 
				
			||||||
            if (Arith) z = {{63{A[63]}}, A};
 | 
					 | 
				
			||||||
            else       z = {63'b0, A};
 | 
					 | 
				
			||||||
          else         z = {A, 63'b0};         
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
      assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
 | 
					      assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // Opposite offset for right shifts
 | 
					  // Opposite offset for right shifts
 | 
				
			||||||
  assign offset = Right ? amttrunc : ~amttrunc;
 | 
					  assign offset = Right ? amttrunc : ~amttrunc;
 | 
				
			||||||
  if (`XLEN == 64) assign CondOffsetTrunc = (W64 & Rotate) ? {{1'b0}, offset[4:0]} : offset;
 | 
					 | 
				
			||||||
  else assign CondOffsetTrunc = offset;
 | 
					 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // Funnel operation
 | 
					  // Funnel operation
 | 
				
			||||||
  assign zshift = z >> CondOffsetTrunc;
 | 
					  assign zshift = z >> offset;
 | 
				
			||||||
  assign Y = zshift[`XLEN-1:0];    
 | 
					  assign Y = zshift[`XLEN-1:0];    
 | 
				
			||||||
endmodule
 | 
					endmodule
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,85 +0,0 @@
 | 
				
			|||||||
///////////////////////////////////////////
 | 
					 | 
				
			||||||
// shifter.sv
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// Written: David_Harris@hmc.edu, Sarah.Harris@unlv.edu, kekim@hmc.edu
 | 
					 | 
				
			||||||
// Created: 9 January 2021
 | 
					 | 
				
			||||||
// Modified: 6 February 2023
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// Purpose: RISC-V 32/64 bit shifter
 | 
					 | 
				
			||||||
// 
 | 
					 | 
				
			||||||
// Documentation: RISC-V System on Chip Design Chapter 4 (Figure 4.5, Table 4.3)
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// A component of the CORE-V-WALLY configurable RISC-V project.
 | 
					 | 
				
			||||||
// 
 | 
					 | 
				
			||||||
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 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
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 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.
 | 
					 | 
				
			||||||
////////////////////////////////////////////////////////////////////////////////////////////////
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
`include "wally-config.vh"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module shifternew (
 | 
					 | 
				
			||||||
  input  logic [`XLEN:0]     shA,                           // shift Source
 | 
					 | 
				
			||||||
  input  logic [`XLEN-1:0]   rotA,                          // rotate source
 | 
					 | 
				
			||||||
  input  logic [`LOG_XLEN-1:0] Amt,                         // Shift amount
 | 
					 | 
				
			||||||
  input  logic                 Right, Rotate, W64,          // Shift right, rotate signals
 | 
					 | 
				
			||||||
  output logic [`XLEN-1:0]     Y);                          // Shifted result
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  logic [2*`XLEN-2:0]      z, zshift;                       // Input to funnel shifter, shifted amount before truncated to 32 or 64 bits
 | 
					 | 
				
			||||||
  logic [`LOG_XLEN-1:0]    amttrunc, offset;                // Shift amount adjusted for RV64, right-shift amount
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (`ZBB_SUPPORTED) begin: rotfunnel
 | 
					 | 
				
			||||||
    if (`XLEN==32) begin // rv32 with rotates
 | 
					 | 
				
			||||||
      always_comb  // funnel mux
 | 
					 | 
				
			||||||
        case({Right, Rotate})
 | 
					 | 
				
			||||||
          2'b00: z = {shA[31:0], 31'b0};
 | 
					 | 
				
			||||||
          2'b01: z = {rotA,rotA[31:1]};
 | 
					 | 
				
			||||||
          2'b10: z = {{31{shA[32]}}, shA[31:0]};
 | 
					 | 
				
			||||||
          2'b11: z = {rotA[30:0],rotA};
 | 
					 | 
				
			||||||
        endcase
 | 
					 | 
				
			||||||
      assign amttrunc = Amt; // shift amount
 | 
					 | 
				
			||||||
    end else begin // rv64 with rotates
 | 
					 | 
				
			||||||
      always_comb  // funnel mux
 | 
					 | 
				
			||||||
        case ({Right, Rotate})
 | 
					 | 
				
			||||||
          2'b00: z = {shA[63:0],{63'b0}};
 | 
					 | 
				
			||||||
          2'b01: z = {rotA, rotA[63:1]};
 | 
					 | 
				
			||||||
          2'b10: z = {{63{shA[64]}},shA[63:0]};
 | 
					 | 
				
			||||||
          2'b11: z = {rotA[62:0],rotA[63:0]};
 | 
					 | 
				
			||||||
        endcase
 | 
					 | 
				
			||||||
      assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end else begin: norotfunnel
 | 
					 | 
				
			||||||
    if (`XLEN==32) begin:shifter // RV32
 | 
					 | 
				
			||||||
      always_comb  // funnel mux
 | 
					 | 
				
			||||||
        if (Right)  z = {{31{shA[32]}}, shA[31:0]};
 | 
					 | 
				
			||||||
        else        z = {shA[31:0], 31'b0};
 | 
					 | 
				
			||||||
      assign amttrunc = Amt; // shift amount
 | 
					 | 
				
			||||||
    end else begin:shifter  // RV64
 | 
					 | 
				
			||||||
      always_comb  // funnel mux
 | 
					 | 
				
			||||||
        if (Right)  z = {{63{shA[64]}},shA[63:0]};
 | 
					 | 
				
			||||||
        else        z = {shA[63:0],{63'b0}};
 | 
					 | 
				
			||||||
      assign amttrunc = W64 ? {1'b0, Amt[4:0]} : Amt; // 32- or 64-bit shift
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // Opposite offset for right shifts
 | 
					 | 
				
			||||||
  assign offset = Right ? amttrunc : ~amttrunc;
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // Funnel operation
 | 
					 | 
				
			||||||
  assign zshift = z >> offset;
 | 
					 | 
				
			||||||
  assign Y = zshift[`XLEN-1:0];    
 | 
					 | 
				
			||||||
endmodule
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user