Add missing "signed" to ALU ports/connections
This commit is contained in:
10
ALU.sv
10
ALU.sv
@ -10,14 +10,14 @@
|
|||||||
// 101 - SUB
|
// 101 - SUB
|
||||||
module ALU(
|
module ALU(
|
||||||
input var logic[2:0] opcode,
|
input var logic[2:0] opcode,
|
||||||
input var logic[7:0] operandA,
|
input var logic signed[7:0] operandA,
|
||||||
input var logic[7:0] operandB,
|
input var logic signed[7:0] operandB,
|
||||||
output var logic[7:0] result
|
output var logic signed[7:0] result
|
||||||
);
|
);
|
||||||
|
|
||||||
// This is a var logic, because I only want a single driver.
|
// This is a var logic, because I only want a single driver.
|
||||||
// It should be synthesized to a wire, as nothing is stored (hopefully?).
|
// It should be synthesized to a wire, as nothing is stored (hopefully?).
|
||||||
var logic[7:0] lu_result;
|
var logic signed[7:0] lu_result;
|
||||||
LogicalUnit lu(
|
LogicalUnit lu(
|
||||||
.opcode(opcode),
|
.opcode(opcode),
|
||||||
.operandA(operandA),
|
.operandA(operandA),
|
||||||
@ -25,7 +25,7 @@ module ALU(
|
|||||||
.result(lu_result)
|
.result(lu_result)
|
||||||
);
|
);
|
||||||
|
|
||||||
var logic[7:0] au_result;
|
var logic signed[7:0] au_result;
|
||||||
ArithmeticUnit au(
|
ArithmeticUnit au(
|
||||||
.opcode(opcode),
|
.opcode(opcode),
|
||||||
.operandA(operandA),
|
.operandA(operandA),
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
module ALU_TestBench;
|
module ALU_TestBench;
|
||||||
|
|
||||||
var logic[2:0] opcode;
|
var logic[2:0] opcode;
|
||||||
var logic[7:0] operandA;
|
var logic signed[7:0] operandA;
|
||||||
var logic[7:0] operandB;
|
var logic signed[7:0] operandB;
|
||||||
tri[7:0] result;
|
tri signed[7:0] result;
|
||||||
|
|
||||||
ALU alu(
|
ALU alu(
|
||||||
.opcode(opcode),
|
.opcode(opcode),
|
||||||
@ -22,7 +22,7 @@ initial begin
|
|||||||
opcode = 3'b000;
|
opcode = 3'b000;
|
||||||
operandA = 8'b00000000;
|
operandA = 8'b00000000;
|
||||||
operandB = 8'b00000000;
|
operandB = 8'b00000000;
|
||||||
#100 assert(result == 8'b00000000);
|
#20 assert(result == 8'b00000000);
|
||||||
|
|
||||||
// First set of operands
|
// First set of operands
|
||||||
operandA = 8'b00000000;
|
operandA = 8'b00000000;
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
// 101 - SUB
|
// 101 - SUB
|
||||||
module ArithmeticUnit(
|
module ArithmeticUnit(
|
||||||
input var logic[2:0] opcode,
|
input var logic[2:0] opcode,
|
||||||
input var logic[7:0] operandA,
|
input var logic signed[7:0] operandA,
|
||||||
input var logic[7:0] operandB,
|
input var logic signed[7:0] operandB,
|
||||||
output var logic[7:0] result
|
output var logic signed[7:0] result
|
||||||
);
|
);
|
||||||
|
|
||||||
// If the least significant opcode bit is 0, it is an addition
|
// If the least significant opcode bit is 0, it is an addition
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
module ArithmeticUnit_TestBench;
|
module ArithmeticUnit_TestBench;
|
||||||
|
|
||||||
var logic[2:0] opcode;
|
var logic[2:0] opcode;
|
||||||
var logic[7:0] operandA;
|
var logic signed[7:0] operandA;
|
||||||
var logic[7:0] operandB;
|
var logic signed[7:0] operandB;
|
||||||
tri[7:0] result;
|
tri signed[7:0] result;
|
||||||
|
|
||||||
ArithmeticUnit au(
|
ArithmeticUnit au(
|
||||||
.opcode(opcode),
|
.opcode(opcode),
|
||||||
|
@ -12,10 +12,11 @@
|
|||||||
// 111 - >= 0
|
// 111 - >= 0
|
||||||
module ConditionalUnit(
|
module ConditionalUnit(
|
||||||
input var logic[2:0] opcode,
|
input var logic[2:0] opcode,
|
||||||
input var logic[7:0] operand,
|
input var logic signed[7:0] operand,
|
||||||
output var logic result
|
output var logic result
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// This could be simplified significantly (basically removed), if I had ALU flags.
|
||||||
always_comb case (opcode)
|
always_comb case (opcode)
|
||||||
3'b000: result = 0;
|
3'b000: result = 0;
|
||||||
3'b001: result = (operand == 0);
|
3'b001: result = (operand == 0);
|
||||||
|
133
ConditionalUnit_TestBench.sv
Normal file
133
ConditionalUnit_TestBench.sv
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
`default_nettype none
|
||||||
|
|
||||||
|
module ConditionalUnit_TestBench;
|
||||||
|
|
||||||
|
var logic[2:0] opcode;
|
||||||
|
var logic signed[7:0] operand;
|
||||||
|
tri result;
|
||||||
|
|
||||||
|
ConditionalUnit cu(
|
||||||
|
.opcode(opcode),
|
||||||
|
.operand(operand),
|
||||||
|
.result(result)
|
||||||
|
);
|
||||||
|
|
||||||
|
// synthesis translate_off
|
||||||
|
initial begin
|
||||||
|
$timeformat(-9, 2, " ns", 20);
|
||||||
|
|
||||||
|
$display("%0t Initial Reset", $time);
|
||||||
|
opcode = 3'b000;
|
||||||
|
operand = 8'b00000000;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
// First set of operands
|
||||||
|
operand = 8'b00000000;
|
||||||
|
|
||||||
|
$display("%0t NEVER 1", $time);
|
||||||
|
opcode = 3'b000;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t EQUAL 1", $time);
|
||||||
|
opcode = 3'b001;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t LESS 1", $time);
|
||||||
|
opcode = 3'b010;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t LESSEQUAL 1", $time);
|
||||||
|
opcode = 3'b011;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t ALWAYS 1", $time);
|
||||||
|
opcode = 3'b100;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t NOTEQUAL 1", $time);
|
||||||
|
opcode = 3'b101;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t GREATER 1", $time);
|
||||||
|
opcode = 3'b110;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t GREATEREQUAL 1", $time);
|
||||||
|
opcode = 3'b111;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
// Second set of operands
|
||||||
|
operand = 8'b11111111;
|
||||||
|
|
||||||
|
$display("%0t NEVER 2", $time);
|
||||||
|
opcode = 3'b000;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t EQUAL 2", $time);
|
||||||
|
opcode = 3'b001;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t LESS 2", $time);
|
||||||
|
opcode = 3'b010;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t LESSEQUAL 2", $time);
|
||||||
|
opcode = 3'b011;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t ALWAYS 2", $time);
|
||||||
|
opcode = 3'b100;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t NOTEQUAL 2", $time);
|
||||||
|
opcode = 3'b101;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t GREATER 2", $time);
|
||||||
|
opcode = 3'b110;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t GREATEREQUAL 2", $time);
|
||||||
|
opcode = 3'b111;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
// Third set of operands
|
||||||
|
operand = 8'b00001111;
|
||||||
|
|
||||||
|
$display("%0t NEVER 3", $time);
|
||||||
|
opcode = 3'b000;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t EQUAL 3", $time);
|
||||||
|
opcode = 3'b001;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t LESS 3", $time);
|
||||||
|
opcode = 3'b010;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t LESSEQUAL 3", $time);
|
||||||
|
opcode = 3'b011;
|
||||||
|
#20 assert(result == 1'b0);
|
||||||
|
|
||||||
|
$display("%0t ALWAYS 3", $time);
|
||||||
|
opcode = 3'b100;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t NOTEQUAL 3", $time);
|
||||||
|
opcode = 3'b101;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t GREATER 3", $time);
|
||||||
|
opcode = 3'b110;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("%0t GREATEREQUAL 3", $time);
|
||||||
|
opcode = 3'b111;
|
||||||
|
#20 assert(result == 1'b1);
|
||||||
|
|
||||||
|
$display("Success!");
|
||||||
|
end
|
||||||
|
// synthesis translate_on
|
||||||
|
|
||||||
|
endmodule
|
Reference in New Issue
Block a user