aboutsummaryrefslogtreecommitdiff
path: root/rtl/src/alu.v
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-21 13:50:28 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-21 13:50:28 +0200
commitcb0be9e2039569ee7d18657e8f675d1f8369b407 (patch)
tree91fa71b3960d1ad5217759371143efbdd833d475 /rtl/src/alu.v
parent98d0dd96611dc2c0e444eaf9410f8adf2924c6b5 (diff)
downloadriscv_cpu-cb0be9e2039569ee7d18657e8f675d1f8369b407.tar.gz
riscv_cpu-cb0be9e2039569ee7d18657e8f675d1f8369b407.zip
restructured project
Diffstat (limited to 'rtl/src/alu.v')
-rw-r--r--rtl/src/alu.v47
1 files changed, 47 insertions, 0 deletions
diff --git a/rtl/src/alu.v b/rtl/src/alu.v
new file mode 100644
index 0000000..8a265ee
--- /dev/null
+++ b/rtl/src/alu.v
@@ -0,0 +1,47 @@
+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