// nandgame ALU `timescale 1us/1us `include "nandgame_types.v" `include "arith_unit.sv" `include "logic_unit.sv" `ifndef NANDGAME_ALU `define NANDGAME_ALU module alu #( parameter DATA_WIDTH = 16 ) ( // "X" operand input [(DATA_WIDTH-1):0] X_in, // "Y" operand input [(DATA_WIDTH-1):0] Y_in, // "u" flag. 1=arithmetic, 0=logic operation input logic u_arith_nlogic_in, // opcode, see ArithCode / LogicCode input logic [1:0] opcode_in, // zero the "X" operand input logic zx_in, // swap "X" and "Y" operands input logic sw_in, // result of operation output logic [(DATA_WIDTH-1):0] result_out ); logic [(DATA_WIDTH-1):0] int_op_x /* verilator public */; logic [(DATA_WIDTH-1):0] int_op_y /* verilator public */; logic [(DATA_WIDTH-1):0] int_result_arith; logic [(DATA_WIDTH-1):0] int_result_logic; assign int_op_x = zx_in ? 0 : (sw_in ? Y_in : X_in); assign int_op_y = sw_in ? X_in : Y_in; arith_unit au ( .X_in(int_op_x), .Y_in(int_op_y), .result_out(int_result_arith), .arith_operation_in(ArithCode'(opcode_in)) ); logic_unit lu ( .X_in(int_op_x), .Y_in(int_op_y), .result_out(int_result_logic), .logic_operation_in(LogicCode'(opcode_in)) ); assign result_out = u_arith_nlogic_in ? int_result_arith : int_result_logic; endmodule `endif