Verilog、SystemVerilog、SystemCなど、ハードウェア記述言語についてのブログです。
** Warning: pp144.v(15): (vlog-2186) SystemVerilog testbench featureランダム、カバレッジ、アサーションはQuestaでのみサポートされているそうです。
(randomization, coverage or assertion) detected in the design.
These features are only supported in Questasim.
package definitions;
parameter VERSION = "1.0";
typedef enum {ADD, SUB, MUL} opcodes_t;
typedef struct {
logic [31:0] a, b;
opcodes_t opcode;
} instruction_t;
function automatic [31:0] multiplier (input [31:0] a, b);
return a * b;
endfunction // multiplier
endpackage // definitions
module ALU (
input definitions::instruction_t IW,
input logic clock,
output logic [31:0] result
);
always_ff @(posedge clock) begin
case(IW.opcode)
definitions::ADD : result = IW.a + IW.b;
definitions::SUB : result = IW.a - IW.b;
definitions::MUL : result = definitions::multiplier(IW.a, IW.b);
endcase // case (IW.opcode)
end
endmodule // ALU
import definitions::*;
module ALU_tb;
parameter PERIOD = 10;
logic clock;
instruction_t IW;
wire [31:0] result;
initial begin
clock = 1'b0;
IW.opcode = ADD;
IW.a = 32'b0;
IW.b = 32'b0;
repeat (5) @(negedge clock);
IW.a = 32'hdeadbeef;
IW.b = 32'b1;
@(negedge clock) IW.opcode = SUB;
@(negedge clock) IW.opcode = MUL;
@(negedge clock);
#1 $finish;
end
always #(PERIOD/2)
clock <= ~clock;
ALU DUT ( .* );
endmodule // ALU_tb
vlib work
vlog -sv definitions.sv ALU_test.sv ALU.sv
vsim -c -do "add wave *; run 1us" ALU_tb
カレンダー
カテゴリー
フリーエリア
最新CM
最新記事
最新TB
プロフィール
ブログ内検索
カウンター
アクセス解析