aboutsummaryrefslogtreecommitdiff
path: root/rtl/src/alu.v
blob: 21b9dc0fe1b86b612cd3fc8882a22ffdc3cea993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// alu:
// Computes result based on operands a, b and the provided operation.
// The signal zero is high if result is zero.

module alu (
  input      [31:0] a, 
  input      [31:0] b,

  input       [3:0] op,
  
  output reg [31:0] result,
  output            zero
);

wire [31:0] arithmetic_result, logic_result, shift_result;

arithmetic_unit au (
  .a(a),
  .b(b),
  .op(op[1:0]),
  .result(arithmetic_result)
);

logic_unit lu (
  .a(a),
  .b(b),
  .op(op[1:0]),
  .result(logic_result)
);

shift_unit su (
  .a(a),
  .b(b[4:0]),
  .op(op[1:0]),
  .result(shift_result)
);

`include "include/consts.vh"

always @ (*) begin
  case (op[3:2])
    ALU_OP_ARITHMETIC: result = arithmetic_result; // ARITHMETIC
    ALU_OP_LOGIC:      result = logic_result;      // LOGIC
    ALU_OP_SHIFT:      result = shift_result;      // SHIFT
    default:           result = 31'b0;
  endcase
end

assign zero = result == 32'b0;

endmodule