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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu/] [altor32_alu.v] - Blame information for rev 27

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

Line No. Rev Author Line
1 27 ultra_embe
//-----------------------------------------------------------------
2
//                           AltOR32 
3
//                Alternative Lightweight OpenRisc 
4
//                            V2.0
5
//                     Ultra-Embedded.com
6
//                   Copyright 2011 - 2013
7
//
8
//               Email: admin@ultra-embedded.com
9
//
10
//                       License: LGPL
11
//-----------------------------------------------------------------
12
//
13
// Copyright (C) 2011 - 2013 Ultra-Embedded.com
14
//
15
// This source file may be used and distributed without         
16
// restriction provided that this copyright statement is not    
17
// removed from the file and that any derivative work contains  
18
// the original copyright notice and the associated disclaimer. 
19
//
20
// This source file is free software; you can redistribute it   
21
// and/or modify it under the terms of the GNU Lesser General   
22
// Public License as published by the Free Software Foundation; 
23
// either version 2.1 of the License, or (at your option) any   
24
// later version.
25
//
26
// This source is distributed in the hope that it will be       
27
// useful, but WITHOUT ANY WARRANTY; without even the implied   
28
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
29
// PURPOSE.  See the GNU Lesser General Public License for more 
30
// details.
31
//
32
// You should have received a copy of the GNU Lesser General    
33
// Public License along with this source; if not, write to the 
34
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
35
// Boston, MA  02111-1307  USA
36
//-----------------------------------------------------------------
37
 
38
//-----------------------------------------------------------------
39
// Includes
40
//-----------------------------------------------------------------
41
`include "altor32_defs.v"
42
 
43
//-----------------------------------------------------------------
44
// Module - ALU
45
//-----------------------------------------------------------------
46
module altor32_alu
47
(
48
    // ALU operation select
49
    input [3:0]     op_i        /*verilator public*/,
50
 
51
    // Operands
52
    input [31:0]    a_i         /*verilator public*/,
53
    input [31:0]    b_i         /*verilator public*/,
54
    input           c_i         /*verilator public*/,
55
 
56
    // Result
57
    output [31:0]   p_o         /*verilator public*/,
58
 
59
    // Carry
60
    output reg      c_o         /*verilator public*/,
61
    output reg      c_update_o  /*verilator public*/
62
);
63
 
64
//-----------------------------------------------------------------
65
// Registers
66
//-----------------------------------------------------------------
67
reg [31:0]      result;
68
 
69
reg [31:16]     shift_right_fill;
70
reg [31:0]      shift_right_1;
71
reg [31:0]      shift_right_2;
72
reg [31:0]      shift_right_4;
73
reg [31:0]      shift_right_8;
74
 
75
reg [31:0]      shift_left_1;
76
reg [31:0]      shift_left_2;
77
reg [31:0]      shift_left_4;
78
reg [31:0]      shift_left_8;
79
 
80
//-----------------------------------------------------------------
81
// ALU
82
//-----------------------------------------------------------------
83
always @ (op_i or a_i or b_i or c_i)
84
begin
85
   case (op_i)
86
       //----------------------------------------------
87
       // Shift Left
88
       //----------------------------------------------   
89
       `ALU_SHIFTL :
90
       begin
91
            if (b_i[0] == 1'b1)
92
                shift_left_1 = {a_i[30:0],1'b0};
93
            else
94
                shift_left_1 = a_i;
95
 
96
            if (b_i[1] == 1'b1)
97
                shift_left_2 = {shift_left_1[29:0],2'b00};
98
            else
99
                shift_left_2 = shift_left_1;
100
 
101
            if (b_i[2] == 1'b1)
102
                shift_left_4 = {shift_left_2[27:0],4'b0000};
103
            else
104
                shift_left_4 = shift_left_2;
105
 
106
            if (b_i[3] == 1'b1)
107
                shift_left_8 = {shift_left_4[23:0],8'b00000000};
108
            else
109
                shift_left_8 = shift_left_4;
110
 
111
            if (b_i[4] == 1'b1)
112
                result = {shift_left_8[15:0],16'b0000000000000000};
113
            else
114
                result = shift_left_8;
115
 
116
            c_o        = 1'b0;
117
            c_update_o = 1'b0;
118
       end
119
       //----------------------------------------------
120
       // Shift Right
121
       //----------------------------------------------
122
       `ALU_SHIFTR, `ALU_SHIRTR_ARITH:
123
       begin
124
            // Arithmetic shift? Fill with 1's if MSB set
125
            if (a_i[31] == 1'b1 && op_i == `ALU_SHIRTR_ARITH)
126
                shift_right_fill = 16'b1111111111111111;
127
            else
128
                shift_right_fill = 16'b0000000000000000;
129
 
130
            if (b_i[0] == 1'b1)
131
                shift_right_1 = {shift_right_fill[31], a_i[31:1]};
132
            else
133
                shift_right_1 = a_i;
134
 
135
            if (b_i[1] == 1'b1)
136
                shift_right_2 = {shift_right_fill[31:30], shift_right_1[31:2]};
137
            else
138
                shift_right_2 = shift_right_1;
139
 
140
            if (b_i[2] == 1'b1)
141
                shift_right_4 = {shift_right_fill[31:28], shift_right_2[31:4]};
142
            else
143
                shift_right_4 = shift_right_2;
144
 
145
            if (b_i[3] == 1'b1)
146
                shift_right_8 = {shift_right_fill[31:24], shift_right_4[31:8]};
147
            else
148
                shift_right_8 = shift_right_4;
149
 
150
            if (b_i[4] == 1'b1)
151
                result = {shift_right_fill[31:16], shift_right_8[31:16]};
152
            else
153
                result = shift_right_8;
154
 
155
            c_o        = 1'b0;
156
            c_update_o = 1'b0;
157
       end
158
       //----------------------------------------------
159
       // Arithmetic
160
       //----------------------------------------------
161
       `ALU_ADD :
162
       begin
163
            {c_o, result} = (a_i + b_i);
164
            c_update_o    = 1'b1;
165
       end
166
       `ALU_ADDC :
167
       begin
168
            {c_o, result} = (a_i + b_i) + {31'h00000000, c_i};
169
            c_update_o    = 1'b1;
170
       end
171
       `ALU_SUB :
172
       begin
173
            result        = (a_i - b_i);
174
            c_o           = 1'b0;
175
            c_update_o    = 1'b0;
176
       end
177
       //----------------------------------------------
178
       // Logical
179
       //----------------------------------------------       
180
       `ALU_AND :
181
       begin
182
            result        = (a_i & b_i);
183
            c_o           = 1'b0;
184
            c_update_o    = 1'b0;
185
       end
186
       `ALU_OR  :
187
       begin
188
            result        = (a_i | b_i);
189
            c_o           = 1'b0;
190
            c_update_o    = 1'b0;
191
       end
192
       `ALU_XOR :
193
       begin
194
            result        = (a_i ^ b_i);
195
            c_o           = 1'b0;
196
            c_update_o    = 1'b0;
197
       end
198
       default  :
199
       begin
200
            result        = a_i;
201
            c_o           = 1'b0;
202
            c_update_o    = 1'b0;
203
       end
204
   endcase
205
end
206
 
207
assign p_o    = result;
208
 
209
endmodule

powered by: WebSVN 2.1.0

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