1 |
2 |
tak.sugawa |
//Jul.5.2004 redushift_oute shift_outritishift_outal path shift_outell
|
2 |
|
|
//Apr.5.2005 always @(*)
|
3 |
|
|
//Apr.8.2005 rewritten using verilog2001 shift_outoding style
|
4 |
|
|
`include "define.h"
|
5 |
|
|
module
|
6 |
|
|
shifter(input [31:0] a,
|
7 |
|
|
output reg [31:0] shift_out,
|
8 |
|
|
input [1:0] shift_func,
|
9 |
|
|
input [4:0] shift_amount);
|
10 |
|
|
|
11 |
|
|
localparam [1:0] shift_left=`SHIFT_LEFT,
|
12 |
|
|
shift_right_unsigned=`SHIFT_RIGHT_UNSIGNED,
|
13 |
|
|
shift_right_signed=`SHIFT_RIGHT_SIGNED;
|
14 |
|
|
|
15 |
|
|
always @ (*) begin //
|
16 |
|
|
if (!shift_func[1] ) begin
|
17 |
|
|
case (shift_amount[4:0] )
|
18 |
|
|
5'b00000: shift_out=a;
|
19 |
|
|
5'b00001: shift_out={a[30:0],1'b0};
|
20 |
|
|
5'b00010: shift_out={a[29:0],2'b00};
|
21 |
|
|
5'b00011: shift_out={a[28:0],3'b000};
|
22 |
|
|
5'b00100: shift_out={a[27:0],4'b0000};
|
23 |
|
|
5'b00101: shift_out={a[26:0],5'b0_0000};
|
24 |
|
|
5'b00110: shift_out={a[25:0],6'b00_0000};
|
25 |
|
|
5'b00111: shift_out={a[24:0],7'b000_0000};
|
26 |
|
|
5'b01000: shift_out={a[23:0],8'b0000_0000};
|
27 |
|
|
5'b01001: shift_out={a[22:0],9'b0_0000_0000};
|
28 |
|
|
5'b01010: shift_out={a[21:0],10'b00_0000_0000};
|
29 |
|
|
5'b01011: shift_out={a[20:0],11'b000_0000_0000};
|
30 |
|
|
5'b01100: shift_out={a[19:0],12'b0000_0000_0000};
|
31 |
|
|
5'b01101: shift_out={a[18:0],13'b0_0000_0000_0000};
|
32 |
|
|
5'b01110: shift_out={a[17:0],14'b00_0000_0000_0000};
|
33 |
|
|
5'b01111: shift_out={a[16:0],15'b000_0000_0000_0000};
|
34 |
|
|
5'b10000: shift_out={a[15:0],16'b0000_0000_0000_0000};
|
35 |
|
|
5'b10001: shift_out={a[14:0],16'b0000_0000_0000_0000,1'b0};
|
36 |
|
|
5'b10010: shift_out={a[13:0],16'b0000_0000_0000_0000,2'b00};
|
37 |
|
|
5'b10011: shift_out={a[12:0],16'b0000_0000_0000_0000,3'b000};
|
38 |
|
|
5'b10100: shift_out={a[11:0],16'b0000_0000_0000_0000,4'b0000};
|
39 |
|
|
5'b10101: shift_out={a[10:0],16'b0000_0000_0000_0000,5'b0_0000};
|
40 |
|
|
5'b10110: shift_out={a[9:0],16'b0000_0000_0000_0000,6'b00_0000};
|
41 |
|
|
5'b10111: shift_out={a[8:0],16'b0000_0000_0000_0000,7'b000_0000};
|
42 |
|
|
5'b11000: shift_out={a[7:0],16'b0000_0000_0000_0000,8'b0000_0000};
|
43 |
|
|
5'b11001: shift_out={a[6:0],16'b0000_0000_0000_0000,9'b0_0000_0000};
|
44 |
|
|
5'b11010: shift_out={a[5:0],16'b0000_0000_0000_0000,10'b00_0000_0000};
|
45 |
|
|
5'b11011: shift_out={a[4:0],16'b0000_0000_0000_0000,11'b000_0000_0000};
|
46 |
|
|
5'b11100: shift_out={a[3:0],16'b0000_0000_0000_0000,12'b0000_0000_0000};
|
47 |
|
|
5'b11101: shift_out={a[2:0],16'b0000_0000_0000_0000,13'b0_0000_0000_0000};
|
48 |
|
|
5'b11110: shift_out={a[1:0],16'b0000_0000_0000_0000,14'b00_0000_0000_0000};
|
49 |
|
|
5'b11111: shift_out={a[0],16'b0000_0000_0000_0000,15'b000_0000_0000_0000};
|
50 |
|
|
endcase
|
51 |
|
|
end else if (shift_func==`SHIFT_RIGHT_UNSIGNED) begin
|
52 |
|
|
case (shift_amount)
|
53 |
|
|
5'b00000: shift_out=a;
|
54 |
|
|
5'b00001: shift_out={1'b0,a[31:1]};
|
55 |
|
|
5'b00010: shift_out={2'b00,a[31:2]};
|
56 |
|
|
5'b00011: shift_out={3'b000,a[31:3]};
|
57 |
|
|
5'b00100: shift_out={4'b0000,a[31:4]};
|
58 |
|
|
5'b00101: shift_out={5'b0_0000,a[31:5]};
|
59 |
|
|
5'b00110: shift_out={6'b00_0000,a[31:6]};
|
60 |
|
|
5'b00111: shift_out={7'b000_0000,a[31:7]};
|
61 |
|
|
5'b01000: shift_out={8'b0000_0000,a[31:8]};
|
62 |
|
|
5'b01001: shift_out={9'b0_0000_0000,a[31:9]};
|
63 |
|
|
5'b01010: shift_out={10'b00_0000_0000,a[31:10]};
|
64 |
|
|
5'b01011: shift_out={11'b000_0000_0000,a[31:11]};
|
65 |
|
|
5'b01100: shift_out={12'b0000_0000_0000,a[31:12]};
|
66 |
|
|
5'b01101: shift_out={13'b0_0000_0000_0000,a[31:13]};
|
67 |
|
|
5'b01110: shift_out={14'b00_0000_0000_0000,a[31:14]};
|
68 |
|
|
5'b01111: shift_out={15'b000_0000_0000_0000,a[31:15]};
|
69 |
|
|
5'b10000: shift_out={16'b0000_0000_0000_0000,a[31:16]};
|
70 |
|
|
5'b10001: shift_out={16'b0000_0000_0000_0000,1'b0,a[31:17]};
|
71 |
|
|
5'b10010: shift_out={16'b0000_0000_0000_0000,2'b00,a[31:18]};
|
72 |
|
|
5'b10011: shift_out={16'b0000_0000_0000_0000,3'b000,a[31:19]};
|
73 |
|
|
5'b10100: shift_out={16'b0000_0000_0000_0000,4'b0000,a[31:20]};
|
74 |
|
|
5'b10101: shift_out={16'b0000_0000_0000_0000,5'b0_0000,a[31:21]};
|
75 |
|
|
5'b10110: shift_out={16'b0000_0000_0000_0000,6'b00_0000,a[31:22]};
|
76 |
|
|
5'b10111: shift_out={16'b0000_0000_0000_0000,7'b000_0000,a[31:23]};
|
77 |
|
|
5'b11000: shift_out={16'b0000_0000_0000_0000,8'b0000_0000,a[31:24]};
|
78 |
|
|
5'b11001: shift_out={16'b0000_0000_0000_0000,9'b0_0000_0000,a[31:25]};
|
79 |
|
|
5'b11010: shift_out={16'b0000_0000_0000_0000,10'b00_0000_0000,a[31:26]};
|
80 |
|
|
5'b11011: shift_out={16'b0000_0000_0000_0000,11'b000_0000_0000,a[31:27]};
|
81 |
|
|
5'b11100: shift_out={16'b0000_0000_0000_0000,12'b0000_0000_0000,a[31:28]};
|
82 |
|
|
5'b11101: shift_out={16'b0000_0000_0000_0000,13'b0_0000_0000_0000,a[31:29]};
|
83 |
|
|
5'b11110: shift_out={16'b0000_0000_0000_0000,14'b00_0000_0000_0000,a[31:30]};
|
84 |
|
|
5'b11111: shift_out={16'b0000_0000_0000_0000,15'b000_0000_0000_0000,a[31:31]};
|
85 |
|
|
endcase
|
86 |
|
|
end else begin// SHIFT_RIGHT_SIGNED
|
87 |
|
|
case (shift_amount)
|
88 |
|
|
5'b00000: shift_out=a;
|
89 |
|
|
5'b00001: shift_out={a[31],a[31:1]};
|
90 |
|
|
5'b00010: shift_out={{2{a[31]}},a[31:2]};
|
91 |
|
|
5'b00011: shift_out={{3{a[31]}},a[31:3]};
|
92 |
|
|
5'b00100: shift_out={{4{a[31]}},a[31:4]};
|
93 |
|
|
5'b00101: shift_out={{5{a[31]}},a[31:5]};
|
94 |
|
|
5'b00110: shift_out={{6{a[31]}},a[31:6]};
|
95 |
|
|
5'b00111: shift_out={{7{a[31]}},a[31:7]};
|
96 |
|
|
5'b01000: shift_out={{8{a[31]}},a[31:8]};
|
97 |
|
|
5'b01001: shift_out={{9{a[31]}},a[31:9]};
|
98 |
|
|
5'b01010: shift_out={{10{a[31]}},a[31:10]};
|
99 |
|
|
5'b01011: shift_out={{11{a[31]}},a[31:11]};
|
100 |
|
|
5'b01100: shift_out={{12{a[31]}},a[31:12]};
|
101 |
|
|
5'b01101: shift_out={{13{a[31]}},a[31:13]};
|
102 |
|
|
5'b01110: shift_out={{14{a[31]}},a[31:14]};
|
103 |
|
|
5'b01111: shift_out={{15{a[31]}},a[31:15]};
|
104 |
|
|
5'b10000: shift_out={{16{a[31]}},a[31:16]};
|
105 |
|
|
5'b10001: shift_out={{17{a[31]}},a[31:17]};
|
106 |
|
|
5'b10010: shift_out={{18{a[31]}},a[31:18]};
|
107 |
|
|
5'b10011: shift_out={{19{a[31]}},a[31:19]};
|
108 |
|
|
5'b10100: shift_out={{20{a[31]}},a[31:20]};
|
109 |
|
|
5'b10101: shift_out={{21{a[31]}},a[31:21]};
|
110 |
|
|
5'b10110: shift_out={{22{a[31]}},a[31:22]};
|
111 |
|
|
5'b10111: shift_out={{23{a[31]}},a[31:23]};
|
112 |
|
|
5'b11000: shift_out={{24{a[31]}},a[31:24]};
|
113 |
|
|
5'b11001: shift_out={{25{a[31]}},a[31:25]};
|
114 |
|
|
5'b11010: shift_out={{26{a[31]}},a[31:26]};
|
115 |
|
|
5'b11011: shift_out={{27{a[31]}},a[31:27]};
|
116 |
|
|
5'b11100: shift_out={{28{a[31]}},a[31:28]};
|
117 |
|
|
5'b11101: shift_out={{29{a[31]}},a[31:29]};
|
118 |
|
|
5'b11110: shift_out={{30{a[31]}},a[31:30]};
|
119 |
|
|
5'b11111: shift_out={{31{a[31]}},a[31:31]};
|
120 |
|
|
endcase
|
121 |
|
|
end
|
122 |
|
|
end
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
endmodule
|