summaryrefslogtreecommitdiff
path: root/shifter.v
diff options
context:
space:
mode:
Diffstat (limited to 'shifter.v')
-rw-r--r--shifter.v52
1 files changed, 10 insertions, 42 deletions
diff --git a/shifter.v b/shifter.v
index 01fa40c..ed4eaa6 100644
--- a/shifter.v
+++ b/shifter.v
@@ -7,50 +7,18 @@ module shifter (
);
wire [31:0] x;
+ wire [15:0] extension;
+ wire [31:0] xshift;
- assign x = {
- v,
+ assign extension =
+ extend == 2'b11 ? v :
+ extend == 2'b10 ? {16{v[dir == 1'b0 ? 0 : 15]}} :
+ {16{extend[0]}};
- extend == 2'b00 ? 16'h0 :
- extend == 2'b01 ? 16'hFFFF :
- extend == 2'b10 ? {16{v[dir == 1'b0 ? 0 : 15]}} : v
- };
-
- wire [4:0] dirAndAmount;
- assign dirAndAmount = {dir, by[3:0]};
+ assign x = dir == 1'b0 ? {v, extension} : {extension, v};
+ assign xshift = dir == 1'b0 ? x << by[3:0] : x >> by[3:0];
assign result =
- |(by[15:4]) ? x[15:0] :
- dirAndAmount == 5'h1F ? {x[14:0], x[31 ]} :
- dirAndAmount == 5'h1E ? {x[13:0], x[31:30]} :
- dirAndAmount == 5'h1D ? {x[12:0], x[31:29]} :
- dirAndAmount == 5'h1C ? {x[11:0], x[31:28]} :
- dirAndAmount == 5'h1B ? {x[10:0], x[31:27]} :
- dirAndAmount == 5'h1A ? {x[ 9:0], x[31:26]} :
- dirAndAmount == 5'h19 ? {x[ 8:0], x[31:25]} :
- dirAndAmount == 5'h18 ? {x[ 7:0], x[31:24]} :
- dirAndAmount == 5'h17 ? {x[ 6:0], x[31:23]} :
- dirAndAmount == 5'h16 ? {x[ 5:0], x[31:22]} :
- dirAndAmount == 5'h15 ? {x[ 4:0], x[31:21]} :
- dirAndAmount == 5'h14 ? {x[ 3:0], x[31:20]} :
- dirAndAmount == 5'h13 ? {x[ 2:0], x[31:19]} :
- dirAndAmount == 5'h12 ? {x[ 1:0], x[31:18]} :
- dirAndAmount == 5'h11 ? {x[ 0], x[31:17]} :
- // zero shift is handled at the bottom
- dirAndAmount == 5'h01 ? x[30:15] :
- dirAndAmount == 5'h02 ? x[29:14] :
- dirAndAmount == 5'h03 ? x[28:13] :
- dirAndAmount == 5'h04 ? x[27:12] :
- dirAndAmount == 5'h05 ? x[26:11] :
- dirAndAmount == 5'h06 ? x[25:10] :
- dirAndAmount == 5'h07 ? x[24: 9] :
- dirAndAmount == 5'h08 ? x[23: 8] :
- dirAndAmount == 5'h09 ? x[22: 7] :
- dirAndAmount == 5'h0A ? x[21: 6] :
- dirAndAmount == 5'h0B ? x[20: 5] :
- dirAndAmount == 5'h0C ? x[19: 4] :
- dirAndAmount == 5'h0D ? x[18: 3] :
- dirAndAmount == 5'h0E ? x[17: 2] :
- dirAndAmount == 5'h0F ? x[16: 1] :
- x[31:16];
+ |(by[15:4]) ? extension :
+ dir == 1'b0 ? xshift[31:16] : xshift[15:0];
endmodule