1.1 diff -r 252df75c8f67 -r c336e674a37e lm32_shifter.v 1.2 --- a/lm32_shifter.v Sun Mar 06 21:17:31 2011 +0000 1.3 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.4 @@ -1,134 +0,0 @@ 1.5 -// ============================================================================= 1.6 -// COPYRIGHT NOTICE 1.7 -// Copyright 2006 (c) Lattice Semiconductor Corporation 1.8 -// ALL RIGHTS RESERVED 1.9 -// This confidential and proprietary software may be used only as authorised by 1.10 -// a licensing agreement from Lattice Semiconductor Corporation. 1.11 -// The entire notice above must be reproduced on all authorized copies and 1.12 -// copies may only be made to the extent permitted by a licensing agreement from 1.13 -// Lattice Semiconductor Corporation. 1.14 -// 1.15 -// Lattice Semiconductor Corporation TEL : 1-800-Lattice (USA and Canada) 1.16 -// 5555 NE Moore Court 408-826-6000 (other locations) 1.17 -// Hillsboro, OR 97124 web : http://www.latticesemi.com/ 1.18 -// U.S.A email: techsupport@latticesemi.com 1.19 -// =============================================================================/ 1.20 -// FILE DETAILS 1.21 -// Project : LatticeMico32 1.22 -// File : lm32_shifter.v 1.23 -// Title : Barrel shifter 1.24 -// Dependencies : lm32_include.v 1.25 -// Version : 6.1.17 1.26 -// : Initial Release 1.27 -// Version : 7.0SP2, 3.0 1.28 -// : No Change 1.29 -// Version : 3.1 1.30 -// : No Change 1.31 -// ============================================================================= 1.32 - 1.33 -`include "lm32_include.v" 1.34 - 1.35 -///////////////////////////////////////////////////// 1.36 -// Module interface 1.37 -///////////////////////////////////////////////////// 1.38 - 1.39 -module lm32_shifter ( 1.40 - // ----- Inputs ------- 1.41 - clk_i, 1.42 - rst_i, 1.43 - stall_x, 1.44 - direction_x, 1.45 - sign_extend_x, 1.46 - operand_0_x, 1.47 - operand_1_x, 1.48 - // ----- Outputs ------- 1.49 - shifter_result_m 1.50 - ); 1.51 - 1.52 -///////////////////////////////////////////////////// 1.53 -// Inputs 1.54 -///////////////////////////////////////////////////// 1.55 - 1.56 -input clk_i; // Clock 1.57 -input rst_i; // Reset 1.58 -input stall_x; // Stall instruction in X stage 1.59 -input direction_x; // Direction to shift 1.60 -input sign_extend_x; // Whether shift is arithmetic (1'b1) or logical (1'b0) 1.61 -input [`LM32_WORD_RNG] operand_0_x; // Operand to shift 1.62 -input [`LM32_WORD_RNG] operand_1_x; // Operand that specifies how many bits to shift by 1.63 - 1.64 -///////////////////////////////////////////////////// 1.65 -// Outputs 1.66 -///////////////////////////////////////////////////// 1.67 - 1.68 -output [`LM32_WORD_RNG] shifter_result_m; // Result of shift 1.69 -wire [`LM32_WORD_RNG] shifter_result_m; 1.70 - 1.71 -///////////////////////////////////////////////////// 1.72 -// Internal nets and registers 1.73 -///////////////////////////////////////////////////// 1.74 - 1.75 -reg direction_m; 1.76 -reg [`LM32_WORD_RNG] left_shift_result; 1.77 -reg [`LM32_WORD_RNG] right_shift_result; 1.78 -reg [`LM32_WORD_RNG] left_shift_operand; 1.79 -wire [`LM32_WORD_RNG] right_shift_operand; 1.80 -wire fill_value; 1.81 -wire [`LM32_WORD_RNG] right_shift_in; 1.82 - 1.83 -integer shift_idx_0; 1.84 -integer shift_idx_1; 1.85 - 1.86 -///////////////////////////////////////////////////// 1.87 -// Combinational Logic 1.88 -///////////////////////////////////////////////////// 1.89 - 1.90 -// Select operands - To perform a left shift, we reverse the bits and perform a right shift 1.91 -always @(*) 1.92 -begin 1.93 - for (shift_idx_0 = 0; shift_idx_0 < `LM32_WORD_WIDTH; shift_idx_0 = shift_idx_0 + 1) 1.94 - left_shift_operand[`LM32_WORD_WIDTH-1-shift_idx_0] = operand_0_x[shift_idx_0]; 1.95 -end 1.96 -assign right_shift_operand = direction_x == `LM32_SHIFT_OP_LEFT ? left_shift_operand : operand_0_x; 1.97 - 1.98 -// Determine fill value for right shift - Sign bit for arithmetic shift, or zero for logical shift 1.99 -assign fill_value = (sign_extend_x == `TRUE) && (direction_x == `LM32_SHIFT_OP_RIGHT) 1.100 - ? operand_0_x[`LM32_WORD_WIDTH-1] 1.101 - : 1'b0; 1.102 - 1.103 -// Determine bits to shift in for right shift or rotate 1.104 -assign right_shift_in = {`LM32_WORD_WIDTH{fill_value}}; 1.105 - 1.106 -// Reverse bits to get left shift result 1.107 -always @(*) 1.108 -begin 1.109 - for (shift_idx_1 = 0; shift_idx_1 < `LM32_WORD_WIDTH; shift_idx_1 = shift_idx_1 + 1) 1.110 - left_shift_result[`LM32_WORD_WIDTH-1-shift_idx_1] = right_shift_result[shift_idx_1]; 1.111 -end 1.112 - 1.113 -// Select result 1.114 -assign shifter_result_m = direction_m == `LM32_SHIFT_OP_LEFT ? left_shift_result : right_shift_result; 1.115 - 1.116 -///////////////////////////////////////////////////// 1.117 -// Sequential Logic 1.118 -///////////////////////////////////////////////////// 1.119 - 1.120 -// Perform right shift 1.121 -always @(posedge clk_i `CFG_RESET_SENSITIVITY) 1.122 -begin 1.123 - if (rst_i == `TRUE) 1.124 - begin 1.125 - right_shift_result <= {`LM32_WORD_WIDTH{1'b0}}; 1.126 - direction_m <= `FALSE; 1.127 - end 1.128 - else 1.129 - begin 1.130 - if (stall_x == `FALSE) 1.131 - begin 1.132 - right_shift_result <= {right_shift_in, right_shift_operand} >> operand_1_x[`LM32_SHIFT_RNG]; 1.133 - direction_m <= direction_x; 1.134 - end 1.135 - end 1.136 -end 1.137 - 1.138 -endmodule