diff --git a/modules/asu.sv b/modules/asu.sv index 3235233..498faad 100644 --- a/modules/asu.sv +++ b/modules/asu.sv @@ -7,11 +7,11 @@ module asu #(parameter width = 2)( always_comb begin // A + (sub) ? B : -B // Adds an extra bit to all operands to calculate the carry bit. Not optimal for hardware synthesis - operand = (B ^ {(width){op}}); - {COUT, OUT_1} = A + operand + {{(width-1){1'b0}}, op}; + operand = (B ^ {(2**width){op}}); + {COUT, OUT_1} = A + operand + {{(2**width-1){1'b0}}, op}; end // Need to do this outside of the always_comb block because parameter-based bitslicing/indexing isn't supported? - // Cin for width-2'th bit to later be xor'ed with COUT to determine if a signed overflow occured for the MIPS architecture - assign OUT_CIN = A[width-1] ^ operand[width-1] ^ OUT_1[width-1]; + // Cin for final bit in adder to later be xor'ed with COUT to determine if a signed overflow occured for the MIPS architecture + assign OUT_CIN = A[2**width-1] ^ operand[2**width-1] ^ OUT_1[2**width-1]; endmodule diff --git a/tests/asu_tb.sv b/tests/asu_tb.sv index 9029b30..e0285fb 100644 --- a/tests/asu_tb.sv +++ b/tests/asu_tb.sv @@ -10,10 +10,8 @@ module asu_tb #(width=8)(); logic [width-1:0] C_exp; logic [0:0] Cout_exp; logic [0:0] Cin_exp; // TODO - - logic [0:0] Signed_overflow; - asu #(width) dut(op, A, B, C, Cout, Cin); + asu #($clog2(width)) dut(op, A, B, C, Cout, Cin); integer error_count; initial begin