1 |
2 |
alfik |
/*
|
2 |
|
|
* This file is subject to the terms and conditions of the BSD License. See
|
3 |
|
|
* the file "LICENSE" in the main directory of this archive for more details.
|
4 |
|
|
*
|
5 |
|
|
* Copyright (C) 2014 Aleksander Osman
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
`include "defines.v"
|
9 |
|
|
|
10 |
|
|
module block_shift(
|
11 |
|
|
input [6:0] rf_cmd,
|
12 |
|
|
input [31:0] rf_instr,
|
13 |
|
|
input [31:0] rf_a,
|
14 |
|
|
input [31:0] rf_b,
|
15 |
|
|
|
16 |
|
|
output [31:0] shift_left,
|
17 |
|
|
output [31:0] shift_right
|
18 |
|
|
);
|
19 |
|
|
|
20 |
|
|
//------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
wire [4:0] shift_left_index = (rf_cmd == `CMD_3arg_sllv)? rf_a[4:0] : rf_instr[10:6];
|
23 |
|
|
|
24 |
|
|
assign shift_left =
|
25 |
|
|
(shift_left_index == 5'd0)? rf_b :
|
26 |
|
|
(shift_left_index == 5'd1)? { rf_b[30:0], 1'b0 } :
|
27 |
|
|
(shift_left_index == 5'd2)? { rf_b[29:0], 2'b0 } :
|
28 |
|
|
(shift_left_index == 5'd3)? { rf_b[28:0], 3'b0 } :
|
29 |
|
|
(shift_left_index == 5'd4)? { rf_b[27:0], 4'b0 } :
|
30 |
|
|
(shift_left_index == 5'd5)? { rf_b[26:0], 5'b0 } :
|
31 |
|
|
(shift_left_index == 5'd6)? { rf_b[25:0], 6'b0 } :
|
32 |
|
|
(shift_left_index == 5'd7)? { rf_b[24:0], 7'b0 } :
|
33 |
|
|
(shift_left_index == 5'd8)? { rf_b[23:0], 8'b0 } :
|
34 |
|
|
(shift_left_index == 5'd9)? { rf_b[22:0], 9'b0 } :
|
35 |
|
|
(shift_left_index == 5'd10)? { rf_b[21:0], 10'b0 } :
|
36 |
|
|
(shift_left_index == 5'd11)? { rf_b[20:0], 11'b0 } :
|
37 |
|
|
(shift_left_index == 5'd12)? { rf_b[19:0], 12'b0 } :
|
38 |
|
|
(shift_left_index == 5'd13)? { rf_b[18:0], 13'b0 } :
|
39 |
|
|
(shift_left_index == 5'd14)? { rf_b[17:0], 14'b0 } :
|
40 |
|
|
(shift_left_index == 5'd15)? { rf_b[16:0], 15'b0 } :
|
41 |
|
|
(shift_left_index == 5'd16)? { rf_b[15:0], 16'b0 } :
|
42 |
|
|
(shift_left_index == 5'd17)? { rf_b[14:0], 17'b0 } :
|
43 |
|
|
(shift_left_index == 5'd18)? { rf_b[13:0], 18'b0 } :
|
44 |
|
|
(shift_left_index == 5'd19)? { rf_b[12:0], 19'b0 } :
|
45 |
|
|
(shift_left_index == 5'd20)? { rf_b[11:0], 20'b0 } :
|
46 |
|
|
(shift_left_index == 5'd21)? { rf_b[10:0], 21'b0 } :
|
47 |
|
|
(shift_left_index == 5'd22)? { rf_b[9:0], 22'b0 } :
|
48 |
|
|
(shift_left_index == 5'd23)? { rf_b[8:0], 23'b0 } :
|
49 |
|
|
(shift_left_index == 5'd24)? { rf_b[7:0], 24'b0 } :
|
50 |
|
|
(shift_left_index == 5'd25)? { rf_b[6:0], 25'b0 } :
|
51 |
|
|
(shift_left_index == 5'd26)? { rf_b[5:0], 26'b0 } :
|
52 |
|
|
(shift_left_index == 5'd27)? { rf_b[4:0], 27'b0 } :
|
53 |
|
|
(shift_left_index == 5'd28)? { rf_b[3:0], 28'b0 } :
|
54 |
|
|
(shift_left_index == 5'd29)? { rf_b[2:0], 29'b0 } :
|
55 |
|
|
(shift_left_index == 5'd30)? { rf_b[1:0], 30'b0 } :
|
56 |
|
|
{ rf_b[0], 31'b0 };
|
57 |
|
|
|
58 |
|
|
wire shift_right_arith = rf_cmd == `CMD_3arg_srav || rf_cmd == `CMD_sra;
|
59 |
|
|
wire [4:0] shift_right_index = (rf_cmd == `CMD_3arg_srav || rf_cmd == `CMD_3arg_srlv)? rf_a[4:0] : rf_instr[10:6];
|
60 |
|
|
|
61 |
|
|
assign shift_right =
|
62 |
|
|
(shift_right_index == 5'd0)? rf_b :
|
63 |
|
|
(shift_right_index == 5'd1)? { {1 {shift_right_arith & rf_b[31]}}, rf_b[31:1] } :
|
64 |
|
|
(shift_right_index == 5'd2)? { {2 {shift_right_arith & rf_b[31]}}, rf_b[31:2] } :
|
65 |
|
|
(shift_right_index == 5'd3)? { {3 {shift_right_arith & rf_b[31]}}, rf_b[31:3] } :
|
66 |
|
|
(shift_right_index == 5'd4)? { {4 {shift_right_arith & rf_b[31]}}, rf_b[31:4] } :
|
67 |
|
|
(shift_right_index == 5'd5)? { {5 {shift_right_arith & rf_b[31]}}, rf_b[31:5] } :
|
68 |
|
|
(shift_right_index == 5'd6)? { {6 {shift_right_arith & rf_b[31]}}, rf_b[31:6] } :
|
69 |
|
|
(shift_right_index == 5'd7)? { {7 {shift_right_arith & rf_b[31]}}, rf_b[31:7] } :
|
70 |
|
|
(shift_right_index == 5'd8)? { {8 {shift_right_arith & rf_b[31]}}, rf_b[31:8] } :
|
71 |
|
|
(shift_right_index == 5'd9)? { {9 {shift_right_arith & rf_b[31]}}, rf_b[31:9] } :
|
72 |
|
|
(shift_right_index == 5'd10)? { {10{shift_right_arith & rf_b[31]}}, rf_b[31:10] } :
|
73 |
|
|
(shift_right_index == 5'd11)? { {11{shift_right_arith & rf_b[31]}}, rf_b[31:11] } :
|
74 |
|
|
(shift_right_index == 5'd12)? { {12{shift_right_arith & rf_b[31]}}, rf_b[31:12] } :
|
75 |
|
|
(shift_right_index == 5'd13)? { {13{shift_right_arith & rf_b[31]}}, rf_b[31:13] } :
|
76 |
|
|
(shift_right_index == 5'd14)? { {14{shift_right_arith & rf_b[31]}}, rf_b[31:14] } :
|
77 |
|
|
(shift_right_index == 5'd15)? { {15{shift_right_arith & rf_b[31]}}, rf_b[31:15] } :
|
78 |
|
|
(shift_right_index == 5'd16)? { {16{shift_right_arith & rf_b[31]}}, rf_b[31:16] } :
|
79 |
|
|
(shift_right_index == 5'd17)? { {17{shift_right_arith & rf_b[31]}}, rf_b[31:17] } :
|
80 |
|
|
(shift_right_index == 5'd18)? { {18{shift_right_arith & rf_b[31]}}, rf_b[31:18] } :
|
81 |
|
|
(shift_right_index == 5'd19)? { {19{shift_right_arith & rf_b[31]}}, rf_b[31:19] } :
|
82 |
|
|
(shift_right_index == 5'd20)? { {20{shift_right_arith & rf_b[31]}}, rf_b[31:20] } :
|
83 |
|
|
(shift_right_index == 5'd21)? { {21{shift_right_arith & rf_b[31]}}, rf_b[31:21] } :
|
84 |
|
|
(shift_right_index == 5'd22)? { {22{shift_right_arith & rf_b[31]}}, rf_b[31:22] } :
|
85 |
|
|
(shift_right_index == 5'd23)? { {23{shift_right_arith & rf_b[31]}}, rf_b[31:23] } :
|
86 |
|
|
(shift_right_index == 5'd24)? { {24{shift_right_arith & rf_b[31]}}, rf_b[31:24] } :
|
87 |
|
|
(shift_right_index == 5'd25)? { {25{shift_right_arith & rf_b[31]}}, rf_b[31:25] } :
|
88 |
|
|
(shift_right_index == 5'd26)? { {26{shift_right_arith & rf_b[31]}}, rf_b[31:26] } :
|
89 |
|
|
(shift_right_index == 5'd27)? { {27{shift_right_arith & rf_b[31]}}, rf_b[31:27] } :
|
90 |
|
|
(shift_right_index == 5'd28)? { {28{shift_right_arith & rf_b[31]}}, rf_b[31:28] } :
|
91 |
|
|
(shift_right_index == 5'd29)? { {29{shift_right_arith & rf_b[31]}}, rf_b[31:29] } :
|
92 |
|
|
(shift_right_index == 5'd30)? { {30{shift_right_arith & rf_b[31]}}, rf_b[31:30] } :
|
93 |
|
|
{ {31{shift_right_arith & rf_b[31]}}, rf_b[31] };
|
94 |
|
|
|
95 |
|
|
//------------------------------------------------------------------------------
|
96 |
|
|
// synthesis translate_off
|
97 |
|
|
wire _unused_ok = &{ 1'b0, rf_instr[31:11], rf_instr[5:0], rf_a[31:5], 1'b0 };
|
98 |
|
|
// synthesis translate_on
|
99 |
|
|
//------------------------------------------------------------------------------
|
100 |
|
|
|
101 |
|
|
endmodule
|