OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber23/] [a23_barrel_shift.v] - Blame information for rev 78

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Barrel Shifter for Amber 2 Core                             //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Provides 32-bit shifts LSL, LSR, ASR and ROR                //
10
//                                                              //
11
//  Author(s):                                                  //
12
//      - Conor Santifort, csantifort.amber@gmail.com           //
13
//                                                              //
14
//////////////////////////////////////////////////////////////////
15
//                                                              //
16
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
17
//                                                              //
18
// This source file may be used and distributed without         //
19
// restriction provided that this copyright statement is not    //
20
// removed from the file and that any derivative work contains  //
21
// the original copyright notice and the associated disclaimer. //
22
//                                                              //
23
// This source file is free software; you can redistribute it   //
24
// and/or modify it under the terms of the GNU Lesser General   //
25
// Public License as published by the Free Software Foundation; //
26
// either version 2.1 of the License, or (at your option) any   //
27
// later version.                                               //
28
//                                                              //
29
// This source is distributed in the hope that it will be       //
30
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
31
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
32
// PURPOSE.  See the GNU Lesser General Public License for more //
33
// details.                                                     //
34
//                                                              //
35
// You should have received a copy of the GNU Lesser General    //
36
// Public License along with this source; if not, download it   //
37
// from http://www.opencores.org/lgpl.shtml                     //
38
//                                                              //
39
//////////////////////////////////////////////////////////////////
40
 
41
 
42 15 csantifort
module a23_barrel_shift (
43 2 csantifort
 
44
input       [31:0]          i_in,
45
input                       i_carry_in,
46
input       [7:0]           i_shift_amount,     // uses 8 LSBs of Rs, or a 5 bit immediate constant
47
input                       i_shift_imm_zero,   // high when immediate shift value of zero selected
48
input       [1:0]           i_function,
49
 
50
output      [31:0]          o_out,
51
output                      o_carry_out
52
 
53
);
54
 
55 15 csantifort
`include "a23_localparams.v"
56 2 csantifort
 
57
  // MSB is carry out
58
wire [32:0] lsl_out;
59
wire [32:0] lsr_out;
60
wire [32:0] asr_out;
61
wire [32:0] ror_out;
62
 
63
 
64
// Logical shift right zero is redundant as it is the same as logical shift left zero, so
65
// the assembler will convert LSR #0 (and ASR #0 and ROR #0) into LSL #0, and allow
66
// lsr #32 to be specified.
67
 
68
// lsl #0 is a special case, where the shifter carry out is the old value of the status flags
69
// C flag. The contents of Rm are used directly as the second operand.
70
assign lsl_out = i_shift_imm_zero         ? {i_carry_in, i_in              } :  // fall through case 
71
 
72
                 i_shift_amount == 8'd 0  ? {i_carry_in, i_in              } :  // fall through case
73
                 i_shift_amount == 8'd 1  ? {i_in[31],   i_in[30: 0],  1'd0} :
74
 
75
                 i_shift_amount == 8'd 2  ? {i_in[30],   i_in[29: 0],  2'd0} :
76
                 i_shift_amount == 8'd 3  ? {i_in[29],   i_in[28: 0],  3'd0} :
77
                 i_shift_amount == 8'd 4  ? {i_in[28],   i_in[27: 0],  4'd0} :
78
                 i_shift_amount == 8'd 5  ? {i_in[27],   i_in[26: 0],  5'd0} :
79
                 i_shift_amount == 8'd 6  ? {i_in[26],   i_in[25: 0],  6'd0} :
80
                 i_shift_amount == 8'd 7  ? {i_in[25],   i_in[24: 0],  7'd0} :
81
                 i_shift_amount == 8'd 8  ? {i_in[24],   i_in[23: 0],  8'd0} :
82
                 i_shift_amount == 8'd 9  ? {i_in[23],   i_in[22: 0],  9'd0} :
83
                 i_shift_amount == 8'd10  ? {i_in[22],   i_in[21: 0], 10'd0} :
84
                 i_shift_amount == 8'd11  ? {i_in[21],   i_in[20: 0], 11'd0} :
85
 
86
                 i_shift_amount == 8'd12  ? {i_in[20],   i_in[19: 0], 12'd0} :
87
                 i_shift_amount == 8'd13  ? {i_in[19],   i_in[18: 0], 13'd0} :
88
                 i_shift_amount == 8'd14  ? {i_in[18],   i_in[17: 0], 14'd0} :
89
                 i_shift_amount == 8'd15  ? {i_in[17],   i_in[16: 0], 15'd0} :
90
                 i_shift_amount == 8'd16  ? {i_in[16],   i_in[15: 0], 16'd0} :
91
                 i_shift_amount == 8'd17  ? {i_in[15],   i_in[14: 0], 17'd0} :
92
                 i_shift_amount == 8'd18  ? {i_in[14],   i_in[13: 0], 18'd0} :
93
                 i_shift_amount == 8'd19  ? {i_in[13],   i_in[12: 0], 19'd0} :
94
                 i_shift_amount == 8'd20  ? {i_in[12],   i_in[11: 0], 20'd0} :
95
                 i_shift_amount == 8'd21  ? {i_in[11],   i_in[10: 0], 21'd0} :
96
 
97
                 i_shift_amount == 8'd22  ? {i_in[10],   i_in[ 9: 0], 22'd0} :
98
                 i_shift_amount == 8'd23  ? {i_in[ 9],   i_in[ 8: 0], 23'd0} :
99
                 i_shift_amount == 8'd24  ? {i_in[ 8],   i_in[ 7: 0], 24'd0} :
100
                 i_shift_amount == 8'd25  ? {i_in[ 7],   i_in[ 6: 0], 25'd0} :
101
                 i_shift_amount == 8'd26  ? {i_in[ 6],   i_in[ 5: 0], 26'd0} :
102
                 i_shift_amount == 8'd27  ? {i_in[ 5],   i_in[ 4: 0], 27'd0} :
103
                 i_shift_amount == 8'd28  ? {i_in[ 4],   i_in[ 3: 0], 28'd0} :
104
                 i_shift_amount == 8'd29  ? {i_in[ 3],   i_in[ 2: 0], 29'd0} :
105
                 i_shift_amount == 8'd30  ? {i_in[ 2],   i_in[ 1: 0], 30'd0} :
106
                 i_shift_amount == 8'd31  ? {i_in[ 1],   i_in[ 0: 0], 31'd0} :
107
                 i_shift_amount == 8'd32  ? {i_in[ 0],   32'd0             } :  // 32
108
                                            {1'd0,       32'd0             } ;  // > 32
109
 
110
 
111
// The form of the shift field which might be expected to correspond to LSR #0 is used
112
// to encode LSR #32, which has a zero result with bit 31 of Rm as the carry output. 
113
                                           // carry out, < -------- out ---------->
114
assign lsr_out = i_shift_imm_zero         ? {i_in[31], 32'd0             } :
115
 
116
                 i_shift_amount == 8'd 0  ? {i_carry_in, i_in            } :  // fall through case
117
                 i_shift_amount == 8'd 1  ? {i_in[ 0],  1'd0, i_in[31: 1]} :
118
                 i_shift_amount == 8'd 2  ? {i_in[ 1],  2'd0, i_in[31: 2]} :
119
                 i_shift_amount == 8'd 3  ? {i_in[ 2],  3'd0, i_in[31: 3]} :
120
                 i_shift_amount == 8'd 4  ? {i_in[ 3],  4'd0, i_in[31: 4]} :
121
                 i_shift_amount == 8'd 5  ? {i_in[ 4],  5'd0, i_in[31: 5]} :
122
                 i_shift_amount == 8'd 6  ? {i_in[ 5],  6'd0, i_in[31: 6]} :
123
                 i_shift_amount == 8'd 7  ? {i_in[ 6],  7'd0, i_in[31: 7]} :
124
                 i_shift_amount == 8'd 8  ? {i_in[ 7],  8'd0, i_in[31: 8]} :
125
                 i_shift_amount == 8'd 9  ? {i_in[ 8],  9'd0, i_in[31: 9]} :
126
 
127
                 i_shift_amount == 8'd10  ? {i_in[ 9], 10'd0, i_in[31:10]} :
128
                 i_shift_amount == 8'd11  ? {i_in[10], 11'd0, i_in[31:11]} :
129
                 i_shift_amount == 8'd12  ? {i_in[11], 12'd0, i_in[31:12]} :
130
                 i_shift_amount == 8'd13  ? {i_in[12], 13'd0, i_in[31:13]} :
131
                 i_shift_amount == 8'd14  ? {i_in[13], 14'd0, i_in[31:14]} :
132
                 i_shift_amount == 8'd15  ? {i_in[14], 15'd0, i_in[31:15]} :
133
                 i_shift_amount == 8'd16  ? {i_in[15], 16'd0, i_in[31:16]} :
134
                 i_shift_amount == 8'd17  ? {i_in[16], 17'd0, i_in[31:17]} :
135
                 i_shift_amount == 8'd18  ? {i_in[17], 18'd0, i_in[31:18]} :
136
                 i_shift_amount == 8'd19  ? {i_in[18], 19'd0, i_in[31:19]} :
137
 
138
                 i_shift_amount == 8'd20  ? {i_in[19], 20'd0, i_in[31:20]} :
139
                 i_shift_amount == 8'd21  ? {i_in[20], 21'd0, i_in[31:21]} :
140
                 i_shift_amount == 8'd22  ? {i_in[21], 22'd0, i_in[31:22]} :
141
                 i_shift_amount == 8'd23  ? {i_in[22], 23'd0, i_in[31:23]} :
142
                 i_shift_amount == 8'd24  ? {i_in[23], 24'd0, i_in[31:24]} :
143
                 i_shift_amount == 8'd25  ? {i_in[24], 25'd0, i_in[31:25]} :
144
                 i_shift_amount == 8'd26  ? {i_in[25], 26'd0, i_in[31:26]} :
145
                 i_shift_amount == 8'd27  ? {i_in[26], 27'd0, i_in[31:27]} :
146
                 i_shift_amount == 8'd28  ? {i_in[27], 28'd0, i_in[31:28]} :
147
                 i_shift_amount == 8'd29  ? {i_in[28], 29'd0, i_in[31:29]} :
148
 
149
                 i_shift_amount == 8'd30  ? {i_in[29], 30'd0, i_in[31:30]} :
150
                 i_shift_amount == 8'd31  ? {i_in[30], 31'd0, i_in[31   ]} :
151
                 i_shift_amount == 8'd32  ? {i_in[31], 32'd0             } :
152
                                            {1'd0,     32'd0             } ;  // > 32
153
 
154
 
155
// The form of the shift field which might be expected to give ASR #0 is used to encode
156
// ASR #32. Bit 31 of Rm is again used as the carry output, and each bit of operand 2 is
157
// also equal to bit 31 of Rm. The result is therefore all ones or all zeros, according to
158
// the value of bit 31 of Rm.
159
 
160
                                          // carry out, < -------- out ---------->
161
assign asr_out = i_shift_imm_zero         ? {i_in[31], {32{i_in[31]}}             } :
162
 
163
                 i_shift_amount == 8'd 0  ? {i_carry_in, i_in                     } :  // fall through case
164
                 i_shift_amount == 8'd 1  ? {i_in[ 0], { 2{i_in[31]}}, i_in[30: 1]} :
165
                 i_shift_amount == 8'd 2  ? {i_in[ 1], { 3{i_in[31]}}, i_in[30: 2]} :
166
                 i_shift_amount == 8'd 3  ? {i_in[ 2], { 4{i_in[31]}}, i_in[30: 3]} :
167
                 i_shift_amount == 8'd 4  ? {i_in[ 3], { 5{i_in[31]}}, i_in[30: 4]} :
168
                 i_shift_amount == 8'd 5  ? {i_in[ 4], { 6{i_in[31]}}, i_in[30: 5]} :
169
                 i_shift_amount == 8'd 6  ? {i_in[ 5], { 7{i_in[31]}}, i_in[30: 6]} :
170
                 i_shift_amount == 8'd 7  ? {i_in[ 6], { 8{i_in[31]}}, i_in[30: 7]} :
171
                 i_shift_amount == 8'd 8  ? {i_in[ 7], { 9{i_in[31]}}, i_in[30: 8]} :
172
                 i_shift_amount == 8'd 9  ? {i_in[ 8], {10{i_in[31]}}, i_in[30: 9]} :
173
 
174
                 i_shift_amount == 8'd10  ? {i_in[ 9], {11{i_in[31]}}, i_in[30:10]} :
175
                 i_shift_amount == 8'd11  ? {i_in[10], {12{i_in[31]}}, i_in[30:11]} :
176
                 i_shift_amount == 8'd12  ? {i_in[11], {13{i_in[31]}}, i_in[30:12]} :
177
                 i_shift_amount == 8'd13  ? {i_in[12], {14{i_in[31]}}, i_in[30:13]} :
178
                 i_shift_amount == 8'd14  ? {i_in[13], {15{i_in[31]}}, i_in[30:14]} :
179
                 i_shift_amount == 8'd15  ? {i_in[14], {16{i_in[31]}}, i_in[30:15]} :
180
                 i_shift_amount == 8'd16  ? {i_in[15], {17{i_in[31]}}, i_in[30:16]} :
181
                 i_shift_amount == 8'd17  ? {i_in[16], {18{i_in[31]}}, i_in[30:17]} :
182
                 i_shift_amount == 8'd18  ? {i_in[17], {19{i_in[31]}}, i_in[30:18]} :
183
                 i_shift_amount == 8'd19  ? {i_in[18], {20{i_in[31]}}, i_in[30:19]} :
184
 
185
                 i_shift_amount == 8'd20  ? {i_in[19], {21{i_in[31]}}, i_in[30:20]} :
186
                 i_shift_amount == 8'd21  ? {i_in[20], {22{i_in[31]}}, i_in[30:21]} :
187
                 i_shift_amount == 8'd22  ? {i_in[21], {23{i_in[31]}}, i_in[30:22]} :
188
                 i_shift_amount == 8'd23  ? {i_in[22], {24{i_in[31]}}, i_in[30:23]} :
189
                 i_shift_amount == 8'd24  ? {i_in[23], {25{i_in[31]}}, i_in[30:24]} :
190
                 i_shift_amount == 8'd25  ? {i_in[24], {26{i_in[31]}}, i_in[30:25]} :
191
                 i_shift_amount == 8'd26  ? {i_in[25], {27{i_in[31]}}, i_in[30:26]} :
192
                 i_shift_amount == 8'd27  ? {i_in[26], {28{i_in[31]}}, i_in[30:27]} :
193
                 i_shift_amount == 8'd28  ? {i_in[27], {29{i_in[31]}}, i_in[30:28]} :
194
                 i_shift_amount == 8'd29  ? {i_in[28], {30{i_in[31]}}, i_in[30:29]} :
195
 
196
                 i_shift_amount == 8'd30  ? {i_in[29], {31{i_in[31]}}, i_in[30   ]} :
197
                 i_shift_amount == 8'd31  ? {i_in[30], {32{i_in[31]}}             } :
198
                                            {i_in[31], {32{i_in[31]}}             } ; // >= 32
199
 
200
 
201
                                          // carry out, < ------- out --------->
202
assign ror_out = i_shift_imm_zero              ? {i_in[ 0], i_carry_in,  i_in[31: 1]} :  // RXR, (ROR w/ imm 0)
203
 
204
                 i_shift_amount[7:0] == 8'd 0  ? {i_carry_in, i_in                  } :  // fall through case
205
 
206
                 i_shift_amount[4:0] == 5'd 0  ? {i_in[31], i_in                    } :  // Rs > 31
207
                 i_shift_amount[4:0] == 5'd 1  ? {i_in[ 0], i_in[    0], i_in[31: 1]} :
208
                 i_shift_amount[4:0] == 5'd 2  ? {i_in[ 1], i_in[ 1: 0], i_in[31: 2]} :
209
                 i_shift_amount[4:0] == 5'd 3  ? {i_in[ 2], i_in[ 2: 0], i_in[31: 3]} :
210
                 i_shift_amount[4:0] == 5'd 4  ? {i_in[ 3], i_in[ 3: 0], i_in[31: 4]} :
211
                 i_shift_amount[4:0] == 5'd 5  ? {i_in[ 4], i_in[ 4: 0], i_in[31: 5]} :
212
                 i_shift_amount[4:0] == 5'd 6  ? {i_in[ 5], i_in[ 5: 0], i_in[31: 6]} :
213
                 i_shift_amount[4:0] == 5'd 7  ? {i_in[ 6], i_in[ 6: 0], i_in[31: 7]} :
214
                 i_shift_amount[4:0] == 5'd 8  ? {i_in[ 7], i_in[ 7: 0], i_in[31: 8]} :
215
                 i_shift_amount[4:0] == 5'd 9  ? {i_in[ 8], i_in[ 8: 0], i_in[31: 9]} :
216
 
217
                 i_shift_amount[4:0] == 5'd10  ? {i_in[ 9], i_in[ 9: 0], i_in[31:10]} :
218
                 i_shift_amount[4:0] == 5'd11  ? {i_in[10], i_in[10: 0], i_in[31:11]} :
219
                 i_shift_amount[4:0] == 5'd12  ? {i_in[11], i_in[11: 0], i_in[31:12]} :
220
                 i_shift_amount[4:0] == 5'd13  ? {i_in[12], i_in[12: 0], i_in[31:13]} :
221
                 i_shift_amount[4:0] == 5'd14  ? {i_in[13], i_in[13: 0], i_in[31:14]} :
222
                 i_shift_amount[4:0] == 5'd15  ? {i_in[14], i_in[14: 0], i_in[31:15]} :
223
                 i_shift_amount[4:0] == 5'd16  ? {i_in[15], i_in[15: 0], i_in[31:16]} :
224
                 i_shift_amount[4:0] == 5'd17  ? {i_in[16], i_in[16: 0], i_in[31:17]} :
225
                 i_shift_amount[4:0] == 5'd18  ? {i_in[17], i_in[17: 0], i_in[31:18]} :
226
                 i_shift_amount[4:0] == 5'd19  ? {i_in[18], i_in[18: 0], i_in[31:19]} :
227
 
228
                 i_shift_amount[4:0] == 5'd20  ? {i_in[19], i_in[19: 0], i_in[31:20]} :
229
                 i_shift_amount[4:0] == 5'd21  ? {i_in[20], i_in[20: 0], i_in[31:21]} :
230
                 i_shift_amount[4:0] == 5'd22  ? {i_in[21], i_in[21: 0], i_in[31:22]} :
231
                 i_shift_amount[4:0] == 5'd23  ? {i_in[22], i_in[22: 0], i_in[31:23]} :
232
                 i_shift_amount[4:0] == 5'd24  ? {i_in[23], i_in[23: 0], i_in[31:24]} :
233
                 i_shift_amount[4:0] == 5'd25  ? {i_in[24], i_in[24: 0], i_in[31:25]} :
234
                 i_shift_amount[4:0] == 5'd26  ? {i_in[25], i_in[25: 0], i_in[31:26]} :
235
                 i_shift_amount[4:0] == 5'd27  ? {i_in[26], i_in[26: 0], i_in[31:27]} :
236
                 i_shift_amount[4:0] == 5'd28  ? {i_in[27], i_in[27: 0], i_in[31:28]} :
237
                 i_shift_amount[4:0] == 5'd29  ? {i_in[28], i_in[28: 0], i_in[31:29]} :
238
 
239
                 i_shift_amount[4:0] == 5'd30  ? {i_in[29], i_in[29: 0], i_in[31:30]} :
240
                                                 {i_in[30], i_in[30: 0], i_in[31:31]} ;
241
 
242
 
243
 
244
assign {o_carry_out, o_out} = i_function == LSL ? lsl_out :
245
                              i_function == LSR ? lsr_out :
246
                              i_function == ASR ? asr_out :
247
                                                  ror_out ;
248
 
249
endmodule
250
 
251
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.