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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [rtl/] [ao486/] [pipeline/] [execute_shift.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * Copyright (c) 2014, Aleksander Osman
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * * Redistributions of source code must retain the above copyright notice, this
9
 *   list of conditions and the following disclaimer.
10
 *
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 *   this list of conditions and the following disclaimer in the documentation
13
 *   and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
 
27
`include "defines.v"
28
 
29
module execute_shift(
30
 
31
    input               exe_is_8bit,
32
    input               exe_operand_16bit,
33
    input               exe_operand_32bit,
34
    input               exe_prefix_2byte,
35
 
36
    input       [6:0]   exe_cmd,
37
    input       [3:0]   exe_cmdex,
38
    input       [39:0]  exe_decoder,
39
    input       [7:0]   exe_modregrm_imm,
40
 
41
    input               cflag,
42
 
43
    input       [31:0]  ecx,
44
 
45
    input       [31:0]  dst,
46
    input       [31:0]  src,
47
 
48
    //output
49
    output              e_shift_no_write,
50
    output              e_shift_oszapc_update,
51
    output              e_shift_cf_of_update,
52
    output              e_shift_oflag,
53
    output              e_shift_cflag,
54
 
55
    output      [31:0]  e_shift_result
56
);
57
 
58
//------------------------------------------------------------------------------ SHRD, SHLD, SAL, SAR, SHR, ROL, ROR, RCL, RCR
59
 
60
wire [31:0] e_shift_dst_wire;
61
wire [4:0]  e_shift_count;
62
wire [2:0]  e_shift_cmd;
63
 
64
wire e_shift_ROL;
65
wire e_shift_ROR;
66
wire e_shift_RCL;
67
wire e_shift_RCR;
68
wire e_shift_SHL;
69
wire e_shift_SHR;
70
wire e_shift_SAR;
71
wire e_shift_SHLD;
72
wire e_shift_SHRD;
73
wire e_shift_SHxD;
74
 
75
wire [63:0] e_shift_left_input;
76
wire [63:0] e_shift_right_input;
77
wire [32:0] e_shift_left_result;
78
wire        e_shift_left_cflag;
79
wire [32:0] e_shift_right_result;
80
 
81
wire e_shift_cf_of_rotate_carry_8bit;
82
wire e_shift_cf_of_rotate_carry_16bit;
83
wire e_shift_cmd_not_carry;
84
wire e_shift_cmd_carry;
85
wire e_shift_cmd_shift;
86
wire e_shift_cmd_rot;
87
 
88
//------------------------------------------------------------------------------
89
 
90
assign e_shift_dst_wire =
91
    (exe_is_8bit)?       { dst[7:0],  dst[7:0], dst[7:0], dst[7:0] } :
92
    (exe_operand_16bit)? { dst[15:0], dst[15:0] } :
93
                           dst;
94
 
95
assign e_shift_count =
96
  (e_shift_SHxD && exe_cmdex == `CMDEX_SHxD_implicit)?      ecx[4:0] :
97
  (e_shift_SHxD && exe_cmdex == `CMDEX_SHxD_modregrm_imm)?  exe_modregrm_imm[4:0] :
98
                                                            src[4:0];
99
 
100
assign e_shift_cmd = exe_decoder[13:11];
101
assign e_shift_ROL = ~(exe_prefix_2byte) && e_shift_cmd == 3'd0;
102
assign e_shift_ROR = ~(exe_prefix_2byte) && e_shift_cmd == 3'd1;
103
assign e_shift_RCL = ~(exe_prefix_2byte) && e_shift_cmd == 3'd2;
104
assign e_shift_RCR = ~(exe_prefix_2byte) && e_shift_cmd == 3'd3;
105
assign e_shift_SHL = ~(exe_prefix_2byte) && (e_shift_cmd == 3'd4 || e_shift_cmd == 3'd6);
106
assign e_shift_SHR = ~(exe_prefix_2byte) && e_shift_cmd == 3'd5;
107
assign e_shift_SAR = ~(exe_prefix_2byte) && e_shift_cmd == 3'd7;
108
 
109
assign e_shift_SHLD = exe_prefix_2byte && ~(exe_cmd[0]);
110
assign e_shift_SHRD = exe_prefix_2byte &&   exe_cmd[0];
111
assign e_shift_SHxD = exe_prefix_2byte;
112
 
113
assign e_shift_left_input =
114
    (e_shift_SHL)?                       { e_shift_dst_wire, 32'd0 } :
115
    (e_shift_ROL)?                       { e_shift_dst_wire, e_shift_dst_wire } :
116
    (e_shift_RCL && exe_is_8bit)?        { dst[7:0], cflag, dst[7:0], cflag, dst[7:2], dst[7:0],
117
                                                     cflag, dst[7:0], cflag, dst[7:0], cflag, dst[7:0], cflag, dst[7:4] } :
118
    (e_shift_RCL  && exe_operand_16bit)? { e_shift_dst_wire, cflag, dst[15:0], cflag, dst[15:2] } :
119
    (e_shift_RCL  && exe_operand_32bit)? { e_shift_dst_wire, cflag, dst[31:1] } :
120
    (e_shift_SHLD && exe_operand_16bit)? { e_shift_dst_wire, src[15:0], dst[15:0] } :
121
                                         { e_shift_dst_wire, src }; // e_shift_SHLD
122
assign e_shift_right_input =
123
    (e_shift_SAR && exe_is_8bit)?           { {56{dst[7]}},  dst[7:0] } :
124
    (e_shift_SAR && exe_operand_16bit)?     { {48{dst[15]}}, dst[15:0] } :
125
    (e_shift_SAR && exe_operand_32bit)?     { {32{dst[31]}}, dst[31:0] } :
126
    (e_shift_SHR && exe_is_8bit)?           { 56'b0, dst[7:0] } :
127
    (e_shift_SHR && exe_operand_16bit)?     { 48'b0, dst[15:0] } :
128
    (e_shift_SHR && exe_operand_32bit)?     { 32'b0, dst[31:0] } :
129
    (e_shift_ROR)?                          { e_shift_dst_wire, e_shift_dst_wire } :
130
    (e_shift_RCR && exe_is_8bit)?           { dst[0], cflag, dst[7:0], cflag, dst[7:0], cflag, dst[7:0],
131
                                              cflag, dst[7:0], cflag, dst[7:0], cflag, dst[7:0], cflag, dst[7:0] } :
132
    (e_shift_RCR && exe_operand_16bit)?     { dst[12:0], cflag, dst[15:0], cflag, dst[15:0], cflag, dst[15:0] } :
133
    (e_shift_RCR && exe_operand_32bit)?     { dst[30:0], cflag, dst } :
134
    (e_shift_SHRD && exe_operand_16bit)?    { e_shift_dst_wire, src[15:0], dst[15:0] } :
135
                                            { src, dst }; // e_shift_SHRD: 32-bits
136
 
137
assign e_shift_left_result =
138
    (e_shift_count == 5'd0)?  { cflag,  e_shift_left_input[63:32] } :
139
    (e_shift_count == 5'd1)?            e_shift_left_input[63:31] :
140
    (e_shift_count == 5'd2)?            e_shift_left_input[62:30] :
141
    (e_shift_count == 5'd3)?            e_shift_left_input[61:29] :
142
    (e_shift_count == 5'd4)?            e_shift_left_input[60:28] :
143
    (e_shift_count == 5'd5)?            e_shift_left_input[59:27] :
144
    (e_shift_count == 5'd6)?            e_shift_left_input[58:26] :
145
    (e_shift_count == 5'd7)?            e_shift_left_input[57:25] :
146
    (e_shift_count == 5'd8)?            e_shift_left_input[56:24] :
147
    (e_shift_count == 5'd9)?            e_shift_left_input[55:23] :
148
    (e_shift_count == 5'd10)?           e_shift_left_input[54:22] :
149
    (e_shift_count == 5'd11)?           e_shift_left_input[53:21] :
150
    (e_shift_count == 5'd12)?           e_shift_left_input[52:20] :
151
    (e_shift_count == 5'd13)?           e_shift_left_input[51:19] :
152
    (e_shift_count == 5'd14)?           e_shift_left_input[50:18] :
153
    (e_shift_count == 5'd15)?           e_shift_left_input[49:17] :
154
    (e_shift_count == 5'd16)?           e_shift_left_input[48:16] :
155
    (e_shift_count == 5'd17)?           e_shift_left_input[47:15] :
156
    (e_shift_count == 5'd18)?           e_shift_left_input[46:14] :
157
    (e_shift_count == 5'd19)?           e_shift_left_input[45:13] :
158
    (e_shift_count == 5'd20)?           e_shift_left_input[44:12] :
159
    (e_shift_count == 5'd21)?           e_shift_left_input[43:11] :
160
    (e_shift_count == 5'd22)?           e_shift_left_input[42:10] :
161
    (e_shift_count == 5'd23)?           e_shift_left_input[41:9] :
162
    (e_shift_count == 5'd24)?           e_shift_left_input[40:8] :
163
    (e_shift_count == 5'd25)?           e_shift_left_input[39:7] :
164
    (e_shift_count == 5'd26)?           e_shift_left_input[38:6] :
165
    (e_shift_count == 5'd27)?           e_shift_left_input[37:5] :
166
    (e_shift_count == 5'd28)?           e_shift_left_input[36:4] :
167
    (e_shift_count == 5'd29)?           e_shift_left_input[35:3] :
168
    (e_shift_count == 5'd30)?           e_shift_left_input[34:2] :
169
                                        e_shift_left_input[33:1];
170
 
171
assign e_shift_left_cflag =
172
    (e_shift_SHL &&   exe_is_8bit                       && e_shift_count >= 5'd9)?    1'b0 :
173
    (e_shift_SHL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count >= 5'd17)?   1'b0 :
174
    (e_shift_RCL &&   exe_is_8bit                       && e_shift_count == 5'd25)?   dst[1] :
175
    (e_shift_RCL &&   exe_is_8bit                       && e_shift_count == 5'd26)?   dst[0] :
176
    (e_shift_RCL &&   exe_is_8bit                       && e_shift_count == 5'd27)?   cflag :
177
    (e_shift_RCL &&   exe_is_8bit                       && e_shift_count == 5'd28)?   dst[7] :
178
    (e_shift_RCL &&   exe_is_8bit                       && e_shift_count == 5'd29)?   dst[6] :
179
    (e_shift_RCL &&   exe_is_8bit                       && e_shift_count == 5'd30)?   dst[5] :
180
    (e_shift_RCL &&   exe_is_8bit                       && e_shift_count == 5'd31)?   dst[4] :
181
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd17)?   cflag :
182
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd18)?   dst[15] :
183
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd19)?   dst[14] :
184
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd20)?   dst[13] :
185
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd21)?   dst[12] :
186
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd22)?   dst[11] :
187
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd23)?   dst[10] :
188
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd24)?   dst[9] :
189
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd25)?   dst[8] :
190
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd26)?   dst[7] :
191
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd27)?   dst[6] :
192
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd28)?   dst[5] :
193
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd29)?   dst[4] :
194
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd30)?   dst[3] :
195
    (e_shift_RCL && ~(exe_is_8bit) && exe_operand_16bit && e_shift_count == 5'd31)?   dst[2] :
196
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd17)?   src[15] :
197
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd18)?   src[14] :
198
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd19)?   src[13] :
199
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd20)?   src[12] :
200
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd21)?   src[11] :
201
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd22)?   src[10] :
202
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd23)?   src[9] :
203
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd24)?   src[8] :
204
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd25)?   src[7] :
205
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd26)?   src[6] :
206
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd27)?   src[5] :
207
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd28)?   src[4] :
208
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd29)?   src[3] :
209
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd30)?   src[2] :
210
    (e_shift_SHLD &&                  exe_operand_16bit && e_shift_count == 5'd31)?   src[1] :
211
                                                                                      e_shift_left_result[32];
212
 
213
assign e_shift_right_result =
214
    (e_shift_count == 5'd0)?  { e_shift_right_input[31:0], cflag } :
215
    (e_shift_count == 5'd1)?    e_shift_right_input[32:0] :
216
    (e_shift_count == 5'd2)?    e_shift_right_input[33:1] :
217
    (e_shift_count == 5'd3)?    e_shift_right_input[34:2] :
218
    (e_shift_count == 5'd4)?    e_shift_right_input[35:3] :
219
    (e_shift_count == 5'd5)?    e_shift_right_input[36:4] :
220
    (e_shift_count == 5'd6)?    e_shift_right_input[37:5] :
221
    (e_shift_count == 5'd7)?    e_shift_right_input[38:6] :
222
    (e_shift_count == 5'd8)?    e_shift_right_input[39:7] :
223
    (e_shift_count == 5'd9)?    e_shift_right_input[40:8] :
224
    (e_shift_count == 5'd10)?   e_shift_right_input[41:9] :
225
    (e_shift_count == 5'd11)?   e_shift_right_input[42:10] :
226
    (e_shift_count == 5'd12)?   e_shift_right_input[43:11] :
227
    (e_shift_count == 5'd13)?   e_shift_right_input[44:12] :
228
    (e_shift_count == 5'd14)?   e_shift_right_input[45:13] :
229
    (e_shift_count == 5'd15)?   e_shift_right_input[46:14] :
230
    (e_shift_count == 5'd16)?   e_shift_right_input[47:15] :
231
    (e_shift_count == 5'd17)?   e_shift_right_input[48:16] :
232
    (e_shift_count == 5'd18)?   e_shift_right_input[49:17] :
233
    (e_shift_count == 5'd19)?   e_shift_right_input[50:18] :
234
    (e_shift_count == 5'd20)?   e_shift_right_input[51:19] :
235
    (e_shift_count == 5'd21)?   e_shift_right_input[52:20] :
236
    (e_shift_count == 5'd22)?   e_shift_right_input[53:21] :
237
    (e_shift_count == 5'd23)?   e_shift_right_input[54:22] :
238
    (e_shift_count == 5'd24)?   e_shift_right_input[55:23] :
239
    (e_shift_count == 5'd25)?   e_shift_right_input[56:24] :
240
    (e_shift_count == 5'd26)?   e_shift_right_input[57:25] :
241
    (e_shift_count == 5'd27)?   e_shift_right_input[58:26] :
242
    (e_shift_count == 5'd28)?   e_shift_right_input[59:27] :
243
    (e_shift_count == 5'd29)?   e_shift_right_input[60:28] :
244
    (e_shift_count == 5'd30)?   e_shift_right_input[61:29] :
245
                                e_shift_right_input[62:30];
246
assign e_shift_cflag =
247
    (e_shift_SHL || e_shift_ROL || e_shift_RCL || e_shift_SHLD)?    e_shift_left_cflag :
248
    (e_shift_SHRD && exe_operand_16bit && e_shift_count >= 5'd17)?  1'b0 :
249
                                                                    e_shift_right_result[0];
250
 
251
assign e_shift_oflag =  (e_shift_ROL)?                                                  e_shift_result[31] ^ e_shift_result[0] :
252
                        (e_shift_ROR || e_shift_RCR || e_shift_SHR || e_shift_SHRD)?    e_shift_result[31] ^ e_shift_result[30] :
253
                        (e_shift_RCL || e_shift_SHL || e_shift_SHLD)?                   e_shift_result[31] ^ e_shift_cflag :
254
                                                                                        1'b0; //e_shift_SAR
255
 
256
assign e_shift_result =
257
    ((e_shift_SHL || e_shift_ROL || e_shift_RCL || e_shift_SHLD) && exe_is_8bit)?       { {24{e_shift_left_result[7]}},  e_shift_left_result[7:0] } :
258
    ((e_shift_SHL || e_shift_ROL || e_shift_RCL || e_shift_SHLD) && exe_operand_16bit)? { {16{e_shift_left_result[15]}}, e_shift_left_result[15:0] } :
259
    ((e_shift_SHL || e_shift_ROL || e_shift_RCL || e_shift_SHLD) && exe_operand_32bit)?       e_shift_left_result[31:0] :
260
    (exe_is_8bit)?                                                                      { e_shift_right_result[8],  {23{e_shift_right_result[7]}},  e_shift_right_result[8:1] } :
261
    (exe_operand_16bit)?                                                                { e_shift_right_result[16], {15{e_shift_right_result[15]}}, e_shift_right_result[16:1] } :
262
                                                                                          e_shift_right_result[32:1];
263
 
264
assign e_shift_cf_of_rotate_carry_8bit  = e_shift_count != 5'd0 && e_shift_count != 5'd9 && e_shift_count != 5'd18 && e_shift_count != 5'd27;
265
assign e_shift_cf_of_rotate_carry_16bit = e_shift_count != 5'd0 && e_shift_count != 5'd17;
266
 
267
assign e_shift_cmd_not_carry = e_shift_ROL || e_shift_ROR || e_shift_SHL || e_shift_SHR || e_shift_SAR || e_shift_SHLD || e_shift_SHRD;
268
assign e_shift_cmd_carry     = e_shift_RCL || e_shift_RCR;
269
assign e_shift_cmd_shift     = e_shift_SHL || e_shift_SHR || e_shift_SAR || e_shift_SHLD || e_shift_SHRD;
270
assign e_shift_cmd_rot       = e_shift_ROL || e_shift_ROR;
271
 
272
assign e_shift_cf_of_update =
273
    (e_shift_count != 5'd0 && e_shift_cmd_not_carry) ||
274
    (   exe_is_8bit                      && e_shift_cf_of_rotate_carry_8bit  && e_shift_cmd_carry) ||
275
    (~(exe_is_8bit) && exe_operand_16bit && e_shift_cf_of_rotate_carry_16bit && e_shift_cmd_carry) ||
276
    (~(exe_is_8bit) && exe_operand_32bit && e_shift_count != 5'd0            && e_shift_cmd_carry);
277
 
278
assign e_shift_oszapc_update = e_shift_cf_of_update && e_shift_cmd_shift;
279
 
280
assign e_shift_no_write =
281
    (                                       e_shift_cmd_shift && e_shift_count == 5'd0) ||
282
    (  exe_is_8bit                       && e_shift_cmd_rot   && e_shift_count[2:0] == 3'd0) ||
283
    (~(exe_is_8bit) && exe_operand_16bit && e_shift_cmd_rot   && e_shift_count[3:0] == 4'd0) ||
284
 
285
    (  exe_is_8bit                       && e_shift_cmd_carry && ~(e_shift_cf_of_rotate_carry_8bit))  ||
286
    (~(exe_is_8bit) && exe_operand_16bit && e_shift_cmd_carry && ~(e_shift_cf_of_rotate_carry_16bit)) ||
287
 
288
    (~(exe_is_8bit) && exe_operand_32bit && e_shift_count      == 5'd0);
289
 
290
//------------------------------------------------------------------------------
291
 
292
//------------------------------------------------------------------------------
293
 
294
// synthesis translate_off
295
wire _unused_ok = &{ 1'b0, exe_cmd[6:1], exe_decoder[39:14], exe_decoder[10:0], exe_modregrm_imm[7:5], ecx[31:5], e_shift_left_input[0], e_shift_right_input[63], 1'b0 };
296
// synthesis translate_on
297
 
298
//------------------------------------------------------------------------------
299
 
300
endmodule

powered by: WebSVN 2.1.0

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