1 |
24 |
zeus |
/*
|
2 |
|
|
* Copyright (c) 2008 Zeus Gomez Marmolejo <zeus@opencores.org>
|
3 |
|
|
*
|
4 |
|
|
* This file is part of the Zet processor. This processor is free
|
5 |
|
|
* hardware; you can redistribute it and/or modify it under the terms of
|
6 |
|
|
* the GNU General Public License as published by the Free Software
|
7 |
|
|
* Foundation; either version 3, or (at your option) any later version.
|
8 |
|
|
*
|
9 |
|
|
* Zet is distrubuted in the hope that it will be useful, but WITHOUT
|
10 |
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
11 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
12 |
|
|
* License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with Zet; see the file COPYING. If not, see
|
16 |
|
|
* <http://www.gnu.org/licenses/>.
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
`timescale 1ns/10ps
|
20 |
|
|
|
21 |
|
|
module rotate (
|
22 |
|
|
input [15:0] x,
|
23 |
27 |
zeus |
input [ 4:0] y,
|
24 |
24 |
zeus |
input [ 1:0] func, // 00: ror, 01: rol, 10: rcr, 11: rcl
|
25 |
|
|
input cfi,
|
26 |
|
|
input word_op,
|
27 |
|
|
output [15:0] out,
|
28 |
|
|
output cfo,
|
29 |
|
|
input ofi,
|
30 |
|
|
output ofo
|
31 |
|
|
);
|
32 |
|
|
|
33 |
|
|
// Net declarations
|
34 |
|
|
wire [4:0] ror16, rol16, rcr16, rcl16, rot16;
|
35 |
|
|
wire [3:0] ror8, rol8, rcr8, rcl8, rot8;
|
36 |
|
|
wire [7:0] out8;
|
37 |
|
|
wire [15:0] out16;
|
38 |
|
|
wire co8, co16;
|
39 |
|
|
wire unchanged;
|
40 |
|
|
|
41 |
|
|
// Module instantiation
|
42 |
|
|
rxr8 rxr8_0 (
|
43 |
|
|
.x (x[7:0]),
|
44 |
|
|
.ci (cfi),
|
45 |
|
|
.y (rot8),
|
46 |
|
|
.e (func[1]),
|
47 |
|
|
.w (out8),
|
48 |
|
|
.co (co8)
|
49 |
|
|
);
|
50 |
|
|
|
51 |
|
|
rxr16 rxr16_0 (
|
52 |
|
|
.x (x),
|
53 |
|
|
.ci (cfi),
|
54 |
|
|
.y (rot16),
|
55 |
|
|
.e (func[1]),
|
56 |
|
|
.w (out16),
|
57 |
|
|
.co (co16)
|
58 |
|
|
);
|
59 |
|
|
|
60 |
|
|
// Continuous assignments
|
61 |
27 |
zeus |
assign unchanged = word_op ? (y==5'b0) : (y[3:0]==4'b0);
|
62 |
24 |
zeus |
assign ror16 = { 1'b0, y[3:0] };
|
63 |
|
|
assign rol16 = { 1'b0, -y[3:0] };
|
64 |
|
|
assign ror8 = { 1'b0, y[2:0] };
|
65 |
|
|
assign rol8 = { 1'b0, -y[2:0] };
|
66 |
|
|
|
67 |
27 |
zeus |
assign rcr16 = (y <= 5'd16) ? y : { 1'b0, y[3:0] - 4'b1 };
|
68 |
|
|
assign rcl16 = (y <= 5'd17) ? 5'd17 - y : 6'd34 - y;
|
69 |
24 |
zeus |
assign rcr8 = y[3:0] <= 4'd8 ? y[3:0] : { 1'b0, y[2:0] - 3'b1 };
|
70 |
|
|
assign rcl8 = y[3:0] <= 4'd9 ? 4'd9 - y[3:0] : 5'd18 - y[3:0];
|
71 |
|
|
|
72 |
|
|
assign rot8 = func[1] ? (func[0] ? rcl8 : rcr8 )
|
73 |
|
|
: (func[0] ? rol8 : ror8 );
|
74 |
|
|
assign rot16 = func[1] ? (func[0] ? rcl16 : rcr16 )
|
75 |
|
|
: (func[0] ? rol16 : ror16 );
|
76 |
|
|
|
77 |
|
|
assign out = word_op ? out16 : { x[15:8], out8 };
|
78 |
|
|
assign cfo = unchanged ? cfi : (func[1] ? (word_op ? co16 : co8)
|
79 |
|
|
: (func[0] ? out[0]
|
80 |
|
|
: (word_op ? out[15] : out[7])));
|
81 |
|
|
// Overflow
|
82 |
|
|
assign ofo = unchanged ? ofi : (func[0] ? // left
|
83 |
|
|
(word_op ? cfo^out[15] : cfo^out[7])
|
84 |
|
|
: // right
|
85 |
|
|
(word_op ? out[15]^out[14] : out[7]^out[6]));
|
86 |
|
|
endmodule
|
87 |
|
|
|
88 |
|
|
module rxr16 (
|
89 |
|
|
input [15:0] x,
|
90 |
|
|
input ci,
|
91 |
|
|
input [ 4:0] y,
|
92 |
|
|
input e,
|
93 |
|
|
output reg [15:0] w,
|
94 |
|
|
output reg co
|
95 |
|
|
);
|
96 |
|
|
|
97 |
|
|
always @(x or ci or y or e)
|
98 |
|
|
case (y)
|
99 |
|
|
default: {co,w} <= {ci,x};
|
100 |
|
|
5'd01: {co,w} <= e ? {x[0], ci, x[15:1]} : {ci, x[0], x[15:1]};
|
101 |
|
|
5'd02: {co,w} <= e ? {x[ 1:0], ci, x[15: 2]} : {ci, x[ 1:0], x[15: 2]};
|
102 |
|
|
5'd03: {co,w} <= e ? {x[ 2:0], ci, x[15: 3]} : {ci, x[ 2:0], x[15: 3]};
|
103 |
|
|
5'd04: {co,w} <= e ? {x[ 3:0], ci, x[15: 4]} : {ci, x[ 3:0], x[15: 4]};
|
104 |
|
|
5'd05: {co,w} <= e ? {x[ 4:0], ci, x[15: 5]} : {ci, x[ 4:0], x[15: 5]};
|
105 |
|
|
5'd06: {co,w} <= e ? {x[ 5:0], ci, x[15: 6]} : {ci, x[ 5:0], x[15: 6]};
|
106 |
|
|
5'd07: {co,w} <= e ? {x[ 6:0], ci, x[15: 7]} : {ci, x[ 6:0], x[15: 7]};
|
107 |
|
|
5'd08: {co,w} <= e ? {x[ 7:0], ci, x[15: 8]} : {ci, x[ 7:0], x[15: 8]};
|
108 |
|
|
5'd09: {co,w} <= e ? {x[ 8:0], ci, x[15: 9]} : {ci, x[ 8:0], x[15: 9]};
|
109 |
|
|
5'd10: {co,w} <= e ? {x[ 9:0], ci, x[15:10]} : {ci, x[ 9:0], x[15:10]};
|
110 |
|
|
5'd11: {co,w} <= e ? {x[10:0], ci, x[15:11]} : {ci, x[10:0], x[15:11]};
|
111 |
|
|
5'd12: {co,w} <= e ? {x[11:0], ci, x[15:12]} : {ci, x[11:0], x[15:12]};
|
112 |
|
|
5'd13: {co,w} <= e ? {x[12:0], ci, x[15:13]} : {ci, x[12:0], x[15:13]};
|
113 |
|
|
5'd14: {co,w} <= e ? {x[13:0], ci, x[15:14]} : {ci, x[13:0], x[15:14]};
|
114 |
|
|
5'd15: {co,w} <= e ? {x[14:0], ci, x[15]} : {ci, x[14:0], x[15]};
|
115 |
|
|
5'd16: {co,w} <= {x,ci};
|
116 |
|
|
endcase
|
117 |
|
|
endmodule
|
118 |
|
|
|
119 |
|
|
module rxr8 (
|
120 |
|
|
input [7:0] x,
|
121 |
|
|
input ci,
|
122 |
|
|
input [3:0] y,
|
123 |
|
|
input e,
|
124 |
|
|
output reg [7:0] w,
|
125 |
|
|
output reg co
|
126 |
|
|
);
|
127 |
|
|
|
128 |
|
|
always @(x or ci or y or e)
|
129 |
|
|
case (y)
|
130 |
|
|
default: {co,w} <= {ci,x};
|
131 |
|
|
5'd01: {co,w} <= e ? {x[0], ci, x[7:1]} : {ci, x[0], x[7:1]};
|
132 |
|
|
5'd02: {co,w} <= e ? {x[1:0], ci, x[7:2]} : {ci, x[1:0], x[7:2]};
|
133 |
|
|
5'd03: {co,w} <= e ? {x[2:0], ci, x[7:3]} : {ci, x[2:0], x[7:3]};
|
134 |
|
|
5'd04: {co,w} <= e ? {x[3:0], ci, x[7:4]} : {ci, x[3:0], x[7:4]};
|
135 |
|
|
5'd05: {co,w} <= e ? {x[4:0], ci, x[7:5]} : {ci, x[4:0], x[7:5]};
|
136 |
|
|
5'd06: {co,w} <= e ? {x[5:0], ci, x[7:6]} : {ci, x[5:0], x[7:6]};
|
137 |
|
|
5'd07: {co,w} <= e ? {x[6:0], ci, x[7]} : {ci, x[6:0], x[7]};
|
138 |
|
|
5'd08: {co,w} <= {x,ci};
|
139 |
|
|
endcase
|
140 |
|
|
endmodule
|