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

Subversion Repositories mips32

[/] [mips32/] [trunk/] [Classic-MIPS/] [source/] [src/] [ALU.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jjf
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    17:15:58 12/29/2016 
7
// Design Name: 
8
// Module Name:    ALU 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
`include "macros.v"
22
module ALU(
23
input wire signed [31:0]         opa,
24
input wire signed [31:0]         opb,
25
input wire [3:0]                         cmd,
26
output wire signed [31:0]                res
27
    );
28
 
29
        wire [5:0]                                    shift;
30
 
31
        wire [31:0]                    dsp_a;
32
        wire [31:0]                    dsp_b;
33
        wire                           dsp_sel;
34
        wire [31:0]                    dsp_out;
35
 
36
 
37
        /* instantiate of the ADD/SUB of DSP */
38
        assign dsp_a = opa;
39
        assign dsp_b = opb;
40
        assign dsp_sel = (cmd == `ALU_ADD) ? 1'b1 : 1'b0;
41
        c_addsub_0 addsub_dsp_inst(
42
           .A(     dsp_a       ),
43
           .B(     dsp_b       ),
44
           .ADD(   dsp_sel     ),
45
           .S(     dsp_out     )
46
        );
47
 
48
        /* the ALU operation */
49
        assign shift = opb[5:0];
50
        assign res = OUT(opa, opb, dsp_out, shift, cmd);
51
 
52
        function signed [31:0] OUT;
53
                input signed [31:0] opa;
54
                input signed [31:0] opb;
55
                input signed [31:0] dsp_out;
56
                input [5:0]                         shift;
57
                input [3:0]                         cmd;
58
                begin
59
                        case( cmd )
60
                        `ALU_AND:       OUT = opa & opb;
61
                        `ALU_OR:        OUT = opa | opb;
62
            `ALU_ADD:   OUT = dsp_out;
63
            `ALU_SUB:   OUT = dsp_out;
64
                        `ALU_SLT:       OUT = (opa < opb) ? 32'd1 : 32'd0;
65
                        `ALU_NOR:       OUT = ~(opa | opb);
66
                        `ALU_XOR:       OUT = opa ^ opb;
67
                        `ALU_LU:        OUT = {opb[15:0], 16'h0};
68
                        `ALU_SLLV:      OUT = opa << shift;
69
                        `ALU_SRLV:      OUT = opa >> shift;
70
                        default: OUT = 32'hxxxxxxxx;
71
                        endcase
72
                end
73
        endfunction
74
 
75
endmodule

powered by: WebSVN 2.1.0

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