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

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [rtl/] [fwrisc_alu.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/****************************************************************************
2
 * fwrisc_alu.sv
3
 *
4
 * Copyright 2018 Matthew Ballance
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in
8
 * compliance with the License.  You may obtain a copy of
9
 * the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in
14
 * writing, software distributed under the License is
15
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16
 * CONDITIONS OF ANY KIND, either express or implied.  See
17
 * the License for the specific language governing
18
 * permissions and limitations under the License.
19
 *
20
 ****************************************************************************/
21
 
22
`include "fwrisc_defines.vh"
23
 
24
/**
25
 * Module: fwrisc_alu
26
 *
27
 * TODO: Add module documentation
28
 */
29
module fwrisc_alu (
30
                input                                   clock,
31
                input                                   reset,
32
                input[31:0]                             op_a,
33
                input[31:0]                             op_b,
34
                input[2:0]                              op,
35
                output reg[31:0]                out,
36
                output                                  carry,
37
                output                                  eqz);
38
 
39
        wire[31:0] or_xor = (op == `OP_XOR)?(op_a ^ op_b):(op_a | op_b);
40
        wire[31:0] add_sub = (op == `OP_ADD)?(op_a + op_b):(op_a - op_b);
41
 
42
//      assign carry = (op_b > op_a);
43
        assign carry = ($signed(op_b) > $signed(op_a));
44
        assign eqz = (op_b == op_a);
45
//      assign carry = 0;
46
 
47
//      genvar i;
48
//      for (i=0; i<31; i++)
49
//              assign or_xor[i] = (op == `OP_XOR)?(op_a[i] ^ op_b[i]):(op_a[i] | op_b[i]);
50
 
51
//      assign eqz = 0;
52
 
53
        always @* begin
54
                case (op)
55
                        /*
56
                        `OP_ADD: out = op_a + op_b;
57
                        `OP_SUB: out = op_a - op_b;
58
                         */
59
                        `OP_ADD,`OP_SUB: out = add_sub;
60
                        `OP_SLL: out = op_a << 1;
61
                        `OP_SRL: out = op_a >> 1;
62
                        `OP_SRA: out = $signed(op_a) >>> 1;
63
                        `OP_AND: out = op_a & op_b;
64
//                      `OP_XOR: out = op_a ^ op_b;
65
//                      default: /*`OP_OR:*/ out = op_a | op_b;
66
                        default: out = or_xor;
67
                endcase
68
        end
69
 
70
endmodule
71
 
72
 

powered by: WebSVN 2.1.0

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